1(function ($) { 2 3/** 4 * Prevents consecutive form submissions of identical form values. 5 * 6 * Repetitive form submissions that would submit the identical form values are 7 * prevented, unless the form values are different from the previously 8 * submitted values. 9 * 10 * This is a simplified re-implementation of a user-agent behavior that should 11 * be natively supported by major web browsers, but at this time, only Firefox 12 * has a built-in protection. 13 * 14 * A form value-based approach ensures that the constraint is triggered for 15 * consecutive, identical form submissions only. Compared to that, a form 16 * button-based approach would (1) rely on [visible] buttons to exist where 17 * technically not required and (2) require more complex state management if 18 * there are multiple buttons in a form. 19 * 20 * This implementation is based on form-level submit events only and relies on 21 * jQuery's serialize() method to determine submitted form values. As such, the 22 * following limitations exist: 23 * 24 * - Event handlers on form buttons that preventDefault() do not receive a 25 * double-submit protection. That is deemed to be fine, since such button 26 * events typically trigger reversible client-side or server-side operations 27 * that are local to the context of a form only. 28 * - Changed values in advanced form controls, such as file inputs, are not part 29 * of the form values being compared between consecutive form submits (due to 30 * limitations of jQuery.serialize()). That is deemed to be acceptable, 31 * because if the user forgot to attach a file, then the size of HTTP payload 32 * will most likely be small enough to be fully passed to the server endpoint 33 * within (milli)seconds. If a user mistakenly attached a wrong file and is 34 * technically versed enough to cancel the form submission (and HTTP payload) 35 * in order to attach a different file, then that edge-case is not supported 36 * here. 37 * 38 * Lastly, all forms submitted via HTTP GET are idempotent by definition of HTTP 39 * standards, so excluded in this implementation. 40 */ 41Drupal.behaviors.formSingleSubmit = { 42 attach: function () { 43 function onFormSubmit (e) { 44 var $form = $(e.currentTarget); 45 var formValues = $form.serialize(); 46 var previousValues = $form.attr('data-drupal-form-submit-last'); 47 if (previousValues === formValues) { 48 e.preventDefault(); 49 } 50 else { 51 $form.attr('data-drupal-form-submit-last', formValues); 52 } 53 } 54 55 $('body').once('form-single-submit') 56 .delegate('form:not([method~="GET"])', 'submit.singleSubmit', onFormSubmit); 57 } 58}; 59 60})(jQuery); 61 62;/*})'"*/ 63;/*})'"*/ 64(function ($) { 65 66/** 67 * Provides Ajax page updating via jQuery $.ajax (Asynchronous JavaScript and XML). 68 * 69 * Ajax is a method of making a request via JavaScript while viewing an HTML 70 * page. The request returns an array of commands encoded in JSON, which is 71 * then executed to make any changes that are necessary to the page. 72 * 73 * Drupal uses this file to enhance form elements with #ajax['path'] and 74 * #ajax['wrapper'] properties. If set, this file will automatically be included 75 * to provide Ajax capabilities. 76 */ 77 78Drupal.ajax = Drupal.ajax || {}; 79 80Drupal.settings.urlIsAjaxTrusted = Drupal.settings.urlIsAjaxTrusted || {}; 81 82/** 83 * Attaches the Ajax behavior to each Ajax form element. 84 */ 85Drupal.behaviors.AJAX = { 86 attach: function (context, settings) { 87 // Load all Ajax behaviors specified in the settings. 88 for (var base in settings.ajax) { 89 if (!$('#' + base + '.ajax-processed').length) { 90 var element_settings = settings.ajax[base]; 91 92 if (typeof element_settings.selector == 'undefined') { 93 element_settings.selector = '#' + base; 94 } 95 $(element_settings.selector).each(function () { 96 element_settings.element = this; 97 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 98 }); 99 100 $('#' + base).addClass('ajax-processed'); 101 } 102 } 103 104 // Bind Ajax behaviors to all items showing the class. 105 $('.use-ajax:not(.ajax-processed)').addClass('ajax-processed').each(function () { 106 var element_settings = {}; 107 // Clicked links look better with the throbber than the progress bar. 108 element_settings.progress = { 'type': 'throbber' }; 109 110 // For anchor tags, these will go to the target of the anch
110or rather 111 // than the usual location. 112 if ($(this).attr('href')) { 113 element_settings.url = $(this).attr('href'); 114 element_settings.event = 'click'; 115 } 116 var base = $(this).attr('id'); 117 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 118 }); 119 120 // This class means to submit the form to the action using Ajax. 121 $('.use-ajax-submit:not(.ajax-processed)').addClass('ajax-processed').each(function () { 122 var element_settings = {}; 123 124 // Ajax submits specified in this manner automatically submit to the 125 // normal form action. 126 element_settings.url = $(this.form).attr('action'); 127 // Form submit button clicks need to tell the form what was clicked so 128 // it gets passed in the POST request. 129 element_settings.setClick = true; 130 // Form buttons use the 'click' event rather than mousedown. 131 element_settings.event = 'click'; 132 // Clicked form buttons look better with the throbber than the progress bar. 133 element_settings.progress = { 'type': 'throbber' }; 134 135 var base = $(this).attr('id'); 136 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 137 }); 138 } 139}; 140 141/** 142 * Ajax object. 143 * 144 * All Ajax objects on a page are accessible through the global Drupal.ajax 145 * object and are keyed by the submit button's ID. You can access them from 146 * your module's JavaScript file to override properties or functions. 147 * 148 * For example, if your Ajax enabled button has the ID 'edit-submit', you can 149 * redefine the function that is called to insert the new content like this 150 * (inside a Drupal.behaviors attach block): 151 * @code 152 * Drupal.behaviors.myCustomAJAXStuff = { 153 * attach: function (context, settings) { 154 * Drupal.ajax['edit-submit'].commands.insert = function (ajax, response, status) { 155 * new_content = $(response.data); 156 * $('#my-wrapper').append(new_content); 157 * alert('New content was appended to #my-wrapper'); 158 * } 159 * } 160 * }; 161 * @endcode 162 */ 163Drupal.ajax = function (base, element, element_settings) { 164 var defaults = { 165 url: 'system/ajax', 166 event: 'mousedown', 167 keypress: true, 168 selector: '#' + base, 169 effect: 'none', 170 speed: 'none', 171 method: 'replaceWith', 172 progress: { 173 type: 'throbber', 174 message: Drupal.t('Please wait...') 175 }, 176 submit: { 177 'js': true 178 } 179 }; 180 181 $.extend(this, defaults, element_settings); 182 183 this.element = element; 184 this.element_settings = element_settings; 185 186 // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let 187 // the server detect when it needs to degrade gracefully. 188 // There are five scenarios to check for: 189 // 1. /nojs/ 190 // 2. /nojs$ - The end of a URL string. 191 // 3. /nojs? - Followed by a query (with clean URLs enabled). 192 // E.g.: path/nojs?destination=foobar 193 // 4. /nojs& - Followed by a query (without clean URLs enabled). 194 // E.g.: ?q=path/nojs&destination=foobar 195 // 5. /nojs# - Followed by a fragment. 196 // E.g.: path/nojs#myfragment 197 this.url = element_settings.url.replace(/\/nojs(\/|$|\?|&|#)/g, '/ajax$1'); 198 // If the 'nojs' version of the URL is trusted, also trust the 'ajax' version. 199 if (Drupal.settings.urlIsAjaxTrusted[element_settings.url]) { 200 Drupal.settings.urlIsAjaxTrusted[this.url] = true; 201 } 202 203 this.wrapper = '#' + element_settings.wrapper; 204 205 // If there isn't a form, jQuery.ajax() will be used instead, allowing us to 206 // bind Ajax to links as well. 207 if (this.element.form) { 208 this.form = $(this.element.form); 209 } 210 211 // Set the options for the ajaxSubmit function. 212 // The 'this' variable will not persist inside of the options object. 213 var ajax = this; 214 ajax.options = { 215 url: Drupal.sanitizeAjaxUrl(ajax.url), 216 data: ajax.submit, 217 beforeSerialize: function (element_settings, options) { 218 return ajax.beforeSerialize(element_settings, options); 219 }, 220 beforeSubmit: function (form_values, element_settings, options) { 221 ajax.ajaxing = true; 222 return ajax.beforeSubmit(form_values, element_settings, options); 223 }, 224 beforeSend: function (xmlhttprequest, options) { 225 ajax.ajaxing = true; 226 return ajax.beforeSend(xmlhttprequest, options); 227 }, 228 success: function (response, status, xmlhttprequest) { 229 // Sanity check for browser support (object expected). 230 // When using iFrame uploads, responses must be returned as a string. 231 if (typeof response == 'string') { 232 response = $.parseJSON(response); 233 } 234 235 // Prior to invoking the response's commands, verify that they can be 236 // trusted by checking for a response header. See 237 // ajax_set_verification_header() for details. 238 // - Empty responses are harmless so can bypass verification. This avoids 239 // an alert message for server-generated no-op responses that skip Ajax 240 // rendering. 241 // - Ajax objects with trusted URLs (e.g., ones defined server-side via 242 // #ajax) can bypass header verification. This is especially useful for 243 // Ajax with multipart forms. Because IFRAME transport is used, the 244 // response headers cannot be accessed for verification. 245 if (response !== null && !Drupal.settings.urlIsAjaxTrusted[ajax.url]) { 246 if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') { 247 var customMessage = Drupal.t("The response failed verification so will not be processed."); 248 return ajax.error(xmlhttprequest, ajax.url, customMessage); 249 } 250 } 251 252 return ajax.success(response, status); 253 }, 254 complete: function (xmlhttprequest, status) { 255 ajax.ajaxing = false;
256 if (status == 'error' || status == 'parsererror') { 257 return ajax.error(xmlhttprequest, ajax.url); 258 } 259 }, 260 dataType: 'json', 261 jsonp: false, 262 type: 'POST' 263 }; 264 265 // For multipart forms (e.g., file uploads), jQuery Form targets the form 266 // submission to an iframe instead of using an XHR object. The initial "src" 267 // of the iframe, prior to the form submission, is set to options.iframeSrc. 268 // "about:blank" is the semantically correct, standards-compliant, way to 269 // initialize a blank iframe; however, some old IE versions (possibly only 6) 270 // incorrectly report a mixed content warning when iframes with an 271 // "about:blank" src are added to a parent document with an https:// origin. 272 // jQuery Form works around this by defaulting to "javascript:false" instead, 273 // but that breaks on Chrome 83, so here we force the semantically correct 274 // behavior for all browsers except old IE. 275 // @see https://www.drupal.org/project/drupal/issues/3143016 276 // @see https://github.com/jquery-form/form/blob/df9cb101b9c9c085c8d75ad980c7ff1cf62063a1/jquery.form.js#L68 277 // @see https://bugs.chromium.org/p/chromium/issues/detail?id=1084874 278 // @see https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts 279 // @see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy 280 if (navigator.userAgent.indexOf("MSIE") === -1) { 281 ajax.options.iframeSrc = 'about:blank'; 282 } 283 284 // Bind the ajaxSubmit function to the element event. 285 $(ajax.element).bind(element_settings.event, function (event) { 286 if (!Drupal.settings.urlIsAjaxTrusted[ajax.url] && !Drupal.urlIsLocal(ajax.url)) { 287 throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', {'!url': ajax.url})); 288 } 289 return ajax.eventResponse(this, event); 290 }); 291 292 // If necessary, enable keyboard submission so that Ajax behaviors 293 // can be triggered through keyboard input as well as e.g. a mousedown 294 // action. 295 if (element_settings.keypress) { 296 $(ajax.element).keypress(function (event) { 297 return ajax.keypressResponse(this, event); 298 }); 299 } 300 301 // If necessary, prevent the browser default action of an additional event. 302 // For example, prevent the browser default action of a click, even if the 303 // AJAX behavior binds to mousedown. 304 if (element_settings.prevent) { 305 $(ajax.element).bind(element_settings.prevent, false); 306 } 307}; 308 309/** 310 * Handle a key press. 311 * 312 * The Ajax object will, if instructed, bind to a key press response. This 313 * will test to see if the key press is valid to trigger this event and 314 * if it is, trigger it for us and prevent other keypresses from triggering. 315 * In this case we're handling RETURN and SPACEBAR keypresses (event codes 13 316 * and 32. RETURN is often used to submit a form when in a textfield, and 317 * SPACE is often used to activate an element without submitting. 318 */ 319Drupal.ajax.prototype.keypressResponse = function (element, event) { 320 // Create a synonym for this to reduce code confusion. 321 var ajax = this; 322 323 // Detect enter key and space bar and allow the standard response for them, 324 // except for form elements of type 'text' and 'textarea', where the 325 // spacebar activation causes inappropriate activation if #ajax['keypress'] is 326 // TRUE. On a text-type widget a space should always be a space. 327 if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) { 328 $(ajax.element_settings.element).trigger(ajax.element_settings.event); 329 return false; 330 } 331}; 332 333/** 334 * Handle an event that triggers an Ajax response. 335 * 336 * When an event that triggers an Ajax response happens, this method will 337 * perform the actual Ajax call. It is bound to the event using 338 * bind() in the constructor, and it uses the options specified on the 339 * ajax object. 340 */ 341Drupal.ajax.prototype.eventResponse = function (element, event) { 342 // Create a synonym for this to reduce code confusion. 343 var ajax = this; 344 345 // Do not perform another ajax command if one is already in progress. 346 if (ajax.ajaxing) { 347 return false; 348 } 349 350 try { 351 if (ajax.form) { 352 // If setClick is set, we must set this to ensure that the button's 353 // value is passed. 354 if (ajax.setClick) { 355 // Mark the clicked button. 'form.clk' is a special variable for 356 // ajaxSubmit that tells the system which element got clicked to 357 // trigger the submit. Without it there would be no 'op' or
358 // equivalent. 359 element.form.clk = element; 360 } 361 362 ajax.form.ajaxSubmit(ajax.options); 363 } 364 else { 365 ajax.beforeSerialize(ajax.element, ajax.options); 366 $.ajax(ajax.options); 367 } 368 } 369 catch (e) { 370 // Unset the ajax.ajaxing flag here because it won't be unset during 371 // the complete response. 372 ajax.ajaxing = false; 373 alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message); 374 } 375 376 // For radio/checkbox, allow the default event. On IE, this means letting 377 // it actually check the box. 378 if (typeof element.type != 'undefined' && (element.type == 'checkbox' || element.type == 'radio')) { 379 return true; 380 } 381 else { 382 return false; 383 } 384 385}; 386 387/** 388 * Handler for the form serialization. 389 * 390 * Runs before the beforeSend() handler (see below), and unlike that one, runs 391 * before field data is collected. 392 */ 393Drupal.ajax.prototype.beforeSerialize = function (element, options) { 394 // Allow detaching behaviors to update field values before collecting them. 395 // This is only needed when field values are added to the POST data, so only 396 // when there is a form such that this.form.ajaxSubmit() is used instead of 397 // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize() 398 // isn't called, but don't rely on that: explicitly check this.form. 399 if (this.form) { 400 var settings = this.settings || Drupal.settings; 401 Drupal.detachBehaviors(this.form, settings, 'serialize'); 402 } 403 404 // Prevent duplicate HTML ids in the returned markup. 405 // @see drupal_html_id() 406 options.data['ajax_html_ids[]'] = []; 407 $('[id]').each(function () { 408 options.data['ajax_html_ids[]'].push(this.id); 409 }); 410 411 // Allow Drupal to return new JavaScript and CSS files to load without 412 // returning the ones already loaded. 413 // @see ajax_base_page_theme() 414 // @see drupal_get_css() 415 // @see drupal_get_js() 416 options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme; 417 options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token; 418 for (var key in Drupal.settings.ajaxPageState.css) { 419 options.data['ajax_page_state[css][' + key + ']'] = 1; 420 } 421 for (var key in Drupal.settings.ajaxPageState.js) { 422 options.data['ajax_page_state[js][' + key + ']'] = 1; 423 } 424}; 425 426/** 427 * Modify form values prior to form submission. 428 */ 429Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) { 430 // This function is left empty to make it simple to override for modules 431 // that wish to add functionality here. 432}; 433 434/** 435 * Prepare the Ajax request before it is sent. 436 */ 437Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) { 438 // For forms without file inputs, the jQuery Form plugin serializes the form 439 // values, and then calls jQuery's $.ajax() function, which invokes this 440 // handler. In this circumstance, options.extraData is never used. For forms 441 // with file inputs, the jQuery Form plugin uses the browser's normal form 442 // submission mechanism, but captures the response in a hidden IFRAME. In this 443 // circumstance, it calls this handler first, and then appends hidden fields 444 // to the form to submit the values in options.extraData. There is no simple 445 // way to know which submission mechanism will be used, so we add to extraData 446 // regardless, and allow it to be ignored in the former case. 447 if (this.form) { 448 options.extraData = options.extraData || {}; 449 450 // Let the server know when the IFRAME submission mechanism is used. The 451 // server can use this information to wrap the JSON response in a TEXTAREA, 452 // as per http://jquery.malsup.com/form/#file-upload. 453 options.extraData.ajax_iframe_upload = '1'; 454 455 // The triggering element is about to be disabled (see below), but if it 456 // contains a value (e.g., a checkbox, textfield, select, etc.), ensure that 457 // value is included in the submission. As per above, submissions that use 458 // $.ajax() are already serialized prior to the element being disabled, so 459 // this is only needed for IFRAME submissions. 460 var v = $.fieldValue(this.element); 461 if (v !== null) { 462 options.extraData[this.element.name] = Drupal.checkPlain(v); 463 } 464 } 465 466 // Disable the element that received the change to prevent user interface 467 // interaction while the Ajax request is in progress. ajax.ajaxing prevents 468 // the element from triggering a new request, but does not prevent the user 469 // from changing its value. 470 $(this.element).addClass('progress-disabled').attr('disabled', true); 471 472 // Insert progressbar or throbber. 473 if (this.progress.type == 'bar') { 474 var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.i
474d, $.noop, this.progress.method, $.noop); 475 if (this.progress.message) { 476 progressBar.setProgress(-1, this.progress.message); 477 } 478 if (this.progress.url) { 479 progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500); 480 } 481 this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar'); 482 this.progress.object = progressBar; 483 $(this.element).after(this.progress.element); 484 } 485 else if (this.progress.type == 'throbber') { 486 this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber"> </div></div>'); 487 if (this.progress.message) { 488 $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); 489 } 490 $(this.element).after(this.progress.element); 491 } 492}; 493 494/** 495 * Handler for the form redirection completion. 496 */ 497Drupal.ajax.prototype.success = function (response, status) { 498 // Remove the progress element. 499 if (this.progress.element) { 500 $(this.progress.element).remove(); 501 } 502 if (this.progress.object) { 503 this.progress.object.stopMonitoring(); 504 } 505 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 506 507 Drupal.freezeHeight(); 508 509 for (var i in response) { 510 if (response.hasOwnProperty(i) && response[i]['command'] && this.commands[response[i]['command']]) { 511 this.commands[response[i]['command']](this, response[i], status); 512 } 513 } 514 515 // Reattach behaviors, if they were detached in beforeSerialize(). The 516 // attachBehaviors() called on the new content from processing the response 517 // commands is not sufficient, because behaviors from the entire form need 518 // to be reattached. 519 if (this.form) { 520 var settings = this.settings || Drupal.settings; 521 Drupal.attachBehaviors(this.form, settings); 522 } 523 524 Drupal.unfreezeHeight(); 525 526 // Remove any response-specific settings so they don't get used on the next 527 // call by mistake. 528 this.settings = null; 529}; 530 531/** 532 * Build an effect object which tells us how to apply the effect when adding new HTML. 533 */ 534Drupal.ajax.prototype.getEffect = function (response) { 535 var type = response.effect || this.effect; 536 var speed = response.speed || this.speed; 537 538 var effect = {}; 539 if (type == 'none') { 540 effect.showEffect = 'show'; 541 effect.hideEffect = 'hide'; 542 effect.showSpeed = ''; 543 } 544 else if (type == 'fade') { 545 effect.showEffect = 'fadeIn'; 546 effect.hideEffect = 'fadeOut'; 547 effect.showSpeed = speed; 548 } 549 else { 550 effect.showEffect = type + 'Toggle'; 551 effect.hideEffect = type + 'Toggle'; 552 effect.showSpeed = speed; 553 } 554 555 return effect; 556}; 557 558/** 559 * Handler for the form redirection error. 560 */ 561Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { 562 Drupal.displayAjaxError(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); 563 // Remove the progress element. 564 if (this.progress.element) { 565 $(this.progress.element).remove(); 566 } 567 if (this.progress.object) { 568 this.progress.object.stopMonitoring(); 569 } 570 // Undo hide. 571 $(this.wrapper).show(); 572 // Re-enable the element. 573 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 574 // Reattach behaviors, if they were detached in beforeSerialize(). 575 if (this.form) { 576 var settings = this.settings || Drupal.settings; 577 Drupal.attachBehaviors(this.form, settings); 578 } 579}; 580 581/** 582 * Provide a series of commands that the server can request the client perform. 583 */ 584Drupal.ajax.prototype.commands = { 585 /** 586 * Command to insert new content into the DOM. 587 */ 588 insert: function (ajax, response, status) { 589 // Get information from the response. If it is not there, default to 590 // our presets. 591 var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper); 592 var method = response.method || ajax.method; 593 var effect = ajax.getEffect(response); 594 595 // We don't know what response.data contains: it might be a string of text 596 // without HTML, so don't rely on jQuery correctly iterpreting 597 // $(response.data) as new HTML rather than a CSS selector. Also, if 598 // response.data contains top-level text nodes, they get lost with either 599 // $(response.data) or $('<div></div>').replaceWith(response.data). 600 var new_content_wrapped = $('<div></div>').html(response.data); 601 var new_content = new_content_wrapped.contents(); 602 603 // For legacy reasons, the effects processing code assumes that new_content 604 // consists of a single top-level element. Also, it has not been 605 // sufficiently tested whether attachBehaviors() can be successfully called 606 // with a context object that includes top-level text nodes. However, to 607 // give developers full control of the HTML appearing in the page, and to 608 // enable Ajax content to be inserted in places where DIV elements are not 609 // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new 610 // content satisfies the requirement of a single top-level element, and 611 // only use the container DIV created above when it doesn't. For more 612 // information, please see http://drupal.org/node/736066. 613 if (new_content.length != 1 || new_content.get(0).nodeType != 1) { 614 new_content = new_content_wrapped; 615 } 616 617 // If removing content from the wrapper, detach behaviors first. 618 switch (method) { 619 case 'html': 620 case 'replaceWith': 621 case 'replaceAll': 622 case 'empty': 623 case 'remove': 624 var settings = response.settings || ajax.settings || Drupal.settings; 625 Drupal.detachBehaviors(wrapper, settings); 626 } 627 628 // Add the new content to the page. 629 wrapper[method](new_content); 630 631 // Immediately hide the new content if we're using any effects. 632 if (effect.showEffect != 'show') { 633 new_content.hide(); 634 } 635 636 // Determine which effect to use and what content will receive the 637 // effect, then show the new content. 638 if ($('.ajax-new-content', new_content).length > 0) { 639 $('.ajax-new-content', new_content).hide(); 640 new_content.show(); 641 $('.ajax-new-content', new_content)[effect.showEffect](effect.showSpeed); 642 } 643 else if (effect.showEffect != 'show') { 644 new_content[effect.showEffect](effect.showSpeed); 645 } 646 647 // Attach all JavaScript behaviors to the new content, if it was successfully 648 // added to the page, this if statement allows #ajax['wrapper'] to be 649 // optional. 650 if (new_content.parents('html').length > 0) { 651 // Apply any settings from the returned JSON if available. 652 var settings = response.settings || ajax.settings || Drupal.settings; 653 Drupal.attachBehaviors(new_content, settings); 654 } 655 }, 656 657 /** 658 * Command to remove a chunk from the page. 659 */ 660 remove: function (ajax, response, status) { 661 var settings = response.settings || ajax.settings || Drupal.settings; 662 Drupal.detachBehaviors($(response.selector), settings); 663 $(response.selector).remove(); 664 }, 665 666 /** 667 * Command to mark a chunk changed. 668 */ 669 changed: function (ajax, response, status) { 670 if (!$(response.selector).hasClass('ajax-changed')) { 671 $(response.selector).addClass('ajax-changed'); 672 if (response.asterisk) { 673 $(response.selector).find(response.asterisk).append(' <span class="ajax-changed">*</span> '); 674 } 675 } 676 }, 677 678 /** 679 * Command to provide an alert. 680 */ 681 alert: function (ajax, response, status) { 682 alert(response.text, response.title); 683 }, 684 685 /** 686 * Command to provide the jQuery css() function. 687 */ 688 css: function (ajax, response, status) { 689 $(response.selector).css(response.argument); 690 }, 691 692 /** 693 * Command to set the settings that will be used for other commands in this response. 694 */ 695 settings: function (ajax, response, status) { 696 if (response.merge) { 697 $.extend(true, Drupal.settings, response.settings); 698 } 699 else { 700 ajax.settings = response.settings; 701 } 702 }, 703 704 /** 705 * Command to attach data using jQuery's data API. 706 */ 707 data: function (ajax, response, status) { 708 $(response.selector).data(response.name, response.value); 709 }, 710 711 /** 712 * Command to apply a jQuery method. 713 */ 714 invoke: function (ajax, response, status) { 715 var $element = $(response.selector); 716 $element[response.method].apply($element, response.arguments); 717 }, 718 719 /** 720 * Command to restripe a table. 721 */ 722 restripe: function (ajax, response, status) { 723 // :even and :odd are reversed because jQuery counts from 0 and 724 // we count from 1, so we're out of sync. 725 // Match immediate children of the parent element to allow nesting. 726 $('> tbody > tr:visible, > tr:visible', $(response.selector)) 727 .removeClass('odd even') 728 .filter(':even').addClass('odd').end() 729 .filter(':odd').addClass('even'); 730 }, 731 732 /** 733 * Command to add css. 734 * 735 * Uses the proprietary addImport method if available as browsers which 736 * support that method ignore @import statements in dynamically added 737 * stylesheets. 738 */ 739 add_css: function (ajax, response, status) { 740 // Add the styles in the normal way. 741 $('head').prepend(response.data); 742 // Add imports in the styles using the addImport method if available. 743 var match, importMatch = /^@import url\("(.*)"\);$/igm; 744 if (document.styleSheets[0].addImport && importMatch.test(response.data)) { 745 importMatch.lastIndex = 0; 746 while (match = importMatch.exec(response.data)) { 747 document.styleSheets[0].addImport(match[1]); 748 } 749 } 750 }, 751 752 /** 753 * Command to update a form's build ID. 754 */ 755 updateBuildId: function(ajax, response, status) { 756 $('input[name="form_build_id"][value="' + response['old'] + '"]').val(response['new']); 757 } 758}; 759 760})(jQuery); 761 762;/*})'"*/ 763;/*})'"*/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.