adminUi.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @file
  3. * Views admin UI functionality.
  4. */
  5. (function ($, Drupal) {
  6. 'use strict';
  7. /**
  8. * @type {Drupal~behavior}
  9. */
  10. Drupal.behaviors.views_bulk_operations = {
  11. attach: function (context, settings) {
  12. $('.views-bulk-operations-ui').once('views-bulk-operations-ui').each(Drupal.viewsBulkOperationsUi);
  13. }
  14. };
  15. /**
  16. * Callback used in {@link Drupal.behaviors.views_bulk_operations}.
  17. */
  18. Drupal.viewsBulkOperationsUi = function () {
  19. var uiElement = $(this);
  20. // Show / hide actions' preliminary configuration.
  21. uiElement.find('.vbo-action-state').each(function () {
  22. var matches = $(this).attr('name').match(/.*\[.*?\]\[(.*?)\]\[.*?\]/);
  23. if (typeof (matches[1]) != 'undefined') {
  24. var preconfigurationElement = uiElement.find('*[data-for="' + matches[1] + '"]');
  25. $(this).change(function (event) {
  26. if ($(this).is(':checked')) {
  27. preconfigurationElement.show('fast');
  28. }
  29. else {
  30. preconfigurationElement.hide('fast');
  31. }
  32. });
  33. }
  34. });
  35. // Select / deselect all functionality.
  36. var actionsElementWrapper = uiElement.find('details.vbo-actions-widget > .details-wrapper');
  37. if (actionsElementWrapper.length) {
  38. var checked = false;
  39. var allHandle = $('<a href="#" class="vbo-all-switch">' + Drupal.t('Select / deselect all') + '</a>');
  40. actionsElementWrapper.prepend(allHandle);
  41. allHandle.on('click', function (event) {
  42. event.preventDefault();
  43. checked = !checked;
  44. actionsElementWrapper.find('.vbo-action-state').each(function () {
  45. $(this).prop('checked', checked);
  46. $(this).trigger('change');
  47. });
  48. return false;
  49. });
  50. }
  51. };
  52. })(jQuery, Drupal);