root / drupal7 / sites / all / themes / bootstrap / js / misc / ajax.js @ 7547bb19
1 |
(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 |
var $element = $(this.element); |
37 |
|
38 |
// Disable the element that received the change to prevent user interface
|
39 |
// interaction while the Ajax request is in progress. ajax.ajaxing prevents
|
40 |
// the element from triggering a new request, but does not prevent the user
|
41 |
// from changing its value.
|
42 |
$element.addClass('progress-disabled').attr('disabled', true); |
43 |
|
44 |
// Insert progressbar or throbber.
|
45 |
if (this.progress.type == 'bar') { |
46 |
var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.id, eval(this.progress.update_callback), this.progress.method, eval(this.progress.error_callback)); |
47 |
if (this.progress.message) { |
48 |
progressBar.setProgress(-1, this.progress.message); |
49 |
} |
50 |
if (this.progress.url) { |
51 |
progressBar.startMonitoring(this.progress.url, this.progress.interval || 500); |
52 |
} |
53 |
this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar'); |
54 |
this.progress.object = progressBar;
|
55 |
$element.closest('.file-widget,.form-item').after(this.progress.element); |
56 |
} |
57 |
else if (this.progress.type == 'throbber') { |
58 |
this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><i class="glyphicon glyphicon-refresh glyphicon-spin"></i></div>'); |
59 |
if (this.progress.message) { |
60 |
$('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); |
61 |
} |
62 |
|
63 |
// If element is an input type, append after.
|
64 |
if ($element.is('input')) { |
65 |
$element.after(this.progress.element); |
66 |
} |
67 |
else if ($element.is('select')) { |
68 |
var $inputGroup = $element.closest('.form-item').find('.input-group-addon, .input-group-btn'); |
69 |
if (!$inputGroup.length) { |
70 |
$element.wrap('<div class="input-group">'); |
71 |
$inputGroup = $('<span class="input-group-addon">'); |
72 |
$element.after($inputGroup); |
73 |
} |
74 |
$inputGroup.append(this.progress.element); |
75 |
} |
76 |
// Otherwise append the throbber inside the element.
|
77 |
else {
|
78 |
$element.append(this.progress.element); |
79 |
} |
80 |
} |
81 |
}; |
82 |
|
83 |
})(jQuery); |