drupal/core/modules/views_ui/js/ajax.js

145 lines
4.6 KiB
JavaScript
Raw Normal View History

2009-05-17 11:16:51 +00:00
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal, drupalSettings) {
Drupal.AjaxCommands.prototype.viewsHighlight = function (ajax, response, status) {
2009-05-17 11:16:51 +00:00
$('.hilited').removeClass('hilited');
$(response.selector).addClass('hilited');
};
Drupal.AjaxCommands.prototype.viewsSetForm = function (ajax, response, status) {
const $form = $('.js-views-ui-dialog form');
const $submitButtons = $(once('views-ajax-submit', $form.find('input[type=submit].js-form-submit, button.js-form-submit')));
$submitButtons.on('click mousedown', function () {
this.form.clk = this;
});
once('views-ajax-submit', $form).forEach(form => {
const $form = $(form);
const elementSettings = {
url: response.url,
event: 'submit',
base: $form.attr('id'),
element: form
};
const ajaxForm = Drupal.ajax(elementSettings);
ajaxForm.$form = $form;
});
};
Drupal.AjaxCommands.prototype.viewsShowButtons = function (ajax, response, status) {
2009-05-17 11:16:51 +00:00
$('div.views-edit-view div.form-actions').removeClass('js-hide');
if (response.changed) {
$('div.views-edit-view div.view-changed.messages').removeClass('js-hide');
}
2009-05-17 11:16:51 +00:00
};
Drupal.AjaxCommands.prototype.viewsTriggerPreview = function (ajax, response, status) {
2009-05-17 11:16:51 +00:00
if ($('input#edit-displays-live-preview').is(':checked')) {
$('#preview-submit').trigger('click');
}
};
Drupal.AjaxCommands.prototype.viewsReplaceTitle = function (ajax, response, status) {
const doc = document;
const oldTitle = doc.title;
const escapedSiteName = response.siteName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
const re = new RegExp(`.+ (.) ${escapedSiteName}`);
doc.title = oldTitle.replace(re, `${response.title} $1 ${response.siteName}`);
2009-05-17 11:16:51 +00:00
$('h1.page-title').text(response.title);
};
Drupal.theme.tableDragChangedWarning = function () {
return [];
};
2009-05-17 11:16:51 +00:00
Drupal.behaviors.livePreview = {
attach(context) {
$(once('views-ajax', 'input#edit-displays-live-preview', context)).on('click', function () {
2009-05-17 11:16:51 +00:00
if ($(this).is(':checked')) {
$('#preview-submit').trigger('click');
2009-05-17 11:16:51 +00:00
}
});
}
};
2009-05-17 11:16:51 +00:00
Drupal.behaviors.syncPreviewDisplay = {
attach(context) {
$(once('views-ajax', '#views-tabset a')).on('click', function () {
const href = $(this).attr('href');
const displayId = href.substr(11);
$('#views-live-preview #preview-display-id').val(displayId);
});
2009-05-17 11:16:51 +00:00
}
};
2009-05-17 11:16:51 +00:00
Drupal.behaviors.viewsAjax = {
collapseReplaced: false,
attach(context, settings) {
const baseElementSettings = {
event: 'click',
progress: {
type: 'fullscreen'
}
2009-05-17 11:16:51 +00:00
};
once('views-ajax', 'a.views-ajax-link', context).forEach(link => {
const $link = $(link);
const elementSettings = baseElementSettings;
elementSettings.base = $link.attr('id');
elementSettings.element = link;
if ($link.attr('href')) {
elementSettings.url = $link.attr('href');
2009-05-17 11:16:51 +00:00
}
Drupal.ajax(elementSettings);
2009-05-17 11:16:51 +00:00
});
once('views-ajax', 'div#views-live-preview a').forEach(link => {
const $link = $(link);
if (!$link.attr('href')) {
return true;
}
2009-05-17 11:16:51 +00:00
const elementSettings = baseElementSettings;
elementSettings.url = $link.attr('href');
if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
return true;
}
elementSettings.wrapper = 'views-preview-wrapper';
elementSettings.method = 'replaceWith';
elementSettings.base = link.id;
elementSettings.element = link;
Drupal.ajax(elementSettings);
});
once('views-ajax', 'div#views-live-preview input[type=submit]').forEach(submit => {
const $submit = $(submit);
$submit.on('click', function () {
this.form.clk = this;
return true;
2009-05-17 11:16:51 +00:00
});
const elementSettings = baseElementSettings;
elementSettings.url = $(submit.form).attr('action');
if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
return true;
}
2009-05-17 11:16:51 +00:00
elementSettings.wrapper = 'views-preview-wrapper';
elementSettings.method = 'replaceWith';
elementSettings.event = 'click';
elementSettings.base = submit.id;
elementSettings.element = submit;
Drupal.ajax(elementSettings);
});
2009-05-17 11:16:51 +00:00
}
2009-05-17 11:16:51 +00:00
};
})(jQuery, Drupal, drupalSettings);