views_send.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. Drupal.behaviors.viewsSend = {
  9. attach: function(context) {
  10. $('.views-send-selection-form', context).each(function() {
  11. Drupal.viewsSend.initTableBehaviors(this);
  12. Drupal.viewsSend.initGenericBehaviors(this);
  13. });
  14. }
  15. }
  16. Drupal.viewsSend = Drupal.viewsSend || {};
  17. Drupal.viewsSend.initTableBehaviors = function(form) {
  18. $('.views-send-table-select-all', form).show();
  19. // This is the "select all" checkbox in (each) table header.
  20. $('.views-send-table-select-all', form).click(function() {
  21. var table = $(this).closest('table')[0];
  22. $('input[id^="edit-views-send"]:not(:disabled)', table).prop('checked', this.checked).change();
  23. });
  24. }
  25. Drupal.viewsSend.initGenericBehaviors = function(form) {
  26. // Show the "select all" fieldset.
  27. $('.views-send-select-all-markup', form).show();
  28. $('.views-send-select-this-page', form).click(function() {
  29. $('input[id^="edit-views-send"]', form).prop('checked', this.checked).change();
  30. // Toggle the "select all" checkbox in grouped tables (if any).
  31. $('.views-send-table-select-all', form).prop('checked', this.checked).change();
  32. });
  33. $('.views-send-select', form).click(function() {
  34. // If a checkbox was deselected, uncheck any "select all" checkboxes.
  35. if (!this.checked) {
  36. $('.views-send-select-this-page', form).prop('checked', false).change();
  37. var table = $(this).closest('table')[0];
  38. if (table) {
  39. // Uncheck the "select all" checkbox in the table header.
  40. $('.views-send-table-select-all', table).prop('checked', false).change();
  41. }
  42. }
  43. });
  44. }
  45. })(jQuery);