author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 21 Jul 2010 12:46:21 +0200 | |
branch | stable |
changeset 6004 | d17d3b34bc12 |
parent 5727 | 29afb9e715bb |
child 6544 | e0d20fb46389 |
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( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
18 |
'[3.9] array.contains(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
|
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 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
35 |
* jQUery flattens arrays returned by the mapping function: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
36 |
* >>> y = ['a:b:c', 'd:e'] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
37 |
* >>> jQuery.map(y, function(y) { return y.split(':');}) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
38 |
* ["a", "b", "c", "d", "e"] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
39 |
* // where one would expect: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
40 |
* [ ["a", "b", "c"], ["d", "e"] ] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
41 |
* XXX why not the same argument order as $.map and forEach ? |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
42 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
43 |
map = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
44 |
'[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
|
45 |
function(func, array) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
46 |
var result = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
47 |
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
|
48 |
result.push(func(array[i])); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
49 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
50 |
return result; |
0 | 51 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
52 |
); |
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 |
findValue = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
55 |
'[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
|
56 |
function(array, element) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
57 |
return jQuery.inArray(element, array); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
58 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
59 |
); |
0 | 60 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
61 |
filter = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
62 |
'[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
|
63 |
function(func, array) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
64 |
return $.grep(array, func); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
65 |
} |
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 |
addElementClass = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
69 |
'[3.9] addElementClass(node, cls) is depcreated, use $(node).addClass(cls) instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
70 |
function(node, klass) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
71 |
$(node).addClass(klass); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
72 |
} |
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 |
removeElementClass = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
76 |
'[3.9] removeElementClass(node, cls) is depcreated, use $(node).removeClass(cls) instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
77 |
function(node, klass) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
78 |
$(node).removeClass(klass); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
79 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
80 |
); |
0 | 81 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
82 |
hasElementClass = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
83 |
'[3.9] hasElementClass(node, cls) is depcreated, use $.className.has(node, cls)', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
84 |
function(node, klass) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
85 |
return $.className.has(node, klass); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
86 |
} |
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 |
getNodeAttribute = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
90 |
'[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
|
91 |
function(node, attribute) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
92 |
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
|
93 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5186
diff
changeset
|
94 |
); |
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 |
* 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
|
98 |
* this current definition can be removed. |
0 | 99 |
*/ |
100 |
var KEYS = { |
|
101 |
KEY_ESC: 27, |
|
102 |
KEY_ENTER: 13 |
|
1563
b130c6cec8c2
loadJSON -> loadRemote, correctly handle json
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1419
diff
changeset
|
103 |
}; |