flag-admin.js
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function ($) {
/**
* Behavior to disable the "unflag" option if "flag" is not available.
*/
Drupal.behaviors.flagRoles = {};
Drupal.behaviors.flagRoles.attach = function(context) {
$('#flag-roles input.flag-access', context).change(function() {
var unflagCheckbox = $(this).parents('tr:first').find('input.unflag-access').get(0);
if (this.checked) {
// If "flag" is available, restore the state of the "unflag" checkbox.
unflagCheckbox.disabled = false;
if (typeof(unflagCheckbox.previousFlagState) != 'undefined') {
unflagCheckbox.checked = unflagCheckbox.previousFlagState;
}
else {
unflagCheckbox.checked = true;
}
}
else {
// Remember if the "unflag" option was checked or unchecked, then disable.
unflagCheckbox.previousFlagState = unflagCheckbox.checked;
unflagCheckbox.disabled = true;
unflagCheckbox.checked = false;
}
});
$('#flag-roles input.unflag-access', context).change(function() {
if ($(this).parents('table:first').find('input.unflag-access:enabled:not(:checked)').size() == 0) {
$('div.form-item-unflag-denied-text').slideUp();
}
else {
$('div.form-item-unflag-denied-text').slideDown();
}
});
// Hide the link options by default if needed.
if ($('#flag-roles input.unflag-access:enabled:not(:checked)').size() == 0) {
$('div.form-item-unflag-denied-text').css('display', 'none');
}
};
/**
* Vertical tabs integration.
*/
Drupal.behaviors.flagSummary = {};
Drupal.behaviors.flagSummary.attach = function (context) {
$('fieldset.flag-fieldset', context).drupalSetSummary(function(context) {
var flags = [];
$('input:checkbox:checked', context).each(function() {
flags.push(this.title);
});
if (flags.length) {
return flags.join(', ');
}
else {
return Drupal.t('No flags');
}
});
};
})(jQuery);