author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 09 May 2012 17:15:44 +0200 | |
changeset 8394 | b8b23af60019 |
parent 8349 | fdb796435d7b |
child 8412 | 09432a572a44 |
permissions | -rw-r--r-- |
7374
3c9850d929e5
[web request] don't define pageid js variable when one is found in form parameters (eg, page ajax call)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7328
diff
changeset
|
1 |
/* copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
2 |
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
3 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
4 |
* This file is part of CubicWeb. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
5 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
6 |
* CubicWeb is free software: you can redistribute it and/or modify it under the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
7 |
* terms of the GNU Lesser General Public License as published by the Free |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
8 |
* Software Foundation, either version 2.1 of the License, or (at your option) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
9 |
* any later version. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
10 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
11 |
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
14 |
* details. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
15 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
16 |
* You should have received a copy of the GNU Lesser General Public License along |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
17 |
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
*/ |
19 |
||
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
20 |
/** |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
21 |
* .. function:: Deferred |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
22 |
* |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
23 |
* dummy ultra minimalist implementation of deferred for jQuery |
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
24 |
*/ |
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
25 |
|
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
26 |
cw.ajax = new Namespace('cw.ajax'); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
27 |
|
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
28 |
function Deferred() { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
29 |
this.__init__(this); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
30 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
31 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
32 |
jQuery.extend(Deferred.prototype, { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
33 |
__init__: function() { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
34 |
this._onSuccess = []; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
35 |
this._onFailure = []; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
36 |
this._req = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
37 |
this._result = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
38 |
this._error = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
39 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
40 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
41 |
addCallback: function(callback) { |
6556
64b39aa0b047
[js/ajax] use proper operator
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6552
diff
changeset
|
42 |
if ((this._req.readyState == 4) && this._result) { |
6552
256725d4e3ec
[js/ajax] fix deferred race condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6215
diff
changeset
|
43 |
var args = [this._result, this._req]; |
256725d4e3ec
[js/ajax] fix deferred race condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6215
diff
changeset
|
44 |
jQuery.merge(args, cw.utils.sliceList(arguments, 1)); |
256725d4e3ec
[js/ajax] fix deferred race condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6215
diff
changeset
|
45 |
callback.apply(null, args); |
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
46 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
47 |
else { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
48 |
this._onSuccess.push([callback, cw.utils.sliceList(arguments, 1)]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
49 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
50 |
return this; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
51 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
52 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
53 |
addErrback: function(callback) { |
6560
48ba5069e051
[js/ajax] fix deferred race condition (errback case)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6556
diff
changeset
|
54 |
if (this._req.readyState == 4 && this._error) { |
48ba5069e051
[js/ajax] fix deferred race condition (errback case)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6556
diff
changeset
|
55 |
callback.apply(null, [this._error, this._req]); |
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
56 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
57 |
else { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
58 |
this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
59 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
60 |
return this; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
61 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
62 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
63 |
success: function(result) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
64 |
this._result = result; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
65 |
try { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
66 |
for (var i = 0; i < this._onSuccess.length; i++) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
67 |
var callback = this._onSuccess[i][0]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
68 |
var args = [result, this._req]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
69 |
jQuery.merge(args, this._onSuccess[i][1]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
70 |
callback.apply(null, args); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
71 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
72 |
} catch(error) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
73 |
this.error(this.xhr, null, error); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
74 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
75 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
76 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
77 |
error: function(xhr, status, error) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
78 |
this._error = error; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
79 |
for (var i = 0; i < this._onFailure.length; i++) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
80 |
var callback = this._onFailure[i][0]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
81 |
var args = [error, this._req]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
82 |
jQuery.merge(args, this._onFailure[i][1]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
83 |
callback.apply(null, args); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
84 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
85 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
86 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
87 |
}); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
88 |
|
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
89 |
var AJAX_PREFIX_URL = 'ajax'; |
0 | 90 |
var JSON_BASE_URL = baseuri() + 'json?'; |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
91 |
var AJAX_BASE_URL = baseuri() + AJAX_PREFIX_URL + '?'; |
0 | 92 |
|
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
93 |
|
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
94 |
jQuery.extend(cw.ajax, { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
95 |
/* variant of jquery evalScript with cache: true in ajax call */ |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
96 |
_evalscript: function ( i, elem ) { |
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
97 |
var src = elem.getAttribute('src'); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
98 |
if (src) { |
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
99 |
jQuery.ajax({ |
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
100 |
url: src, |
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
101 |
async: false, |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
102 |
cache: true, |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
103 |
dataType: "script" |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
104 |
}); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
105 |
} else { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
106 |
jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
107 |
} |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
108 |
if ( elem.parentNode ) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
109 |
elem.parentNode.removeChild( elem ); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
110 |
} |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
111 |
}, |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
112 |
|
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
113 |
evalscripts: function ( scripts ) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
114 |
if ( scripts.length ) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
115 |
jQuery.each(scripts, cw.ajax._evalscript); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
116 |
} |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
117 |
}, |
7284
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7199
diff
changeset
|
118 |
|
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
119 |
/** |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
120 |
* returns true if `url` is a mod_concat-like url |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
121 |
* (e.g. http://..../data??resource1.js,resource2.js) |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
122 |
*/ |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
123 |
_modconcatLikeUrl: function(url) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
124 |
var base = baseuri(); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
125 |
if (!base.endswith('/')) { base += '/'; } |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
126 |
var modconcat_rgx = new RegExp('(' + base + 'data/([a-z0-9]+/)?)\\?\\?(.+)'); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
127 |
return modconcat_rgx.exec(url); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
128 |
}, |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
129 |
|
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
130 |
/** |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
131 |
* decomposes a mod_concat-like url into its corresponding list of |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
132 |
* resources' urls |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
133 |
* >>> _listResources('http://foo.com/data/??a.js,b.js,c.js') |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
134 |
* ['http://foo.com/data/a.js', 'http://foo.com/data/b.js', 'http://foo.com/data/c.js'] |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
135 |
*/ |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
136 |
_listResources: function(src) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
137 |
var resources = []; |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
138 |
var groups = cw.ajax._modconcatLikeUrl(src); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
139 |
if (groups == null) { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
140 |
resources.push(src); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
141 |
} else { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
142 |
var dataurl = groups[1]; |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
143 |
$.each(cw.utils.lastOf(groups).split(','), |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
144 |
function() { |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
145 |
resources.push(dataurl + this); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
146 |
} |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
147 |
); |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
148 |
} |
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
149 |
return resources; |
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
150 |
}, |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
151 |
|
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
152 |
_buildMissingResourcesUrl: function(url, loadedResources) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
153 |
var resources = cw.ajax._listResources(url); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
154 |
var missingResources = $.grep(resources, function(resource) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
155 |
return $.inArray(resource, loadedResources) == -1; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
156 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
157 |
cw.utils.extend(loadedResources, missingResources); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
158 |
var missingResourceUrl = null; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
159 |
if (missingResources.length == 1) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
160 |
// only one resource missing: build a node with a single resource url |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
161 |
// (maybe the browser has it in cache already) |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
162 |
missingResourceUrl = missingResources[0]; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
163 |
} else if (missingResources.length > 1) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
164 |
// several resources missing: build a node with a concatenated |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
165 |
// resources url |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
166 |
var dataurl = cw.ajax._modconcatLikeUrl(url)[1]; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
167 |
var missing_path = $.map(missingResources, function(resource) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
168 |
return resource.substring(dataurl.length); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
169 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
170 |
missingResourceUrl = dataurl + '??' + missing_path.join(','); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
171 |
} |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
172 |
return missingResourceUrl; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
173 |
}, |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
174 |
|
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
175 |
_loadAjaxStylesheets: function($responseHead, $head) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
176 |
$responseHead.find('link[href]').each(function(i) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
177 |
var $srcnode = $(this); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
178 |
var url = $srcnode.attr('href'); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
179 |
if (url) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
180 |
var missingStylesheetsUrl = cw.ajax._buildMissingResourcesUrl(url, cw.loaded_links); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
181 |
// compute concat-like url for missing resources and append <link> |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
182 |
// element to $head |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
183 |
if (missingStylesheetsUrl) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
184 |
$srcnode.attr('href', missingStylesheetsUrl); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
185 |
$srcnode.appendTo($head); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
186 |
} |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
187 |
} |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
188 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
189 |
$responseHead.find('link[href]').remove(); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
190 |
}, |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
191 |
|
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
192 |
_loadAjaxScripts: function($responseHead, $head) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
193 |
$responseHead.find('pre.script').each(function(i) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
194 |
var $srcnode = $(this); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
195 |
var url = $srcnode.attr('src'); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
196 |
if (url) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
197 |
var missingScriptsUrl = cw.ajax._buildMissingResourcesUrl(url, cw.loaded_scripts); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
198 |
if (missingScriptsUrl) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
199 |
$srcnode.attr('src', missingScriptsUrl); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
200 |
/* special handling of <script> tags: script nodes appended by jquery |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
201 |
* use uncached ajax calls and do not appear in the DOM |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
202 |
* (See comments in response to Syt on // http://api.jquery.com/append/), |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
203 |
* which cause undesired duplicated load in our case. We now handle |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
204 |
* a list of already loaded resources, since bare DOM api gives bugs with the |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
205 |
* server-response event, and we lose control on when the |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
206 |
* script is loaded (jQuery loads it immediately). */ |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
207 |
cw.ajax.evalscripts($srcnode); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
208 |
} |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
209 |
} else { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
210 |
// <script> contains inlined javascript code, node content |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
211 |
// must be evaluated |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
212 |
jQuery.globalEval($srcnode.text()); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
213 |
} |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
214 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
215 |
$responseHead.find('pre.script').remove(); |
7284
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7199
diff
changeset
|
216 |
} |
7427
06444c1233e0
[ajax js/css] modconcat fix: load code exactly once (auc, fcayre)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7377
diff
changeset
|
217 |
}); |
7284
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7199
diff
changeset
|
218 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
219 |
//============= utility function handling remote calls responses. ==============// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
220 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
221 |
* .. function:: function loadAjaxHtmlHead(response) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
222 |
* |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
223 |
* inspect dom response (as returned by getDomFromResponse), search for |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
224 |
* a <div class="ajaxHtmlHead"> node and put its content into the real |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
225 |
* document's head. |
642
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
226 |
* This enables dynamic css and js loading and is used by replacePageChunk |
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
227 |
*/ |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
228 |
function loadAjaxHtmlHead(response) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
229 |
var $head = jQuery('head'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
230 |
var $responseHead = jQuery(response).find('div.ajaxHtmlHead'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
231 |
// no ajaxHtmlHead found, no processing required |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
232 |
if (!$responseHead.length) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
233 |
return response; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
234 |
} |
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
235 |
cw.ajax._loadAjaxStylesheets($responseHead, $head); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
236 |
cw.ajax._loadAjaxScripts($responseHead, $head); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
237 |
// add any remaining children (e.g. meta) |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
238 |
$responseHead.children().appendTo($head); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
239 |
// remove original container, which is now empty |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
240 |
$responseHead.remove(); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
241 |
// if there was only one actual node in the reponse besides |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
242 |
// the ajaxHtmlHead, then remove the wrapper created by |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
243 |
// getDomFromResponse() and return this single element |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
244 |
// For instance : |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
245 |
// 1/ CW returned the following content : |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
246 |
// <div>the-actual-content</div><div class="ajaxHtmlHead">...</div> |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
247 |
// 2/ getDomFromReponse() wrapped this into a single DIV to hold everything |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
248 |
// in one, unique, dom element |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
249 |
// 3/ now that we've removed the ajaxHtmlHead div, the only |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
250 |
// node left in the wrapper if the 'real' node built by the view, |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
251 |
// we can safely return this node. Otherwise, the view itself |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
252 |
// returned several 'root' nodes and we need to keep the wrapper |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
253 |
// created by getDomFromResponse() |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
254 |
if (response.childNodes.length == 1 && response.getAttribute('cubicweb:type') == 'cwResponseWrapper') { |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
255 |
return response.firstChild; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
256 |
} |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
257 |
return response; |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
258 |
} |
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
259 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
260 |
function _postAjaxLoad(node) { |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
261 |
// find textareas and wrap them if there are some |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
262 |
if (typeof(FCKeditor) != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
263 |
buildWysiwygEditors(); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
264 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
265 |
if (typeof initFacetBoxEvents != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
266 |
initFacetBoxEvents(node); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
267 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
268 |
if (typeof buildWidgets != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
269 |
buildWidgets(node); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
270 |
} |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2257
diff
changeset
|
271 |
if (typeof roundedCorners != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
272 |
roundedCorners(node); |
955 | 273 |
} |
3863
fe22502d4ab1
[forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3784
diff
changeset
|
274 |
if (typeof setFormsTarget != 'undefined') { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
275 |
setFormsTarget(node); |
3863
fe22502d4ab1
[forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3784
diff
changeset
|
276 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
277 |
_loadDynamicFragments(node); |
4830
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4208
diff
changeset
|
278 |
// XXX [3.7] jQuery.one is now used instead jQuery.bind, |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4208
diff
changeset
|
279 |
// jquery.treeview.js can be unpatched accordingly. |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6215
diff
changeset
|
280 |
jQuery(cw).trigger('server-response', [true, node]); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
281 |
jQuery(node).trigger('server-response', [true, node]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
282 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
283 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
284 |
function remoteCallFailed(err, req) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
285 |
cw.log(err); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
286 |
if (req.status == 500) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
287 |
updateMessage(err); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
288 |
} else { |
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5998
diff
changeset
|
289 |
updateMessage(_("an error occurred while processing your request")); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
290 |
} |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
291 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
292 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
293 |
//============= base AJAX functions to make remote calls =====================// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
294 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
295 |
* .. function:: ajaxFuncArgs(fname, form, *args) |
3011 | 296 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
297 |
* extend `form` parameters to call the js_`fname` function of the json |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
298 |
* controller with `args` arguments. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
299 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
300 |
function ajaxFuncArgs(fname, form /* ... */) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
301 |
form = form || {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
302 |
$.extend(form, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
303 |
'fname': fname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
304 |
'pageid': pageid, |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
305 |
'arg': $.map(cw.utils.sliceList(arguments, 2), jQuery.toJSON) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
306 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
307 |
return form; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
308 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
309 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
310 |
/** |
7571
6386f802fbc6
[cw.ajax] fix loadxhtml documentation and warn when called on an empty elements list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7422
diff
changeset
|
311 |
* .. function:: loadxhtml(url, form, reqtype='get', mode='replace', cursor=false) |
3011 | 312 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
313 |
* build url given by absolute or relative `url` and `form` parameters |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
314 |
* (dictionary), fetch it using `reqtype` method, then evaluate the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
315 |
* returned XHTML and insert it according to `mode` in the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
316 |
* document. Possible modes are : |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
317 |
* |
3011 | 318 |
* - 'replace' to replace the node's content with the generated HTML |
319 |
* - 'swap' to replace the node itself with the generated HTML |
|
320 |
* - 'append' to append the generated HTML to the node's content |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
321 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
322 |
* If `cursor`, turn mouse cursor into 'progress' cursor until the remote call |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
323 |
* is back. |
3011 | 324 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
325 |
jQuery.fn.loadxhtml = function(url, form, reqtype, mode, cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
326 |
if (this.size() > 1) { |
7571
6386f802fbc6
[cw.ajax] fix loadxhtml documentation and warn when called on an empty elements list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7422
diff
changeset
|
327 |
cw.log('loadxhtml called with more than one element'); |
6386f802fbc6
[cw.ajax] fix loadxhtml documentation and warn when called on an empty elements list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7422
diff
changeset
|
328 |
} else if (this.size() < 1) { |
6386f802fbc6
[cw.ajax] fix loadxhtml documentation and warn when called on an empty elements list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7422
diff
changeset
|
329 |
cw.log('loadxhtml called without an element'); |
0 | 330 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
331 |
var callback = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
332 |
if (form && form.callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
333 |
cw.log('[3.9] callback given through form.callback is deprecated, add ' + 'callback on the defered'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
334 |
callback = form.callback; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
335 |
delete form.callback; |
0 | 336 |
} |
642
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
337 |
var node = this.get(0); // only consider the first element |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
338 |
if (cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
339 |
setProgressCursor(); |
0 | 340 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
341 |
var d = loadRemote(url, form, reqtype); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
342 |
d.addCallback(function(response) { |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
343 |
var domnode = getDomFromResponse(response); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
344 |
domnode = loadAjaxHtmlHead(domnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
345 |
mode = mode || 'replace'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
346 |
// make sure the component is visible |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
347 |
$(node).removeClass("hidden"); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
348 |
if (mode == 'swap') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
349 |
var origId = node.id; |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5909
diff
changeset
|
350 |
node = cw.swapDOM(node, domnode); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
351 |
if (!node.id) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
352 |
node.id = origId; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
353 |
} |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
354 |
} else if (mode == 'replace') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
355 |
jQuery(node).empty().append(domnode); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
356 |
} else if (mode == 'append') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
357 |
jQuery(node).append(domnode); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
358 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
359 |
_postAjaxLoad(node); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
360 |
while (jQuery.isFunction(callback)) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
361 |
callback = callback.apply(this, [domnode]); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
362 |
} |
0 | 363 |
}); |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5909
diff
changeset
|
364 |
d.addErrback(remoteCallFailed); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
365 |
if (cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
366 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
367 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
368 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
369 |
return d; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
370 |
} |
0 | 371 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
372 |
/** |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5909
diff
changeset
|
373 |
* .. function:: loadRemote(url, form, reqtype='GET', sync=false) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
374 |
* |
8332
e7c008ebef74
[js] fix error in loadRemote docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8191
diff
changeset
|
375 |
* Asynchronously (unless `sync` argument is set to true) load an url or path |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
376 |
* and return a deferred whose callbacks args are decoded according to the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
377 |
* Content-Type response header. `form` should be additional form params |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
378 |
* dictionary, `reqtype` the HTTP request type (get 'GET' or 'POST'). |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
379 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
380 |
function loadRemote(url, form, reqtype, sync) { |
7122
3b0f1c2af20f
[javascript] fix loadRemote test for JSON_BASE_URL / baseuri matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6952
diff
changeset
|
381 |
if (!url.toLowerCase().startswith(baseuri().toLowerCase())) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
382 |
url = baseuri() + url; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
383 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
384 |
if (!sync) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
385 |
var deferred = new Deferred(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
386 |
jQuery.ajax({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
387 |
url: url, |
6618
1268da8a2dbb
[js/ajax] switch to POST by default, fixes an IE7 caching bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6560
diff
changeset
|
388 |
type: (reqtype || 'POST').toUpperCase(), |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
389 |
data: form, |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6215
diff
changeset
|
390 |
traditional: true, |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
391 |
async: true, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
392 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
393 |
beforeSend: function(xhr) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
394 |
deferred._req = xhr; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
395 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
396 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
397 |
success: function(data, status) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
398 |
deferred.success(data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
399 |
}, |
0 | 400 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
401 |
error: function(xhr, status, error) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
402 |
try { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
403 |
if (xhr.status == 500) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
404 |
var reason_dict = cw.evalJSON(xhr.responseText); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
405 |
deferred.error(xhr, status, reason_dict['reason']); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
406 |
return; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
407 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
408 |
} catch(exc) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
409 |
cw.log('error with server side error report:' + exc); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
410 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
411 |
deferred.error(xhr, status, null); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
412 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
413 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
414 |
return deferred; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
415 |
} else { |
6555
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
416 |
var result; |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
417 |
// jQuery.ajax returns the XHR object, even for synchronous requests, |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
418 |
// but in that case, the success callback will be called before |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
419 |
// jQuery.ajax returns. The first argument of the callback will be |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
420 |
// the server result, interpreted by jQuery according to the reponse's |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
421 |
// content-type (i.e. json or xml) |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
422 |
jQuery.ajax({ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
423 |
url: url, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
424 |
type: (reqtype || 'GET').toUpperCase(), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
425 |
data: form, |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6215
diff
changeset
|
426 |
traditional: true, |
6555
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
427 |
async: false, |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
428 |
success: function(res) { |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
429 |
result = res; |
f8b36b1e98bf
[javascript] fix loadRemote implementation for synchronous requests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
430 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
431 |
}); |
6121
57dddb6b5913
add missing semi colon in js
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6109
diff
changeset
|
432 |
return result; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
433 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
434 |
} |
0 | 435 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
436 |
//============= higher level AJAX functions using remote calls ===============// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
437 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
438 |
* .. function:: _(message) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
439 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
440 |
* emulation of gettext's _ shortcut |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
441 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
442 |
function _(message) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
443 |
return loadRemote(AJAX_BASE_URL, ajaxFuncArgs('i18n', null, [message]), 'GET', true)[0]; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
444 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
445 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
446 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
447 |
* .. function:: _loadDynamicFragments(node) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
448 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
449 |
* finds each dynamic fragment in the page and executes the |
0 | 450 |
* the associated RQL to build them (Async call) |
451 |
*/ |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
452 |
function _loadDynamicFragments(node) { |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
453 |
if (node) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
454 |
var fragments = jQuery(node).find('div.dynamicFragment'); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
455 |
} else { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
456 |
var fragments = jQuery('div.dynamicFragment'); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
457 |
} |
0 | 458 |
if (fragments.length == 0) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
459 |
return; |
0 | 460 |
} |
461 |
if (typeof LOADING_MSG == 'undefined') { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
462 |
LOADING_MSG = 'loading'; // this is only a safety belt, it should not happen |
0 | 463 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
464 |
for (var i = 0; i < fragments.length; i++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
465 |
var fragment = fragments[i]; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
466 |
fragment.innerHTML = '<h3>' + LOADING_MSG + ' ... <img src="data/loading.gif" /></h3>'; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
467 |
var $fragment = jQuery(fragment); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
468 |
// if cubicweb:loadurl is set, just pick the url et send it to loadxhtml |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
469 |
var url = $fragment.attr('cubicweb:loadurl'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
470 |
if (url) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
471 |
$fragment.loadxhtml(url); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
472 |
continue; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
473 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
474 |
// else: rebuild full url by fetching cubicweb:rql, cubicweb:vid, etc. |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
475 |
var rql = $fragment.attr('cubicweb:rql'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
476 |
var items = $fragment.attr('cubicweb:vid').split('&'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
477 |
var vid = items[0]; |
0 | 478 |
var extraparams = {}; |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
479 |
// case where vid='myvid¶m1=val1¶m2=val2': this is a deprecated abuse-case |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
480 |
if (items.length > 1) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
481 |
cw.log("[3.5] you're using extraargs in cubicweb:vid " + |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
482 |
"attribute, this is deprecated, consider using " + |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
483 |
"loadurl instead"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
484 |
for (var j = 1; j < items.length; j++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
485 |
var keyvalue = items[j].split('='); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
486 |
extraparams[keyvalue[0]] = keyvalue[1]; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
487 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
488 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
489 |
var actrql = $fragment.attr('cubicweb:actualrql'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
490 |
if (actrql) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
491 |
extraparams['actualrql'] = actrql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
492 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
493 |
var fbvid = $fragment.attr('cubicweb:fallbackvid'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
494 |
if (fbvid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
495 |
extraparams['fallbackvid'] = fbvid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
496 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
497 |
extraparams['rql'] = rql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
498 |
extraparams['vid'] = vid; |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
499 |
$fragment.loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('view', extraparams)); |
0 | 500 |
} |
501 |
} |
|
502 |
function unloadPageData() { |
|
503 |
// NOTE: do not make async calls on unload if you want to avoid |
|
504 |
// strange bugs |
|
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
505 |
loadRemote(AJAX_BASE_URL, ajaxFuncArgs('unload_page_data'), 'GET', true); |
0 | 506 |
} |
507 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
508 |
function removeBookmark(beid) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
509 |
var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('delete_bookmark', null, beid)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
510 |
d.addCallback(function(boxcontent) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
511 |
$('#bookmarks_box').loadxhtml(AJAX_BASE_URL, |
6947
3d72028a6cd4
[js] using the actual registry fixes spurious warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6924
diff
changeset
|
512 |
ajaxFuncArgs('render', null, 'ctxcomponents', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
513 |
'bookmarks_box')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
514 |
document.location.hash = '#header'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
515 |
updateMessage(_("bookmark has been removed")); |
0 | 516 |
}); |
517 |
} |
|
518 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
519 |
function userCallback(cbname) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
520 |
setProgressCursor(); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
521 |
var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('user_callback', null, cbname)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
522 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
523 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
524 |
d.addErrback(remoteCallFailed); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
525 |
return d; |
0 | 526 |
} |
527 |
||
528 |
function userCallbackThenUpdateUI(cbname, compid, rql, msg, registry, nodeid) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
529 |
var d = userCallback(cbname); |
0 | 530 |
d.addCallback(function() { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
531 |
$('#' + nodeid).loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('render', {'rql': rql}, |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6121
diff
changeset
|
532 |
registry, compid)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
533 |
if (msg) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
534 |
updateMessage(msg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
535 |
} |
0 | 536 |
}); |
537 |
} |
|
538 |
||
539 |
function userCallbackThenReloadPage(cbname, msg) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
540 |
var d = userCallback(cbname); |
0 | 541 |
d.addCallback(function() { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
542 |
window.location.reload(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
543 |
if (msg) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
544 |
updateMessage(msg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
545 |
} |
0 | 546 |
}); |
547 |
} |
|
548 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
549 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
550 |
* .. function:: unregisterUserCallback(cbname) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
551 |
* |
0 | 552 |
* unregisters the python function registered on the server's side |
553 |
* while the page was generated. |
|
554 |
*/ |
|
555 |
function unregisterUserCallback(cbname) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
556 |
setProgressCursor(); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
557 |
var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('unregister_user_callback', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
558 |
null, cbname)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
559 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
560 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
561 |
d.addErrback(remoteCallFailed); |
0 | 562 |
} |
563 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
564 |
//============= XXX move those functions? ====================================// |
0 | 565 |
function openHash() { |
566 |
if (document.location.hash) { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
567 |
var nid = document.location.hash.replace('#', ''); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
568 |
var node = jQuery('#' + nid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
569 |
if (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
570 |
$(node).removeClass("hidden"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
571 |
} |
0 | 572 |
}; |
573 |
} |
|
574 |
jQuery(document).ready(openHash); |
|
575 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
576 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
577 |
* .. function:: buildWysiwygEditors(parent) |
0 | 578 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
579 |
*XXX: this function should go in edition.js but as for now, htmlReplace |
0 | 580 |
* references it. |
581 |
* |
|
582 |
* replace all textareas with fckeditors. |
|
583 |
*/ |
|
584 |
function buildWysiwygEditors(parent) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
585 |
jQuery('textarea').each(function() { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
586 |
if (this.getAttribute('cubicweb:type') == 'wysiwyg') { |
3060
ea967a4f6ccb
avoid installing editor n times for n ajax loads
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3011
diff
changeset
|
587 |
// mark editor as instanciated, we may be called a number of times |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
588 |
// (see _postAjaxLoad) |
3060
ea967a4f6ccb
avoid installing editor n times for n ajax loads
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3011
diff
changeset
|
589 |
this.setAttribute('cubicweb:type', 'fckeditor'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
590 |
if (typeof FCKeditor != "undefined") { |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
591 |
var fck = new FCKeditor(this.id); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
592 |
fck.Config['CustomConfigurationsPath'] = fckconfigpath; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
593 |
fck.Config['DefaultLanguage'] = fcklang; |
7199
589801acf08e
[fckeditor] fix fckeditor relative url: use baseuri()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7122
diff
changeset
|
594 |
fck.BasePath = baseuri() + "fckeditor/"; |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
595 |
fck.ReplaceTextarea(); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
596 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
597 |
cw.log('fckeditor could not be found.'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
598 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
599 |
} |
0 | 600 |
}); |
601 |
} |
|
602 |
jQuery(document).ready(buildWysiwygEditors); |
|
603 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
604 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
605 |
* .. function:: stripEmptyTextNodes(nodelist) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
606 |
* |
1419 | 607 |
* takes a list of DOM nodes and removes all empty text nodes |
608 |
*/ |
|
609 |
function stripEmptyTextNodes(nodelist) { |
|
4208
b2826afdaf8c
fix stripEmptyTextNodes for IE (part of #615337)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4175
diff
changeset
|
610 |
/* this DROPS empty text nodes */ |
1419 | 611 |
var stripped = []; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
612 |
for (var i = 0; i < nodelist.length; i++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
613 |
var node = nodelist[i]; |
4208
b2826afdaf8c
fix stripEmptyTextNodes for IE (part of #615337)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4175
diff
changeset
|
614 |
if (isTextNode(node)) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
615 |
/* all browsers but FF -> innerText, FF -> textContent */ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
616 |
var text = node.innerText || node.textContent; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
617 |
if (text && ! text.strip()) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
618 |
continue; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
619 |
} |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
620 |
} else { |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
621 |
stripped.push(node); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
622 |
} |
1419 | 623 |
} |
624 |
return stripped; |
|
625 |
} |
|
626 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
627 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
628 |
* .. function:: getDomFromResponse(response) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
629 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
630 |
* convenience function that returns a DOM node based on req's result. |
3104 | 631 |
* XXX clarify the need to clone |
632 |
* */ |
|
0 | 633 |
function getDomFromResponse(response) { |
634 |
if (typeof(response) == 'string') { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
635 |
var doc = html2dom(response); |
3073
09c6fe0db381
do postprocessing as in the xhtml case fix #345293
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3060
diff
changeset
|
636 |
} else { |
09c6fe0db381
do postprocessing as in the xhtml case fix #345293
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3060
diff
changeset
|
637 |
var doc = response.documentElement; |
0 | 638 |
} |
639 |
var children = doc.childNodes; |
|
640 |
if (!children.length) { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
641 |
// no child (error cases) => return the whole document |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
642 |
return jQuery(doc).clone().context; |
0 | 643 |
} |
1419 | 644 |
children = stripEmptyTextNodes(children); |
0 | 645 |
if (children.length == 1) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
646 |
// only one child => return it |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
647 |
return jQuery(children[0]).clone().context; |
0 | 648 |
} |
649 |
// several children => wrap them in a single node and return the wrap |
|
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
650 |
return DIV({'cubicweb:type': "cwResponseWrapper"}, |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6121
diff
changeset
|
651 |
$.map(children, function(node) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6121
diff
changeset
|
652 |
return jQuery(node).clone().context;}) |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6121
diff
changeset
|
653 |
); |
0 | 654 |
} |
655 |
||
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
656 |
/* High-level functions *******************************************************/ |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
657 |
|
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
658 |
/** |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
659 |
* .. function:: reloadCtxComponentsSection(context, actualEid, creationEid=None) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
660 |
* |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
661 |
* reload all components in the section for a given `context`. |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
662 |
* |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
663 |
* This is necessary for cases where the parent entity (on which the section |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
664 |
* apply) has been created during post, hence the section has to be reloaded to |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
665 |
* consider its new eid, hence the two additional arguments `actualEid` and |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
666 |
* `creationEid`: `actualEid` is the eid of newly created top level entity and |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
667 |
* `creationEid` the fake eid that was given as form creation marker (e.g. A). |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
668 |
* |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
669 |
* You can still call this function with only the actual eid if you're not in |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
670 |
* such creation case. |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
671 |
*/ |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
672 |
function reloadCtxComponentsSection(context, actualEid, creationEid) { |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
673 |
// in this case, actualEid is the eid of newly created top level entity and |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
674 |
// creationEid the fake eid given as form creation marker (e.g. A) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
675 |
if (!creationEid) { creationEid = actualEid ; } |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
676 |
var $compsholder = $('#' + context + creationEid); |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
677 |
// reload the whole components section |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
678 |
$compsholder.children().each(function (index) { |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
679 |
// XXX this.id[:-len(eid)] |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
680 |
var compid = this.id.replace("_", ".").rstrip(creationEid); |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
681 |
var params = ajaxFuncArgs('render', null, 'ctxcomponents', |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
682 |
compid, actualEid); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
683 |
$(this).loadxhtml(AJAX_BASE_URL, params, null, 'swap', true); |
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
684 |
}); |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
685 |
$compsholder.attr('id', context + actualEid); |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
686 |
} |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
687 |
|
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
688 |
|
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
689 |
/** |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
690 |
* .. function:: reload(domid, registry, formparams, *render_args) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
691 |
* |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
692 |
* `js_render` based reloading of views and components. |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
693 |
*/ |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
694 |
function reload(domid, compid, registry, formparams /* ... */) { |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
695 |
var ajaxArgs = ['render', formparams, registry, compid]; |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
696 |
ajaxArgs = ajaxArgs.concat(cw.utils.sliceList(arguments, 4)); |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
697 |
var params = ajaxFuncArgs.apply(null, ajaxArgs); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
698 |
return $('#'+domid).loadxhtml(AJAX_BASE_URL, params, null, 'swap'); |
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
699 |
} |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6862
diff
changeset
|
700 |
|
6952
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
701 |
/* ajax tabs ******************************************************************/ |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
702 |
|
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
703 |
function setTab(tabname, cookiename) { |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
704 |
// set appropriate cookie |
7820
2c73fc529a20
[tabs] do not use an ajax call to set cookie value, use jquery.cookie helper instead (closes #1944522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
705 |
jQuery.cookie(cookiename, tabname, {path: '/'}); |
6952
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
706 |
// trigger show + tabname event |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
707 |
triggerLoad(tabname); |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
708 |
} |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
709 |
|
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
710 |
function loadNow(eltsel, holesel, reloadable) { |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
711 |
var lazydiv = jQuery(eltsel); |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
712 |
var hole = lazydiv.children(holesel); |
8191
eceaf9e21966
[js] better support for no js in tabs (closes #2162092)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7952
diff
changeset
|
713 |
hole.show(); |
6952
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
714 |
if ((hole.length == 0) && ! reloadable) { |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
715 |
/* the hole is already filed */ |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
716 |
return; |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
717 |
} |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
718 |
lazydiv.loadxhtml(lazydiv.attr('cubicweb:loadurl'), {'pageid': pageid}); |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
719 |
} |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
720 |
|
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
721 |
function triggerLoad(divid) { |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
722 |
jQuery('#lazy-' + divid).trigger('load_' + divid); |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
723 |
} |
7de13eb473e3
[tabs js] merge tabs and lazy js files into cw.ajax.js and use camel case names to satisfy js coding standards
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6947
diff
changeset
|
724 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
725 |
/* DEPRECATED *****************************************************************/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
726 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
727 |
preprocessAjaxLoad = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
728 |
'[3.9] preprocessAjaxLoad() is deprecated, use loadAjaxHtmlHead instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
729 |
function(node, newdomnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
730 |
return loadAjaxHtmlHead(newdomnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
731 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
732 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
733 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
734 |
reloadComponent = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
735 |
'[3.9] reloadComponent() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
736 |
function(compid, rql, registry, nodeid, extraargs) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
737 |
registry = registry || 'components'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
738 |
rql = rql || ''; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
739 |
nodeid = nodeid || (compid + 'Component'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
740 |
extraargs = extraargs || {}; |
5909
9af8ac182f53
[javascript] fix some javascript errors and remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5820
diff
changeset
|
741 |
var node = cw.jqNode(nodeid); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
742 |
return node.loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('component', null, compid, |
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
743 |
rql, registry, extraargs)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
744 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
745 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
746 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
747 |
reloadBox = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
748 |
'[3.9] reloadBox() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
749 |
function(boxid, rql) { |
6947
3d72028a6cd4
[js] using the actual registry fixes spurious warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6924
diff
changeset
|
750 |
return reloadComponent(boxid, rql, 'ctxcomponents', boxid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
751 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
752 |
); |
0 | 753 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
754 |
replacePageChunk = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
755 |
'[3.9] replacePageChunk() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
756 |
function(nodeId, rql, vid, extraparams, /* ... */ swap, callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
757 |
var params = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
758 |
if (callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
759 |
params = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
760 |
callback: callback |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
761 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
762 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
763 |
var node = jQuery('#' + nodeId)[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
764 |
var props = {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
765 |
if (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
766 |
props['rql'] = rql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
767 |
props['fname'] = 'view'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
768 |
props['pageid'] = pageid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
769 |
if (vid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
770 |
props['vid'] = vid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
771 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
772 |
if (extraparams) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
773 |
jQuery.extend(props, extraparams); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
774 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
775 |
// FIXME we need to do asURL(props) manually instead of |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
776 |
// passing `props` directly to loadxml because replacePageChunk |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
777 |
// is sometimes called (abusively) with some extra parameters in `vid` |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
778 |
var mode = swap ? 'swap': 'replace'; |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
779 |
var url = AJAX_BASE_URL + asURL(props); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
780 |
jQuery(node).loadxhtml(url, params, 'get', mode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
781 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
782 |
cw.log('Node', nodeId, 'not found'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
783 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
784 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
785 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
786 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
787 |
loadxhtml = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
788 |
'[3.9] loadxhtml() function is deprecated, use loadxhtml method instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
789 |
function(nodeid, url, /* ... */ replacemode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
790 |
jQuery('#' + nodeid).loadxhtml(url, null, 'post', replacemode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
791 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
792 |
); |
0 | 793 |
|
7422
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
794 |
function remoteExec(fname /* ... */) { |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
795 |
setProgressCursor(); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
796 |
var props = { |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
797 |
fname: fname, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
798 |
pageid: pageid, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
799 |
arg: $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON) |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
800 |
}; |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
801 |
var result = jQuery.ajax({ |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
802 |
url: AJAX_BASE_URL, |
7422
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
803 |
data: props, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
804 |
async: false, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
805 |
traditional: true |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
806 |
}).responseText; |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
807 |
if (result) { |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
808 |
result = cw.evalJSON(result); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
809 |
} |
7422
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
810 |
resetCursor(); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
811 |
return result; |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
812 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
813 |
|
7422
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
814 |
function asyncRemoteExec(fname /* ... */) { |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
815 |
setProgressCursor(); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
816 |
var props = { |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
817 |
fname: fname, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
818 |
pageid: pageid, |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
819 |
arg: $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON) |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
820 |
}; |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
821 |
// XXX we should inline the content of loadRemote here |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8191
diff
changeset
|
822 |
var deferred = loadRemote(AJAX_BASE_URL, props, 'POST'); |
7422
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
823 |
deferred = deferred.addErrback(remoteCallFailed); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
824 |
deferred = deferred.addErrback(resetCursor); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
825 |
deferred = deferred.addCallback(resetCursor); |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
826 |
return deferred; |
9948cdd21b36
[js/ajax] undeprecate (async)remoteExec. closes #1381205
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7374
diff
changeset
|
827 |
} |
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
828 |
|
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
829 |
jQuery(document).ready(function() { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
830 |
_loadDynamicFragments(); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
831 |
// build loaded_scripts / loaded_links lists |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
832 |
cw.loaded_scripts = []; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
833 |
jQuery('head script[src]').each(function(i) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
834 |
cw.utils.extend(cw.loaded_scripts, cw.ajax._listResources(this.getAttribute('src'))); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
835 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
836 |
cw.loaded_links = []; |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
837 |
jQuery('head link[href]').each(function(i) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
838 |
cw.utils.extend(cw.loaded_links, cw.ajax._listResources(this.getAttribute('href'))); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
839 |
}); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7623
diff
changeset
|
840 |
}); |