Révision 7547bb19
Ajouté par Assos Assos il y a environ 7 ans
drupal7/sites/all/modules/views_bulk_operations/js/views_bulk_operations.js | ||
---|---|---|
1 | 1 |
(function ($) { |
2 |
// Polyfill for jQuery less than 1.6. |
|
3 |
if (typeof $.fn.prop != 'function') { |
|
4 |
jQuery.fn.extend({ |
|
5 |
prop: jQuery.fn.attr |
|
6 |
}); |
|
7 |
} |
|
8 |
|
|
2 | 9 |
Drupal.behaviors.vbo = { |
3 | 10 |
attach: function(context) { |
4 | 11 |
$('.vbo-views-form', context).each(function() { |
5 | 12 |
Drupal.vbo.initTableBehaviors(this); |
6 | 13 |
Drupal.vbo.initGenericBehaviors(this); |
14 |
Drupal.vbo.toggleButtonsState(this); |
|
7 | 15 |
}); |
8 | 16 |
} |
9 | 17 |
} |
... | ... | |
32 | 40 |
// This is the "select all" checkbox in (each) table header. |
33 | 41 |
$('.vbo-table-select-all', form).click(function() { |
34 | 42 |
var table = $(this).closest('table')[0]; |
35 |
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', table).attr('checked', this.checked); |
|
43 |
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', table).prop('checked', this.checked); |
|
44 |
Drupal.vbo.toggleButtonsState(form); |
|
36 | 45 |
|
37 | 46 |
// Toggle the visibility of the "select all" row (if any). |
38 | 47 |
if (this.checked) { |
... | ... | |
83 | 92 |
$('.vbo-select-all-markup', form).show(); |
84 | 93 |
|
85 | 94 |
$('.vbo-select-this-page', form).click(function() { |
86 |
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked); |
|
87 |
$('.vbo-select-all-pages', form).attr('checked', false); |
|
95 |
$('input[id^="edit-views-bulk-operations"]', form).prop('checked', this.checked); |
|
96 |
Drupal.vbo.toggleButtonsState(form); |
|
97 |
$('.vbo-select-all-pages', form).prop('checked', false); |
|
88 | 98 |
|
89 | 99 |
// Toggle the "select all" checkbox in grouped tables (if any). |
90 |
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
|
100 |
$('.vbo-table-select-all', form).prop('checked', this.checked);
|
|
91 | 101 |
}); |
92 | 102 |
$('.vbo-select-all-pages', form).click(function() { |
93 |
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked); |
|
94 |
$('.vbo-select-this-page', form).attr('checked', false); |
|
103 |
$('input[id^="edit-views-bulk-operations"]', form).prop('checked', this.checked); |
|
104 |
Drupal.vbo.toggleButtonsState(form); |
|
105 |
$('.vbo-select-this-page', form).prop('checked', false); |
|
95 | 106 |
|
96 | 107 |
// Toggle the "select all" checkbox in grouped tables (if any). |
97 |
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
|
108 |
$('.vbo-table-select-all', form).prop('checked', this.checked);
|
|
98 | 109 |
|
99 | 110 |
// Modify the value of the hidden form field. |
100 | 111 |
$('.select-all-rows', form).val(this.checked); |
101 | 112 |
}); |
102 | 113 |
|
114 |
// Toggle submit buttons' "disabled" states with the state of the operation |
|
115 |
// selectbox. |
|
116 |
$('select[name="operation"]', form).change(function () { |
|
117 |
Drupal.vbo.toggleButtonsState(form); |
|
118 |
}); |
|
119 |
|
|
103 | 120 |
$('.vbo-select', form).click(function() { |
104 | 121 |
// If a checkbox was deselected, uncheck any "select all" checkboxes. |
105 | 122 |
if (!this.checked) { |
106 |
$('.vbo-select-this-page', form).attr('checked', false);
|
|
107 |
$('.vbo-select-all-pages', form).attr('checked', false);
|
|
123 |
$('.vbo-select-this-page', form).prop('checked', false);
|
|
124 |
$('.vbo-select-all-pages', form).prop('checked', false);
|
|
108 | 125 |
// Modify the value of the hidden form field. |
109 | 126 |
$('.select-all-rows', form).val('0') |
110 | 127 |
|
111 | 128 |
var table = $(this).closest('table')[0]; |
112 | 129 |
if (table) { |
113 | 130 |
// Uncheck the "select all" checkbox in the table header. |
114 |
$('.vbo-table-select-all', table).attr('checked', false);
|
|
131 |
$('.vbo-table-select-all', table).prop('checked', false);
|
|
115 | 132 |
|
116 | 133 |
// If there's a "select all" row, hide it. |
117 | 134 |
if ($('.vbo-table-select-this-page', table).length) { |
... | ... | |
121 | 138 |
} |
122 | 139 |
} |
123 | 140 |
} |
141 |
|
|
142 |
Drupal.vbo.toggleButtonsState(form); |
|
124 | 143 |
}); |
125 | 144 |
} |
126 | 145 |
|
146 |
Drupal.vbo.toggleButtonsState = function(form) { |
|
147 |
// If no rows are checked, disable any form submit actions. |
|
148 |
var selectbox = $('select[name="operation"]', form); |
|
149 |
var checkedCheckboxes = $('.vbo-select:checked', form); |
|
150 |
var buttons = $('[id^="edit-select"] input[type="submit"]', form); |
|
151 |
|
|
152 |
if (selectbox.length) { |
|
153 |
var has_selection = checkedCheckboxes.length && selectbox.val() !== '0'; |
|
154 |
buttons.prop('disabled', !has_selection); |
|
155 |
} |
|
156 |
else { |
|
157 |
buttons.prop('disabled', !checkedCheckboxes.length); |
|
158 |
} |
|
159 |
}; |
|
160 |
|
|
127 | 161 |
})(jQuery); |
Formats disponibles : Unified diff
Weekly update of contrib modules