root / drupal7 / sites / all / themes / bootstrap / js / misc / ajax.js @ 87dbc3bf
1 | 87dbc3bf | Benjamin Luce | (function ($) { |
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * Override Drupal's AJAX prototype beforeSend function so it can append the
|
||
5 | * throbber inside the pager links.
|
||
6 | */
|
||
7 | Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) { |
||
8 | // For forms without file inputs, the jQuery Form plugin serializes the form
|
||
9 | // values, and then calls jQuery's $.ajax() function, which invokes this
|
||
10 | // handler. In this circumstance, options.extraData is never used. For forms
|
||
11 | // with file inputs, the jQuery Form plugin uses the browser's normal form
|
||
12 | // submission mechanism, but captures the response in a hidden IFRAME. In this
|
||
13 | // circumstance, it calls this handler first, and then appends hidden fields
|
||
14 | // to the form to submit the values in options.extraData. There is no simple
|
||
15 | // way to know which submission mechanism will be used, so we add to extraData
|
||
16 | // regardless, and allow it to be ignored in the former case.
|
||
17 | if (this.form) { |
||
18 | options.extraData = options.extraData || {}; |
||
19 | |||
20 | // Let the server know when the IFRAME submission mechanism is used. The
|
||
21 | // server can use this information to wrap the JSON response in a TEXTAREA,
|
||
22 | // as per http://jquery.malsup.com/form/#file-upload.
|
||
23 | options.extraData.ajax_iframe_upload = '1';
|
||
24 | |||
25 | // The triggering element is about to be disabled (see below), but if it
|
||
26 | // contains a value (e.g., a checkbox, textfield, select, etc.), ensure that
|
||
27 | // value is included in the submission. As per above, submissions that use
|
||
28 | // $.ajax() are already serialized prior to the element being disabled, so
|
||
29 | // this is only needed for IFRAME submissions.
|
||
30 | var v = $.fieldValue(this.element); |
||
31 | if (v !== null) { |
||
32 | options.extraData[this.element.name] = v;
|
||
33 | } |
||
34 | } |
||
35 | |||
36 | // Disable the element that received the change to prevent user interface
|
||
37 | // interaction while the Ajax request is in progress. ajax.ajaxing prevents
|
||
38 | // the element from triggering a new request, but does not prevent the user
|
||
39 | // from changing its value.
|
||
40 | $(this.element).addClass('progress-disabled').attr('disabled', true); |
||
41 | |||
42 | // Insert progressbar or throbber.
|
||
43 | if (this.progress.type == 'bar') { |
||
44 | var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.id, eval(this.progress.update_callback), this.progress.method, eval(this.progress.error_callback)); |
||
45 | if (this.progress.message) { |
||
46 | progressBar.setProgress(-1, this.progress.message); |
||
47 | } |
||
48 | if (this.progress.url) { |
||
49 | progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500); |
||
50 | } |
||
51 | this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar'); |
||
52 | this.progress.object = progressBar;
|
||
53 | $(this.element).after(this.progress.element); |
||
54 | } |
||
55 | else if (this.progress.type == 'throbber') { |
||
56 | this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><i class="glyphicon glyphicon-refresh glyphicon-spin"></i></div>'); |
||
57 | // If element is an input type, append after.
|
||
58 | if ($(this.element).is('input')) { |
||
59 | if (this.progress.message) { |
||
60 | $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); |
||
61 | } |
||
62 | $(this.element).after(this.progress.element); |
||
63 | } |
||
64 | // Otherwise inject it inside the element.
|
||
65 | else {
|
||
66 | if (this.progress.message) { |
||
67 | $('.throbber', this.progress.element).append('<div class="message">' + this.progress.message + '</div>'); |
||
68 | } |
||
69 | $(this.element).append(this.progress.element); |
||
70 | } |
||
71 | } |
||
72 | }; |
||
73 | |||
74 | })(jQuery); |