ajax.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal, drupalSettings) {
  8. Drupal.AjaxCommands.prototype.viewsHighlight = function (ajax, response, status) {
  9. $('.hilited').removeClass('hilited');
  10. $(response.selector).addClass('hilited');
  11. };
  12. Drupal.AjaxCommands.prototype.viewsSetForm = function (ajax, response, status) {
  13. var $form = $('.js-views-ui-dialog form');
  14. var $submitButtons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit');
  15. $submitButtons.on('click mousedown', function () {
  16. this.form.clk = this;
  17. });
  18. $form.once('views-ajax-submit').each(function () {
  19. var $form = $(this);
  20. var elementSettings = {
  21. url: response.url,
  22. event: 'submit',
  23. base: $form.attr('id'),
  24. element: this
  25. };
  26. var ajaxForm = Drupal.ajax(elementSettings);
  27. ajaxForm.$form = $form;
  28. });
  29. };
  30. Drupal.AjaxCommands.prototype.viewsShowButtons = function (ajax, response, status) {
  31. $('div.views-edit-view div.form-actions').removeClass('js-hide');
  32. if (response.changed) {
  33. $('div.views-edit-view div.view-changed.messages').removeClass('js-hide');
  34. }
  35. };
  36. Drupal.AjaxCommands.prototype.viewsTriggerPreview = function (ajax, response, status) {
  37. if ($('input#edit-displays-live-preview').is(':checked')) {
  38. $('#preview-submit').trigger('click');
  39. }
  40. };
  41. Drupal.AjaxCommands.prototype.viewsReplaceTitle = function (ajax, response, status) {
  42. var doc = document;
  43. var oldTitle = doc.title;
  44. var escapedSiteName = response.siteName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  45. var re = new RegExp('.+ (.) ' + escapedSiteName);
  46. doc.title = oldTitle.replace(re, response.title + ' $1 ' + response.siteName);
  47. $('h1.page-title').text(response.title);
  48. };
  49. Drupal.theme.tableDragChangedWarning = function () {
  50. return [];
  51. };
  52. Drupal.behaviors.livePreview = {
  53. attach: function attach(context) {
  54. $('input#edit-displays-live-preview', context).once('views-ajax').on('click', function () {
  55. if ($(this).is(':checked')) {
  56. $('#preview-submit').trigger('click');
  57. }
  58. });
  59. }
  60. };
  61. Drupal.behaviors.syncPreviewDisplay = {
  62. attach: function attach(context) {
  63. $('#views-tabset a').once('views-ajax').on('click', function () {
  64. var href = $(this).attr('href');
  65. var displayId = href.substr(11);
  66. $('#views-live-preview #preview-display-id').val(displayId);
  67. });
  68. }
  69. };
  70. Drupal.behaviors.viewsAjax = {
  71. collapseReplaced: false,
  72. attach: function attach(context, settings) {
  73. var baseElementSettings = {
  74. event: 'click',
  75. progress: { type: 'fullscreen' }
  76. };
  77. $('a.views-ajax-link', context).once('views-ajax').each(function () {
  78. var elementSettings = baseElementSettings;
  79. elementSettings.base = $(this).attr('id');
  80. elementSettings.element = this;
  81. if ($(this).attr('href')) {
  82. elementSettings.url = $(this).attr('href');
  83. }
  84. Drupal.ajax(elementSettings);
  85. });
  86. $('div#views-live-preview a').once('views-ajax').each(function () {
  87. if (!$(this).attr('href')) {
  88. return true;
  89. }
  90. var elementSettings = baseElementSettings;
  91. elementSettings.url = $(this).attr('href');
  92. if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
  93. return true;
  94. }
  95. elementSettings.wrapper = 'views-preview-wrapper';
  96. elementSettings.method = 'replaceWith';
  97. elementSettings.base = $(this).attr('id');
  98. elementSettings.element = this;
  99. Drupal.ajax(elementSettings);
  100. });
  101. $('div#views-live-preview input[type=submit]').once('views-ajax').each(function (event) {
  102. $(this).on('click', function () {
  103. this.form.clk = this;
  104. return true;
  105. });
  106. var elementSettings = baseElementSettings;
  107. elementSettings.url = $(this.form).attr('action');
  108. if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
  109. return true;
  110. }
  111. elementSettings.wrapper = 'views-preview-wrapper';
  112. elementSettings.method = 'replaceWith';
  113. elementSettings.event = 'click';
  114. elementSettings.base = $(this).attr('id');
  115. elementSettings.element = this;
  116. Drupal.ajax(elementSettings);
  117. });
  118. }
  119. };
  120. })(jQuery, Drupal, drupalSettings);