diff --git a/js/h5p-display-options.js b/js/h5p-display-options.js index 9c8f664..2165152 100644 --- a/js/h5p-display-options.js +++ b/js/h5p-display-options.js @@ -2,7 +2,7 @@ * Utility that makes it possible to hide fields when a checkbox is unchecked */ (function ($) { - function setupHiding () { + function setupHiding() { var $toggler = $(this); // Getting the field which should be hidden: @@ -16,8 +16,39 @@ toggle(); } + function setupRevealing() { + var $button = $(this); + + // Getting the field which should have the value: + var $input = $('#' + $button.data('control')); + + if (!$input.data('value')) { + $button.remove(); + return; + } + + // Setup button action + var revealed = false; + var text = $button.html(); + $button.click(function () { + if (revealed) { + $input.val(''); + $button.html(text); + revealed = false; + } + else { + $input.val($input.data('value')); + $button.html($button.data('hide')); + revealed = true; + } + }); + } + $(document).ready(function () { // Get the checkboxes making other fields being hidden: $('.h5p-visibility-toggler').each(setupHiding); + + // Get the buttons making other fields have hidden values: + $('.h5p-reveal-value').each(setupRevealing); }); })(H5P.jQuery);