author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 09 May 2012 17:15:44 +0200 | |
changeset 8394 | b8b23af60019 |
parent 7258 | 2e7f0d6fa2d6 |
child 9259 | 68cde7431c2c |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
1 |
cw.utils.movedToNamespace(['log', 'jqNode', 'getNode', 'evalJSON', 'urlEncode', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
2 |
'swapDOM'], cw); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
3 |
cw.utils.movedToNamespace(['nodeWalkDepthFirst', 'formContents', 'isArray', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
4 |
'isString', 'isArrayLike', 'sliceList', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
5 |
'toISOTimestamp'], cw.utils); |
0 | 6 |
|
7 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
8 |
if ($.noop === undefined) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
9 |
function noop() {} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
10 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
11 |
noop = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
12 |
'[3.9] noop() is deprecated, use $.noop() instead (XXX requires jQuery 1.4)', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
13 |
$.noop); |
0 | 14 |
} |
15 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
16 |
// ========== ARRAY EXTENSIONS ========== /// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
17 |
Array.prototype.contains = cw.utils.deprecatedFunction( |
7258
2e7f0d6fa2d6
[js] fix inArray usage in reorderTabIndex() : inArray returns -1 if element is not found, not 'false'
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6880
diff
changeset
|
18 |
'[3.9] array.contains(elt) is deprecated, use $.inArray(elt, array)!=-1 instead', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
19 |
function(element) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
20 |
return jQuery.inArray(element, this) != - 1; |
0 | 21 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
22 |
); |
0 | 23 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
24 |
// ========== END OF ARRAY EXTENSIONS ========== /// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
25 |
forEach = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
26 |
'[3.9] forEach() is deprecated, use $.each() instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
27 |
function(array, func) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
28 |
return $.each(array, func); |
0 | 29 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
30 |
); |
0 | 31 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
32 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
33 |
* .. function:: cw.utils.deprecatedFunction(msg, function) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
34 |
* |
6880
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
35 |
* jQUery flattens arrays returned by the mapping function: :: |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
36 |
* |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
37 |
* >>> y = ['a:b:c', 'd:e'] |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
38 |
* >>> jQuery.map(y, function(y) { return y.split(':');}) |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
39 |
* ["a", "b", "c", "d", "e"] |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
40 |
* // where one would expect: |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
41 |
* [ ["a", "b", "c"], ["d", "e"] ] |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
42 |
*/ |
6880
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6545
diff
changeset
|
43 |
// XXX why not the same argument order as $.map and forEach ? |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
44 |
map = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
45 |
'[3.9] map() is deprecated, use $.map instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
46 |
function(func, array) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
47 |
var result = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
48 |
for (var i = 0, length = array.length; i < length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
49 |
result.push(func(array[i])); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
50 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
51 |
return result; |
0 | 52 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
53 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
54 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
55 |
findValue = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
56 |
'[3.9] findValue(array, elt) is deprecated, use $.inArray(elt, array) instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
57 |
function(array, element) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
58 |
return jQuery.inArray(element, array); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
59 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
60 |
); |
0 | 61 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
62 |
filter = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
63 |
'[3.9] filter(func, array) is deprecated, use $.grep(array, f) instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
64 |
function(func, array) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
65 |
return $.grep(array, func); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
66 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
67 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
68 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
69 |
addElementClass = cw.utils.deprecatedFunction( |
6545 | 70 |
'[3.9] addElementClass(node, cls) is deprecated, use $(node).addClass(cls) instead', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
71 |
function(node, klass) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
72 |
$(node).addClass(klass); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
73 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
74 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
75 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
76 |
removeElementClass = cw.utils.deprecatedFunction( |
6545 | 77 |
'[3.9] removeElementClass(node, cls) is deprecated, use $(node).removeClass(cls) instead', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
78 |
function(node, klass) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
79 |
$(node).removeClass(klass); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
80 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
81 |
); |
0 | 82 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
83 |
hasElementClass = cw.utils.deprecatedFunction( |
6544
e0d20fb46389
[jquery] className doesn't exist anymore in 1.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
84 |
'[3.9] hasElementClass(node, cls) is deprecated, use $(node).hasClass(cls)', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
85 |
function(node, klass) { |
6544
e0d20fb46389
[jquery] className doesn't exist anymore in 1.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
86 |
return $(node).hasClass(klass); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
87 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
88 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
89 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
90 |
getNodeAttribute = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
91 |
'[3.9] getNodeAttribute(node, attr) is deprecated, use $(node).attr(attr)', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
92 |
function(node, attribute) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
93 |
return $(node).attr(attribute); |
2537
73c83c14dd2c
[javascript] fix IFRAME implementation and make it work in IE 6/7 + FF3 with text/html served pages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1563
diff
changeset
|
94 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
95 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
96 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
97 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
98 |
* The only known usage of KEYS is in the tag cube. Once cubicweb-tag 1.7.0 is out, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
99 |
* this current definition can be removed. |
0 | 100 |
*/ |
101 |
var KEYS = { |
|
102 |
KEY_ESC: 27, |
|
103 |
KEY_ENTER: 13 |
|
1563
b130c6cec8c2
loadJSON -> loadRemote, correctly handle json
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1419
diff
changeset
|
104 |
}; |