2 Drupal
.behaviors
.vbo
= {
3 attach: function(context
) {
4 $('.vbo-views-form', context
).each(function() {
5 Drupal
.vbo
.initTableBehaviors(this);
6 Drupal
.vbo
.initGenericBehaviors(this);
11 Drupal
.vbo
= Drupal
.vbo
|| {};
12 Drupal
.vbo
.initTableBehaviors = function(form
) {
13 // If the table is not grouped, "Select all on this page / all pages"
14 // markup gets inserted below the table header.
15 var selectAllMarkup
= $('.vbo-table-select-all-markup', form
);
16 if (selectAllMarkup
.length
) {
17 $('.views-table > tbody', form
).prepend('<tr class="views-table-row-select-all even">></tr>');
18 var colspan
= $('table th', form
).length
;
19 $('.views-table-row-select-all', form
).html('<td colspan="' + colspan
+ '">' + selectAllMarkup
.html() + '</td>');
21 $('.vbo-table-select-all-pages', form
).click(function() {
22 Drupal
.vbo
.tableSelectAllPages(form
);
25 $('.vbo-table-select-this-page', form
).click(function() {
26 Drupal
.vbo
.tableSelectThisPage(form
);
31 $('.vbo-table-select-all', form
).show();
32 // This is the "select all" checkbox in (each) table header.
33 $('.vbo-table-select-all', form
).click(function() {
34 var table
= $(this).closest('table')[0];
35 $('input[id^="edit-views-bulk-operations"]:not(:disabled)', table
).attr('checked', this.checked
);
37 // Toggle the visibility of the "select all" row (if any).
39 $('.views-table-row-select-all', table
).show();
42 $('.views-table-row-select-all', table
).hide();
43 // Disable "select all across pages".
44 Drupal
.vbo
.tableSelectThisPage(form
);
48 // Set up the ability to click anywhere on the row to select it.
49 if (Drupal
.settings
.vbo
.row_clickable
) {
50 $('.views-table tbody tr', form
).click(function(event
) {
51 if (event
.target
.tagName
.toLowerCase() != 'input' && event
.target
.tagName
.toLowerCase() != 'a') {
52 $('input[id^="edit-views-bulk-operations"]:not(:disabled)', this).each(function() {
53 var checked
= this.checked
;
54 // trigger() toggles the checkmark *after* the event is set,
55 // whereas manually clicking the checkbox toggles it *beforehand*.
56 // that's why we manually set the checkmark first, then trigger the
57 // event (so that listeners get notified), then re-set the checkmark
58 // which the trigger will have toggled. yuck!
59 this.checked
= !checked
;
60 $(this).trigger('click');
61 this.checked
= !checked
;
68 Drupal
.vbo
.tableSelectAllPages = function(form
) {
69 $('.vbo-table-this-page', form
).hide();
70 $('.vbo-table-all-pages', form
).show();
71 // Modify the value of the hidden form field.
72 $('.select-all-rows', form
).val('1');
74 Drupal
.vbo
.tableSelectThisPage = function(form
) {
75 $('.vbo-table-all-pages', form
).hide();
76 $('.vbo-table-this-page', form
).show();
77 // Modify the value of the hidden form field.
78 $('.select-all-rows', form
).val('0');
81 Drupal
.vbo
.initGenericBehaviors = function(form
) {
82 // Show the "select all" fieldset.
83 $('.vbo-select-all-markup', form
).show();
85 $('.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);
89 // Toggle the "select all" checkbox in grouped tables (if any).
90 $('.vbo-table-select-all', form
).attr('checked', this.checked
);
92 $('.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);
96 // Toggle the "select all" checkbox in grouped tables (if any).
97 $('.vbo-table-select-all', form
).attr('checked', this.checked
);
99 // Modify the value of the hidden form field.
100 $('.select-all-rows', form
).val(this.checked
);
103 $('.vbo-select', form
).click(function() {
104 // If a checkbox was deselected, uncheck any "select all" checkboxes.
106 $('.vbo-select-this-page', form
).attr('checked', false);
107 $('.vbo-select-all-pages', form
).attr('checked', false);
108 // Modify the value of the hidden form field.
109 $('.select-all-rows', form
).val('0')
111 var table
= $(this).closest('table')[0];
113 // Uncheck the "select all" checkbox in the table header.
114 $('.vbo-table-select-all', table
).attr('checked', false);
116 // If there's a "select all" row, hide it.
117 if ($('.vbo-table-select-this-page', table
).length
) {
118 $('.views-table-row-select-all', table
).hide();
119 // Disable "select all across pages".
120 Drupal
.vbo
.tableSelectThisPage(form
);