2016-12-13 10:29:33 +01:00
|
|
|
/**
|
|
|
|
* Utility that makes it possible to hide fields when a checkbox is unchecked
|
|
|
|
*/
|
|
|
|
(function ($) {
|
2017-02-20 15:06:42 +01:00
|
|
|
function setupHiding() {
|
2016-12-13 10:29:33 +01:00
|
|
|
var $toggler = $(this);
|
|
|
|
|
|
|
|
// Getting the field which should be hidden:
|
|
|
|
var $subject = $($toggler.data('h5p-visibility-subject-selector'));
|
|
|
|
|
|
|
|
var toggle = function () {
|
|
|
|
$subject.toggle($toggler.is(':checked'));
|
|
|
|
};
|
|
|
|
|
|
|
|
$toggler.change(toggle);
|
|
|
|
toggle();
|
|
|
|
}
|
|
|
|
|
2017-02-20 15:06:42 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-13 10:29:33 +01:00
|
|
|
$(document).ready(function () {
|
|
|
|
// Get the checkboxes making other fields being hidden:
|
|
|
|
$('.h5p-visibility-toggler').each(setupHiding);
|
2017-02-20 15:06:42 +01:00
|
|
|
|
|
|
|
// Get the buttons making other fields have hidden values:
|
|
|
|
$('.h5p-reveal-value').each(setupRevealing);
|
2016-12-13 10:29:33 +01:00
|
|
|
});
|
|
|
|
})(H5P.jQuery);
|