annotate core/misc/ajax.js @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7 function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
Chris@0 8
Chris@0 9 (function ($, window, Drupal, drupalSettings) {
Chris@0 10 Drupal.behaviors.AJAX = {
Chris@0 11 attach: function attach(context, settings) {
Chris@0 12 function loadAjaxBehavior(base) {
Chris@0 13 var elementSettings = settings.ajax[base];
Chris@0 14 if (typeof elementSettings.selector === 'undefined') {
Chris@0 15 elementSettings.selector = '#' + base;
Chris@0 16 }
Chris@0 17 $(elementSettings.selector).once('drupal-ajax').each(function () {
Chris@0 18 elementSettings.element = this;
Chris@0 19 elementSettings.base = base;
Chris@0 20 Drupal.ajax(elementSettings);
Chris@0 21 });
Chris@0 22 }
Chris@0 23
Chris@0 24 Object.keys(settings.ajax || {}).forEach(function (base) {
Chris@0 25 return loadAjaxBehavior(base);
Chris@0 26 });
Chris@0 27
Chris@0 28 Drupal.ajax.bindAjaxLinks(document.body);
Chris@0 29
Chris@0 30 $('.use-ajax-submit').once('ajax').each(function () {
Chris@0 31 var elementSettings = {};
Chris@0 32
Chris@0 33 elementSettings.url = $(this.form).attr('action');
Chris@0 34
Chris@0 35 elementSettings.setClick = true;
Chris@0 36
Chris@0 37 elementSettings.event = 'click';
Chris@0 38
Chris@0 39 elementSettings.progress = { type: 'throbber' };
Chris@0 40 elementSettings.base = $(this).attr('id');
Chris@0 41 elementSettings.element = this;
Chris@0 42
Chris@0 43 Drupal.ajax(elementSettings);
Chris@0 44 });
Chris@0 45 },
Chris@0 46 detach: function detach(context, settings, trigger) {
Chris@0 47 if (trigger === 'unload') {
Chris@0 48 Drupal.ajax.expired().forEach(function (instance) {
Chris@0 49 Drupal.ajax.instances[instance.instanceIndex] = null;
Chris@0 50 });
Chris@0 51 }
Chris@0 52 }
Chris@0 53 };
Chris@0 54
Chris@0 55 Drupal.AjaxError = function (xmlhttp, uri, customMessage) {
Chris@0 56 var statusCode = void 0;
Chris@0 57 var statusText = void 0;
Chris@0 58 var responseText = void 0;
Chris@0 59 if (xmlhttp.status) {
Chris@0 60 statusCode = '\n' + Drupal.t('An AJAX HTTP error occurred.') + '\n' + Drupal.t('HTTP Result Code: !status', { '!status': xmlhttp.status });
Chris@0 61 } else {
Chris@0 62 statusCode = '\n' + Drupal.t('An AJAX HTTP request terminated abnormally.');
Chris@0 63 }
Chris@0 64 statusCode += '\n' + Drupal.t('Debugging information follows.');
Chris@0 65 var pathText = '\n' + Drupal.t('Path: !uri', { '!uri': uri });
Chris@0 66 statusText = '';
Chris@0 67
Chris@0 68 try {
Chris@0 69 statusText = '\n' + Drupal.t('StatusText: !statusText', { '!statusText': $.trim(xmlhttp.statusText) });
Chris@0 70 } catch (e) {}
Chris@0 71
Chris@0 72 responseText = '';
Chris@0 73
Chris@0 74 try {
Chris@0 75 responseText = '\n' + Drupal.t('ResponseText: !responseText', { '!responseText': $.trim(xmlhttp.responseText) });
Chris@0 76 } catch (e) {}
Chris@0 77
Chris@0 78 responseText = responseText.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi, '');
Chris@0 79 responseText = responseText.replace(/[\n]+\s+/g, '\n');
Chris@0 80
Chris@0 81 var readyStateText = xmlhttp.status === 0 ? '\n' + Drupal.t('ReadyState: !readyState', { '!readyState': xmlhttp.readyState }) : '';
Chris@0 82
Chris@0 83 customMessage = customMessage ? '\n' + Drupal.t('CustomMessage: !customMessage', { '!customMessage': customMessage }) : '';
Chris@0 84
Chris@0 85 this.message = statusCode + pathText + statusText + customMessage + responseText + readyStateText;
Chris@0 86
Chris@0 87 this.name = 'AjaxError';
Chris@0 88 };
Chris@0 89
Chris@0 90 Drupal.AjaxError.prototype = new Error();
Chris@0 91 Drupal.AjaxError.prototype.constructor = Drupal.AjaxError;
Chris@0 92
Chris@0 93 Drupal.ajax = function (settings) {
Chris@0 94 if (arguments.length !== 1) {
Chris@0 95 throw new Error('Drupal.ajax() function must be called with one configuration object only');
Chris@0 96 }
Chris@0 97
Chris@0 98 var base = settings.base || false;
Chris@0 99 var element = settings.element || false;
Chris@0 100 delete settings.base;
Chris@0 101 delete settings.element;
Chris@0 102
Chris@0 103 if (!settings.progress && !element) {
Chris@0 104 settings.progress = false;
Chris@0 105 }
Chris@0 106
Chris@0 107 var ajax = new Drupal.Ajax(base, element, settings);
Chris@0 108 ajax.instanceIndex = Drupal.ajax.instances.length;
Chris@0 109 Drupal.ajax.instances.push(ajax);
Chris@0 110
Chris@0 111 return ajax;
Chris@0 112 };
Chris@0 113
Chris@0 114 Drupal.ajax.instances = [];
Chris@0 115
Chris@0 116 Drupal.ajax.expired = function () {
Chris@0 117 return Drupal.ajax.instances.filter(function (instance) {
Chris@0 118 return instance && instance.element !== false && !document.body.contains(instance.element);
Chris@0 119 });
Chris@0 120 };
Chris@0 121
Chris@0 122 Drupal.ajax.bindAjaxLinks = function (element) {
Chris@0 123 $(element).find('.use-ajax').once('ajax').each(function (i, ajaxLink) {
Chris@0 124 var $linkElement = $(ajaxLink);
Chris@0 125
Chris@0 126 var elementSettings = {
Chris@0 127 progress: { type: 'throbber' },
Chris@0 128 dialogType: $linkElement.data('dialog-type'),
Chris@0 129 dialog: $linkElement.data('dialog-options'),
Chris@0 130 dialogRenderer: $linkElement.data('dialog-renderer'),
Chris@0 131 base: $linkElement.attr('id'),
Chris@0 132 element: ajaxLink
Chris@0 133 };
Chris@0 134 var href = $linkElement.attr('href');
Chris@0 135
Chris@0 136 if (href) {
Chris@0 137 elementSettings.url = href;
Chris@0 138 elementSettings.event = 'click';
Chris@0 139 }
Chris@0 140 Drupal.ajax(elementSettings);
Chris@0 141 });
Chris@0 142 };
Chris@0 143
Chris@0 144 Drupal.Ajax = function (base, element, elementSettings) {
Chris@0 145 var defaults = {
Chris@0 146 event: element ? 'mousedown' : null,
Chris@0 147 keypress: true,
Chris@0 148 selector: base ? '#' + base : null,
Chris@0 149 effect: 'none',
Chris@0 150 speed: 'none',
Chris@0 151 method: 'replaceWith',
Chris@0 152 progress: {
Chris@0 153 type: 'throbber',
Chris@0 154 message: Drupal.t('Please wait...')
Chris@0 155 },
Chris@0 156 submit: {
Chris@0 157 js: true
Chris@0 158 }
Chris@0 159 };
Chris@0 160
Chris@0 161 $.extend(this, defaults, elementSettings);
Chris@0 162
Chris@0 163 this.commands = new Drupal.AjaxCommands();
Chris@0 164
Chris@0 165 this.instanceIndex = false;
Chris@0 166
Chris@0 167 if (this.wrapper) {
Chris@0 168 this.wrapper = '#' + this.wrapper;
Chris@0 169 }
Chris@0 170
Chris@0 171 this.element = element;
Chris@0 172
Chris@0 173 this.element_settings = elementSettings;
Chris@0 174
Chris@0 175 this.elementSettings = elementSettings;
Chris@0 176
Chris@0 177 if (this.element && this.element.form) {
Chris@0 178 this.$form = $(this.element.form);
Chris@0 179 }
Chris@0 180
Chris@0 181 if (!this.url) {
Chris@0 182 var $element = $(this.element);
Chris@0 183 if ($element.is('a')) {
Chris@0 184 this.url = $element.attr('href');
Chris@0 185 } else if (this.element && element.form) {
Chris@0 186 this.url = this.$form.attr('action');
Chris@0 187 }
Chris@0 188 }
Chris@0 189
Chris@0 190 var originalUrl = this.url;
Chris@0 191
Chris@0 192 this.url = this.url.replace(/\/nojs(\/|$|\?|#)/g, '/ajax$1');
Chris@0 193
Chris@0 194 if (drupalSettings.ajaxTrustedUrl[originalUrl]) {
Chris@0 195 drupalSettings.ajaxTrustedUrl[this.url] = true;
Chris@0 196 }
Chris@0 197
Chris@0 198 var ajax = this;
Chris@0 199
Chris@0 200 ajax.options = {
Chris@0 201 url: ajax.url,
Chris@0 202 data: ajax.submit,
Chris@0 203 beforeSerialize: function beforeSerialize(elementSettings, options) {
Chris@0 204 return ajax.beforeSerialize(elementSettings, options);
Chris@0 205 },
Chris@0 206 beforeSubmit: function beforeSubmit(formValues, elementSettings, options) {
Chris@0 207 ajax.ajaxing = true;
Chris@0 208 return ajax.beforeSubmit(formValues, elementSettings, options);
Chris@0 209 },
Chris@0 210 beforeSend: function beforeSend(xmlhttprequest, options) {
Chris@0 211 ajax.ajaxing = true;
Chris@0 212 return ajax.beforeSend(xmlhttprequest, options);
Chris@0 213 },
Chris@0 214 success: function success(response, status, xmlhttprequest) {
Chris@0 215 if (typeof response === 'string') {
Chris@0 216 response = $.parseJSON(response);
Chris@0 217 }
Chris@0 218
Chris@0 219 if (response !== null && !drupalSettings.ajaxTrustedUrl[ajax.url]) {
Chris@0 220 if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') {
Chris@0 221 var customMessage = Drupal.t('The response failed verification so will not be processed.');
Chris@0 222 return ajax.error(xmlhttprequest, ajax.url, customMessage);
Chris@0 223 }
Chris@0 224 }
Chris@0 225
Chris@0 226 return ajax.success(response, status);
Chris@0 227 },
Chris@0 228 complete: function complete(xmlhttprequest, status) {
Chris@0 229 ajax.ajaxing = false;
Chris@0 230 if (status === 'error' || status === 'parsererror') {
Chris@0 231 return ajax.error(xmlhttprequest, ajax.url);
Chris@0 232 }
Chris@0 233 },
Chris@0 234
Chris@0 235 dataType: 'json',
Chris@0 236 type: 'POST'
Chris@0 237 };
Chris@0 238
Chris@0 239 if (elementSettings.dialog) {
Chris@0 240 ajax.options.data.dialogOptions = elementSettings.dialog;
Chris@0 241 }
Chris@0 242
Chris@0 243 if (ajax.options.url.indexOf('?') === -1) {
Chris@0 244 ajax.options.url += '?';
Chris@0 245 } else {
Chris@0 246 ajax.options.url += '&';
Chris@0 247 }
Chris@0 248
Chris@0 249 var wrapper = 'drupal_' + (elementSettings.dialogType || 'ajax');
Chris@0 250 if (elementSettings.dialogRenderer) {
Chris@0 251 wrapper += '.' + elementSettings.dialogRenderer;
Chris@0 252 }
Chris@0 253 ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=' + wrapper;
Chris@0 254
Chris@0 255 $(ajax.element).on(elementSettings.event, function (event) {
Chris@0 256 if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) {
Chris@0 257 throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { '!url': ajax.url }));
Chris@0 258 }
Chris@0 259 return ajax.eventResponse(this, event);
Chris@0 260 });
Chris@0 261
Chris@0 262 if (elementSettings.keypress) {
Chris@0 263 $(ajax.element).on('keypress', function (event) {
Chris@0 264 return ajax.keypressResponse(this, event);
Chris@0 265 });
Chris@0 266 }
Chris@0 267
Chris@0 268 if (elementSettings.prevent) {
Chris@0 269 $(ajax.element).on(elementSettings.prevent, false);
Chris@0 270 }
Chris@0 271 };
Chris@0 272
Chris@0 273 Drupal.ajax.WRAPPER_FORMAT = '_wrapper_format';
Chris@0 274
Chris@0 275 Drupal.Ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax';
Chris@0 276
Chris@0 277 Drupal.Ajax.prototype.execute = function () {
Chris@0 278 if (this.ajaxing) {
Chris@0 279 return;
Chris@0 280 }
Chris@0 281
Chris@0 282 try {
Chris@0 283 this.beforeSerialize(this.element, this.options);
Chris@0 284
Chris@0 285 return $.ajax(this.options);
Chris@0 286 } catch (e) {
Chris@0 287 this.ajaxing = false;
Chris@0 288 window.alert('An error occurred while attempting to process ' + this.options.url + ': ' + e.message);
Chris@0 289
Chris@0 290 return $.Deferred().reject();
Chris@0 291 }
Chris@0 292 };
Chris@0 293
Chris@0 294 Drupal.Ajax.prototype.keypressResponse = function (element, event) {
Chris@0 295 var ajax = this;
Chris@0 296
Chris@0 297 if (event.which === 13 || event.which === 32 && element.type !== 'text' && element.type !== 'textarea' && element.type !== 'tel' && element.type !== 'number') {
Chris@0 298 event.preventDefault();
Chris@0 299 event.stopPropagation();
Chris@0 300 $(element).trigger(ajax.elementSettings.event);
Chris@0 301 }
Chris@0 302 };
Chris@0 303
Chris@0 304 Drupal.Ajax.prototype.eventResponse = function (element, event) {
Chris@0 305 event.preventDefault();
Chris@0 306 event.stopPropagation();
Chris@0 307
Chris@0 308 var ajax = this;
Chris@0 309
Chris@0 310 if (ajax.ajaxing) {
Chris@0 311 return;
Chris@0 312 }
Chris@0 313
Chris@0 314 try {
Chris@0 315 if (ajax.$form) {
Chris@0 316 if (ajax.setClick) {
Chris@0 317 element.form.clk = element;
Chris@0 318 }
Chris@0 319
Chris@0 320 ajax.$form.ajaxSubmit(ajax.options);
Chris@0 321 } else {
Chris@0 322 ajax.beforeSerialize(ajax.element, ajax.options);
Chris@0 323 $.ajax(ajax.options);
Chris@0 324 }
Chris@0 325 } catch (e) {
Chris@0 326 ajax.ajaxing = false;
Chris@0 327 window.alert('An error occurred while attempting to process ' + ajax.options.url + ': ' + e.message);
Chris@0 328 }
Chris@0 329 };
Chris@0 330
Chris@0 331 Drupal.Ajax.prototype.beforeSerialize = function (element, options) {
Chris@0 332 if (this.$form) {
Chris@0 333 var settings = this.settings || drupalSettings;
Chris@0 334 Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize');
Chris@0 335 }
Chris@0 336
Chris@0 337 options.data[Drupal.Ajax.AJAX_REQUEST_PARAMETER] = 1;
Chris@0 338
Chris@0 339 var pageState = drupalSettings.ajaxPageState;
Chris@0 340 options.data['ajax_page_state[theme]'] = pageState.theme;
Chris@0 341 options.data['ajax_page_state[theme_token]'] = pageState.theme_token;
Chris@0 342 options.data['ajax_page_state[libraries]'] = pageState.libraries;
Chris@0 343 };
Chris@0 344
Chris@0 345 Drupal.Ajax.prototype.beforeSubmit = function (formValues, element, options) {};
Chris@0 346
Chris@0 347 Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) {
Chris@0 348 if (this.$form) {
Chris@0 349 options.extraData = options.extraData || {};
Chris@0 350
Chris@0 351 options.extraData.ajax_iframe_upload = '1';
Chris@0 352
Chris@0 353 var v = $.fieldValue(this.element);
Chris@0 354 if (v !== null) {
Chris@0 355 options.extraData[this.element.name] = v;
Chris@0 356 }
Chris@0 357 }
Chris@0 358
Chris@0 359 $(this.element).prop('disabled', true);
Chris@0 360
Chris@0 361 if (!this.progress || !this.progress.type) {
Chris@0 362 return;
Chris@0 363 }
Chris@0 364
Chris@0 365 var progressIndicatorMethod = 'setProgressIndicator' + this.progress.type.slice(0, 1).toUpperCase() + this.progress.type.slice(1).toLowerCase();
Chris@0 366 if (progressIndicatorMethod in this && typeof this[progressIndicatorMethod] === 'function') {
Chris@0 367 this[progressIndicatorMethod].call(this);
Chris@0 368 }
Chris@0 369 };
Chris@0 370
Chris@0 371 Drupal.Ajax.prototype.setProgressIndicatorBar = function () {
Chris@0 372 var progressBar = new Drupal.ProgressBar('ajax-progress-' + this.element.id, $.noop, this.progress.method, $.noop);
Chris@0 373 if (this.progress.message) {
Chris@0 374 progressBar.setProgress(-1, this.progress.message);
Chris@0 375 }
Chris@0 376 if (this.progress.url) {
Chris@0 377 progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500);
Chris@0 378 }
Chris@0 379 this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar');
Chris@0 380 this.progress.object = progressBar;
Chris@0 381 $(this.element).after(this.progress.element);
Chris@0 382 };
Chris@0 383
Chris@0 384 Drupal.Ajax.prototype.setProgressIndicatorThrobber = function () {
Chris@0 385 this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber">&nbsp;</div></div>');
Chris@0 386 if (this.progress.message) {
Chris@0 387 this.progress.element.find('.throbber').after('<div class="message">' + this.progress.message + '</div>');
Chris@0 388 }
Chris@0 389 $(this.element).after(this.progress.element);
Chris@0 390 };
Chris@0 391
Chris@0 392 Drupal.Ajax.prototype.setProgressIndicatorFullscreen = function () {
Chris@0 393 this.progress.element = $('<div class="ajax-progress ajax-progress-fullscreen">&nbsp;</div>');
Chris@0 394 $('body').after(this.progress.element);
Chris@0 395 };
Chris@0 396
Chris@0 397 Drupal.Ajax.prototype.success = function (response, status) {
Chris@0 398 var _this = this;
Chris@0 399
Chris@0 400 if (this.progress.element) {
Chris@0 401 $(this.progress.element).remove();
Chris@0 402 }
Chris@0 403 if (this.progress.object) {
Chris@0 404 this.progress.object.stopMonitoring();
Chris@0 405 }
Chris@0 406 $(this.element).prop('disabled', false);
Chris@0 407
Chris@0 408 var elementParents = $(this.element).parents('[data-drupal-selector]').addBack().toArray();
Chris@0 409
Chris@0 410 var focusChanged = false;
Chris@0 411 Object.keys(response || {}).forEach(function (i) {
Chris@0 412 if (response[i].command && _this.commands[response[i].command]) {
Chris@0 413 _this.commands[response[i].command](_this, response[i], status);
Chris@0 414 if (response[i].command === 'invoke' && response[i].method === 'focus') {
Chris@0 415 focusChanged = true;
Chris@0 416 }
Chris@0 417 }
Chris@0 418 });
Chris@0 419
Chris@0 420 if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) {
Chris@0 421 var target = false;
Chris@0 422
Chris@0 423 for (var n = elementParents.length - 1; !target && n > 0; n--) {
Chris@0 424 target = document.querySelector('[data-drupal-selector="' + elementParents[n].getAttribute('data-drupal-selector') + '"]');
Chris@0 425 }
Chris@0 426
Chris@0 427 if (target) {
Chris@0 428 $(target).trigger('focus');
Chris@0 429 }
Chris@0 430 }
Chris@0 431
Chris@0 432 if (this.$form) {
Chris@0 433 var settings = this.settings || drupalSettings;
Chris@0 434 Drupal.attachBehaviors(this.$form.get(0), settings);
Chris@0 435 }
Chris@0 436
Chris@0 437 this.settings = null;
Chris@0 438 };
Chris@0 439
Chris@0 440 Drupal.Ajax.prototype.getEffect = function (response) {
Chris@0 441 var type = response.effect || this.effect;
Chris@0 442 var speed = response.speed || this.speed;
Chris@0 443
Chris@0 444 var effect = {};
Chris@0 445 if (type === 'none') {
Chris@0 446 effect.showEffect = 'show';
Chris@0 447 effect.hideEffect = 'hide';
Chris@0 448 effect.showSpeed = '';
Chris@0 449 } else if (type === 'fade') {
Chris@0 450 effect.showEffect = 'fadeIn';
Chris@0 451 effect.hideEffect = 'fadeOut';
Chris@0 452 effect.showSpeed = speed;
Chris@0 453 } else {
Chris@0 454 effect.showEffect = type + 'Toggle';
Chris@0 455 effect.hideEffect = type + 'Toggle';
Chris@0 456 effect.showSpeed = speed;
Chris@0 457 }
Chris@0 458
Chris@0 459 return effect;
Chris@0 460 };
Chris@0 461
Chris@0 462 Drupal.Ajax.prototype.error = function (xmlhttprequest, uri, customMessage) {
Chris@0 463 if (this.progress.element) {
Chris@0 464 $(this.progress.element).remove();
Chris@0 465 }
Chris@0 466 if (this.progress.object) {
Chris@0 467 this.progress.object.stopMonitoring();
Chris@0 468 }
Chris@0 469
Chris@0 470 $(this.wrapper).show();
Chris@0 471
Chris@0 472 $(this.element).prop('disabled', false);
Chris@0 473
Chris@0 474 if (this.$form) {
Chris@0 475 var settings = this.settings || drupalSettings;
Chris@0 476 Drupal.attachBehaviors(this.$form.get(0), settings);
Chris@0 477 }
Chris@0 478 throw new Drupal.AjaxError(xmlhttprequest, uri, customMessage);
Chris@0 479 };
Chris@0 480
Chris@0 481 Drupal.AjaxCommands = function () {};
Chris@0 482 Drupal.AjaxCommands.prototype = {
Chris@0 483 insert: function insert(ajax, response, status) {
Chris@0 484 var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
Chris@0 485 var method = response.method || ajax.method;
Chris@0 486 var effect = ajax.getEffect(response);
Chris@0 487 var settings = void 0;
Chris@0 488
Chris@0 489 var $newContentWrapped = $('<div></div>').html(response.data);
Chris@0 490 var $newContent = $newContentWrapped.contents();
Chris@0 491
Chris@0 492 if ($newContent.length !== 1 || $newContent.get(0).nodeType !== 1) {
Chris@0 493 $newContent = $newContentWrapped;
Chris@0 494 }
Chris@0 495
Chris@0 496 switch (method) {
Chris@0 497 case 'html':
Chris@0 498 case 'replaceWith':
Chris@0 499 case 'replaceAll':
Chris@0 500 case 'empty':
Chris@0 501 case 'remove':
Chris@0 502 settings = response.settings || ajax.settings || drupalSettings;
Chris@0 503 Drupal.detachBehaviors($wrapper.get(0), settings);
Chris@0 504 }
Chris@0 505
Chris@0 506 $wrapper[method]($newContent);
Chris@0 507
Chris@0 508 if (effect.showEffect !== 'show') {
Chris@0 509 $newContent.hide();
Chris@0 510 }
Chris@0 511
Chris@0 512 if ($newContent.find('.ajax-new-content').length > 0) {
Chris@0 513 $newContent.find('.ajax-new-content').hide();
Chris@0 514 $newContent.show();
Chris@0 515 $newContent.find('.ajax-new-content')[effect.showEffect](effect.showSpeed);
Chris@0 516 } else if (effect.showEffect !== 'show') {
Chris@0 517 $newContent[effect.showEffect](effect.showSpeed);
Chris@0 518 }
Chris@0 519
Chris@0 520 if ($newContent.parents('html').length > 0) {
Chris@0 521 settings = response.settings || ajax.settings || drupalSettings;
Chris@0 522 Drupal.attachBehaviors($newContent.get(0), settings);
Chris@0 523 }
Chris@0 524 },
Chris@0 525 remove: function remove(ajax, response, status) {
Chris@0 526 var settings = response.settings || ajax.settings || drupalSettings;
Chris@0 527 $(response.selector).each(function () {
Chris@0 528 Drupal.detachBehaviors(this, settings);
Chris@0 529 }).remove();
Chris@0 530 },
Chris@0 531 changed: function changed(ajax, response, status) {
Chris@0 532 var $element = $(response.selector);
Chris@0 533 if (!$element.hasClass('ajax-changed')) {
Chris@0 534 $element.addClass('ajax-changed');
Chris@0 535 if (response.asterisk) {
Chris@0 536 $element.find(response.asterisk).append(' <abbr class="ajax-changed" title="' + Drupal.t('Changed') + '">*</abbr> ');
Chris@0 537 }
Chris@0 538 }
Chris@0 539 },
Chris@0 540 alert: function alert(ajax, response, status) {
Chris@0 541 window.alert(response.text, response.title);
Chris@0 542 },
Chris@0 543 redirect: function redirect(ajax, response, status) {
Chris@0 544 window.location = response.url;
Chris@0 545 },
Chris@0 546 css: function css(ajax, response, status) {
Chris@0 547 $(response.selector).css(response.argument);
Chris@0 548 },
Chris@0 549 settings: function settings(ajax, response, status) {
Chris@0 550 var ajaxSettings = drupalSettings.ajax;
Chris@0 551
Chris@0 552 if (ajaxSettings) {
Chris@0 553 Drupal.ajax.expired().forEach(function (instance) {
Chris@0 554
Chris@0 555 if (instance.selector) {
Chris@0 556 var selector = instance.selector.replace('#', '');
Chris@0 557 if (selector in ajaxSettings) {
Chris@0 558 delete ajaxSettings[selector];
Chris@0 559 }
Chris@0 560 }
Chris@0 561 });
Chris@0 562 }
Chris@0 563
Chris@0 564 if (response.merge) {
Chris@0 565 $.extend(true, drupalSettings, response.settings);
Chris@0 566 } else {
Chris@0 567 ajax.settings = response.settings;
Chris@0 568 }
Chris@0 569 },
Chris@0 570 data: function data(ajax, response, status) {
Chris@0 571 $(response.selector).data(response.name, response.value);
Chris@0 572 },
Chris@0 573 invoke: function invoke(ajax, response, status) {
Chris@0 574 var $element = $(response.selector);
Chris@0 575 $element[response.method].apply($element, _toConsumableArray(response.args));
Chris@0 576 },
Chris@0 577 restripe: function restripe(ajax, response, status) {
Chris@0 578 $(response.selector).find('> tbody > tr:visible, > tr:visible').removeClass('odd even').filter(':even').addClass('odd').end().filter(':odd').addClass('even');
Chris@0 579 },
Chris@0 580 update_build_id: function update_build_id(ajax, response, status) {
Chris@0 581 $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
Chris@0 582 },
Chris@0 583 add_css: function add_css(ajax, response, status) {
Chris@0 584 $('head').prepend(response.data);
Chris@0 585
Chris@0 586 var match = void 0;
Chris@0 587 var importMatch = /^@import url\("(.*)"\);$/igm;
Chris@0 588 if (document.styleSheets[0].addImport && importMatch.test(response.data)) {
Chris@0 589 importMatch.lastIndex = 0;
Chris@0 590 do {
Chris@0 591 match = importMatch.exec(response.data);
Chris@0 592 document.styleSheets[0].addImport(match[1]);
Chris@0 593 } while (match);
Chris@0 594 }
Chris@0 595 }
Chris@0 596 };
Chris@0 597 })(jQuery, window, Drupal, drupalSettings);