1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
(function ($) {
|
8 |
|
|
Drupal.CTools = Drupal.CTools || {};
|
9 |
|
|
Drupal.CTools.AJAX = Drupal.CTools.AJAX || {};
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
Drupal.CTools.AJAX.warmCache = function () {
|
16 |
|
|
|
17 |
|
|
$this = $(this);
|
18 |
|
|
var old_url = $this.attr('href');
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
if ($this.hasClass('ctools-fetching') || Drupal.CTools.AJAX.commandCache[old_url]) {
|
23 |
|
|
return false;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
var $objects = $('a[href="' + old_url + '"]')
|
30 |
|
|
$objects.addClass('ctools-fetching');
|
31 |
|
|
try {
|
32 |
|
|
url = old_url.replace(/\/nojs(\/|$)/g, '/ajax$1');
|
33 |
|
|
$.ajax({
|
34 |
|
|
type: "POST",
|
35 |
|
|
url: url,
|
36 |
|
|
data: { 'js': 1, 'ctools_ajax': 1},
|
37 |
|
|
global: true,
|
38 |
|
|
success: function (data) {
|
39 |
|
|
Drupal.CTools.AJAX.commandCache[old_url] = data;
|
40 |
|
|
$objects.addClass('ctools-cache-warmed').trigger('ctools-cache-warm', [data]);
|
41 |
|
|
},
|
42 |
|
|
complete: function() {
|
43 |
|
|
$objects.removeClass('ctools-fetching');
|
44 |
|
|
},
|
45 |
|
|
dataType: 'json'
|
46 |
|
|
});
|
47 |
|
|
}
|
48 |
|
|
catch (err) {
|
49 |
|
|
$objects.removeClass('ctools-fetching');
|
50 |
|
|
return false;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
return false;
|
54 |
|
|
};
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
Drupal.CTools.AJAX.clickAJAXCacheLink = function () {
|
60 |
|
|
$this = $(this);
|
61 |
|
|
if ($this.hasClass('ctools-fetching')) {
|
62 |
|
|
$this.bind('ctools-cache-warm', function (event, data) {
|
63 |
|
|
Drupal.CTools.AJAX.respond(data);
|
64 |
|
|
});
|
65 |
|
|
return false;
|
66 |
|
|
}
|
67 |
|
|
else {
|
68 |
|
|
if ($this.hasClass('ctools-cache-warmed') && Drupal.CTools.AJAX.commandCache[$this.attr('href')]) {
|
69 |
|
|
Drupal.CTools.AJAX.respond(Drupal.CTools.AJAX.commandCache[$this.attr('href')]);
|
70 |
|
|
return false;
|
71 |
|
|
}
|
72 |
|
|
else {
|
73 |
|
|
return Drupal.CTools.AJAX.clickAJAXLink.apply(this);
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
};
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
Drupal.CTools.AJAX.findURL = function(item) {
|
87 |
|
|
var url = '';
|
88 |
|
|
var url_class = '.' + $(item).attr('id') + '-url';
|
89 |
|
|
$(url_class).each(
|
90 |
|
|
function() {
|
91 |
|
|
var $this = $(this);
|
92 |
|
|
if (url && $this.val()) {
|
93 |
|
|
url += '/';
|
94 |
|
|
}
|
95 |
|
|
url += $this.val();
|
96 |
|
|
});
|
97 |
|
|
return url;
|
98 |
|
|
};
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
$(function() {
|
102 |
|
|
Drupal.ajax.prototype.commands.attr = function(ajax, data, status) {
|
103 |
|
|
$(data.selector).attr(data.name, data.value);
|
104 |
|
|
};
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
Drupal.ajax.prototype.commands.redirect = function(ajax, data, status) {
|
108 |
|
|
if (data.delay > 0) {
|
109 |
|
|
setTimeout(function () {
|
110 |
|
|
location.href = data.url;
|
111 |
|
|
}, data.delay);
|
112 |
|
|
}
|
113 |
|
|
else {
|
114 |
|
|
location.href = data.url;
|
115 |
|
|
}
|
116 |
|
|
};
|
117 |
|
|
|
118 |
|
|
Drupal.ajax.prototype.commands.reload = function(ajax, data, status) {
|
119 |
|
|
location.reload();
|
120 |
|
|
};
|
121 |
|
|
|
122 |
|
|
Drupal.ajax.prototype.commands.submit = function(ajax, data, status) {
|
123 |
|
|
$(data.selector).submit();
|
124 |
|
|
}
|
125 |
|
|
});
|
126 |
|
|
})(jQuery); |