author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 25 Nov 2014 12:15:41 +0100 | |
branch | stable |
changeset 10056 | cb96f4403cf2 |
parent 9534 | 34d9de030564 |
child 9661 | c170ec8a4525 |
permissions | -rw-r--r-- |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
1 |
|
5705
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
2 |
function Namespace(name) { |
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
3 |
this.__name__ = name; |
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
4 |
} |
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
5 |
|
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
6 |
cw = new Namespace('cw'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
7 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
8 |
jQuery.extend(cw, { |
6388
34317f395619
[js] add cubes namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
9 |
cubes: new Namespace('cubes'), |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
10 |
/* provide a removeEventListener / detachEvent definition to |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
11 |
* to bypass a jQuery 1.4.2 bug when unbind() is called on a |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
12 |
* plain JS object and not a DOM node. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
13 |
* see http://dev.jquery.com/ticket/6184 for more details |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
14 |
*/ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
15 |
removeEventListener: function() {}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
16 |
detachEvent: function() {}, |
6388
34317f395619
[js] add cubes namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5949
diff
changeset
|
17 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
18 |
log: function () { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
var args = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
20 |
for (var i = 0; i < arguments.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
21 |
args.push(arguments[i]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
23 |
if (typeof(window) != "undefined" && window.console && window.console.log) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
24 |
window.console.log(args.join(' ')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
25 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
26 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
27 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
28 |
//removed: getElementsByTagAndClassName, replaceChildNodes, toggleElementClass |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
29 |
// partial, merge, isNotEmpty, update, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
30 |
// String.in_, String.join, list, getattr, attrgetter, methodcaller, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
31 |
// min, max, dict, concat |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
32 |
jqNode: function (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
33 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
34 |
* .. function:: jqNode(node) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
35 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
36 |
* safe version of jQuery('#nodeid') because we use ':' in nodeids |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
* which messes with jQuery selection mechanism |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
if (typeof(node) == 'string') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
node = document.getElementById(node); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
41 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
if (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
return $(node); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
45 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
46 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
|
9284
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
48 |
// escapes string selectors (e.g. "foo.[subject]:42" -> "foo\.\[subject\]\:42" |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
49 |
escape: function(selector) { |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
50 |
if (typeof(selector) == 'string') { |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
51 |
return selector.replace( /(:|\.|\[|\])/g, "\\$1" ); |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
52 |
} |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
53 |
// cw.log('non string selector', selector); |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
54 |
return ''; |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
55 |
}, |
4c37808fd284
[js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9259
diff
changeset
|
56 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
getNode: function (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
58 |
if (typeof(node) == 'string') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
return document.getElementById(node); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
60 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
61 |
return node; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
62 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
64 |
evalJSON: function (json) { // trust source |
7831
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
65 |
try { |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
66 |
return eval("(" + json + ")"); |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
67 |
} catch(e) { |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
68 |
cw.log(e); |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
69 |
cw.log('The faulty json source was', json); |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
70 |
throw (e); |
6af00dbfaadd
[cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7649
diff
changeset
|
71 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
72 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
74 |
urlEncode: function (str) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
75 |
if (typeof(encodeURIComponent) != "undefined") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
76 |
return encodeURIComponent(str).replace(/\'/g, '%27'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
78 |
return escape(str).replace(/\+/g, '%2B').replace(/\"/g, '%22'). |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
79 |
rval.replace(/\'/g, '%27'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
80 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
81 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
82 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
83 |
swapDOM: function (dest, src) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
84 |
dest = cw.getNode(dest); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
85 |
var parent = dest.parentNode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
86 |
if (src) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
87 |
src = cw.getNode(src); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
parent.replaceChild(src, dest); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
89 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
90 |
parent.removeChild(dest); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
91 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
92 |
return src; |
7961
f7ab1db39778
[js]Â missing trailing comma
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7953
diff
changeset
|
93 |
}, |
7953
a37531c8a4a6
merge and fix cubicwebSortValueExtraction pb which disappeared when tablesorter.js has been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7831
diff
changeset
|
94 |
|
a37531c8a4a6
merge and fix cubicwebSortValueExtraction pb which disappeared when tablesorter.js has been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7831
diff
changeset
|
95 |
sortValueExtraction: function (node) { |
8129
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
96 |
var $node = $(node); |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
97 |
var sortvalue = $node.attr('cubicweb:sortvalue'); |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
98 |
// No metadata found, use cell content as sort key |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
99 |
if (sortvalue === undefined) { |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
100 |
return $node.text(); |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
101 |
} |
2dedcc15208d
[table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8071
diff
changeset
|
102 |
return cw.evalJSON(sortvalue); |
8071
9ab3a9406473
[js/tablesorter] work around tablesorter deficiencies (bool handling)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8045
diff
changeset
|
103 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
104 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
105 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
106 |
|
5705
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
107 |
cw.utils = new Namespace('cw.utils'); |
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
108 |
jQuery.extend(cw.utils, { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
109 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
110 |
deprecatedFunction: function (msg, newfunc) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
111 |
return function () { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
112 |
cw.log(msg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
113 |
return newfunc.apply(this, arguments); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
114 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
115 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
116 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
117 |
createDomFunction: function (tag) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
118 |
function builddom(params, children) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
119 |
var node = document.createElement(tag); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
120 |
for (key in params) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
121 |
var value = params[key]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
122 |
if (key.substring(0, 2) == 'on') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
123 |
// this is an event handler definition |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
124 |
if (typeof value == 'string') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
125 |
// litteral definition |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
126 |
value = new Function(value); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
127 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
128 |
node[key] = value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
129 |
} else { // normal node attribute |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
130 |
jQuery(node).attr(key, params[key]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
131 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
132 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
133 |
if (children) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
134 |
if (!cw.utils.isArrayLike(children)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
135 |
children = [children]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
136 |
for (var i = 2; i < arguments.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
137 |
var arg = arguments[i]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
138 |
if (cw.utils.isArray(arg)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
139 |
jQuery.merge(children, arg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
140 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
141 |
children.push(arg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
142 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
143 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
144 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
145 |
for (var i = 0; i < children.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
146 |
var child = children[i]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
147 |
if (typeof child == "string" || typeof child == "number") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
148 |
child = document.createTextNode(child); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
149 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
150 |
node.appendChild(child); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
151 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
152 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
153 |
return node; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
154 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
155 |
return builddom; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
156 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
157 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
158 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
159 |
* .. function:: toISOTimestamp(date) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
160 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
161 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
162 |
toISOTimestamp: function (date) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
163 |
if (typeof(date) == "undefined" || date === null) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
164 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
165 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
166 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
167 |
function _padTwo(n) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
168 |
return (n > 9) ? n : "0" + n; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
169 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
170 |
var isoTime = [_padTwo(date.getHours()), _padTwo(date.getMinutes()), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
171 |
_padTwo(date.getSeconds())].join(':'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
172 |
var isoDate = [date.getFullYear(), _padTwo(date.getMonth() + 1), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
173 |
_padTwo(date.getDate())].join("-"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
174 |
return isoDate + " " + isoTime; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
175 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
176 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
177 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
178 |
* .. function:: nodeWalkDepthFirst(node, visitor) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
179 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
180 |
* depth-first implementation of the nodeWalk function found |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
181 |
* in `MochiKit.Base <http://mochikit.com/doc/html/MochiKit/Base.html#fn-nodewalk>`_ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
182 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
183 |
nodeWalkDepthFirst: function (node, visitor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
184 |
var children = visitor(node); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
185 |
if (children) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
186 |
for (var i = 0; i < children.length; i++) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
187 |
cw.utils.nodeWalkDepthFirst(children[i], visitor); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
188 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
189 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
190 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
191 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
192 |
isArray: function (it) { // taken from dojo |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
193 |
return it && (it instanceof Array || typeof it == "array"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
194 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
195 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
196 |
isString: function (it) { // taken from dojo |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
197 |
return !!arguments.length && it != null && (typeof it == "string" || it instanceof String); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
198 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
199 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
200 |
isArrayLike: function (it) { // taken from dojo |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
201 |
return (it && it !== undefined && |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
202 |
// keep out built-in constructors (Number, String, ...) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
203 |
// which have length properties |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
204 |
!cw.utils.isString(it) && !jQuery.isFunction(it) && |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
205 |
!(it.tagName && it.tagName.toLowerCase() == 'form') && |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
206 |
(cw.utils.isArray(it) || isFinite(it.length))); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
207 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
208 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
209 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
210 |
* .. function:: formContents(elem \/* = document.body *\/) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
211 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
212 |
* this implementation comes from MochiKit |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
213 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
214 |
formContents: function (elem /* = document.body */ ) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
215 |
var names = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
216 |
var values = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
217 |
if (typeof(elem) == "undefined" || elem === null) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
218 |
elem = document.body; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
219 |
} else { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
220 |
elem = cw.getNode(elem); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
221 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
222 |
cw.utils.nodeWalkDepthFirst(elem, function (elem) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
223 |
var name = elem.name; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
224 |
if (name && name.length) { |
9534
34d9de030564
[web/data] Ignore disabled widgets in cw.utils.formContents() (closes #3544492)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9284
diff
changeset
|
225 |
if (elem.disabled) { |
34d9de030564
[web/data] Ignore disabled widgets in cw.utils.formContents() (closes #3544492)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9284
diff
changeset
|
226 |
return null; |
34d9de030564
[web/data] Ignore disabled widgets in cw.utils.formContents() (closes #3544492)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9284
diff
changeset
|
227 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
228 |
var tagName = elem.tagName.toUpperCase(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
229 |
if (tagName === "INPUT" && (elem.type == "radio" || elem.type == "checkbox") && !elem.checked) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
230 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
231 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
232 |
if (tagName === "SELECT") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
233 |
if (elem.type == "select-one") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
234 |
if (elem.selectedIndex >= 0) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
235 |
var opt = elem.options[elem.selectedIndex]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
236 |
var v = opt.value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
237 |
if (!v) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
238 |
var h = opt.outerHTML; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
239 |
// internet explorer sure does suck. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
240 |
if (h && !h.match(/^[^>]+\svalue\s*=/i)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
241 |
v = opt.text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
242 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
243 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
244 |
names.push(name); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
245 |
values.push(v); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
246 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
247 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
248 |
// no form elements? |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
249 |
names.push(name); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
250 |
values.push(""); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
251 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
252 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
253 |
var opts = elem.options; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
254 |
if (!opts.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
255 |
names.push(name); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
256 |
values.push(""); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
257 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
258 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
259 |
for (var i = 0; i < opts.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
260 |
var opt = opts[i]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
261 |
if (!opt.selected) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
262 |
continue; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
263 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
264 |
var v = opt.value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
265 |
if (!v) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
266 |
var h = opt.outerHTML; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
267 |
// internet explorer sure does suck. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
268 |
if (h && !h.match(/^[^>]+\svalue\s*=/i)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
269 |
v = opt.text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
270 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
271 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
272 |
names.push(name); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
273 |
values.push(v); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
274 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
275 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
276 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
277 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
278 |
if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" || tagName === "DIV") { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
279 |
return elem.childNodes; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
280 |
} |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
281 |
var value = elem.value; |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
282 |
if (tagName === "TEXTAREA") { |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
283 |
if (typeof(FCKeditor) != 'undefined') { |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
284 |
var fck = FCKeditorAPI.GetInstance(elem.id); |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
285 |
if (fck) { |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
286 |
value = fck.GetHTML(); |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
287 |
} |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
288 |
} |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
289 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
290 |
names.push(name); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5705
diff
changeset
|
291 |
values.push(value || ''); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
292 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
293 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
294 |
return elem.childNodes; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
295 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
296 |
return [names, values]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
297 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
298 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
299 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
300 |
* .. function:: sliceList(lst, start, stop, step) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
301 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
302 |
* returns a subslice of `lst` using `start`/`stop`/`step` |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
303 |
* start, stop might be negative |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
304 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
305 |
* >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
306 |
* ['c', 'd', 'e', 'f'] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
307 |
* >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2, -2) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
308 |
* ['c', 'd'] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
309 |
* >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], -3) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
310 |
* ['d', 'e', 'f'] |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
311 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
312 |
sliceList: function (lst, start, stop, step) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
313 |
start = start || 0; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
314 |
stop = stop || lst.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
315 |
step = step || 1; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
316 |
if (stop < 0) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
317 |
stop = Math.max(lst.length + stop, 0); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
318 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
319 |
if (start < 0) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
320 |
start = Math.min(lst.length + start, lst.length); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
321 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
322 |
var result = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
323 |
for (var i = start; i < stop; i += step) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
324 |
result.push(lst[i]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
325 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
326 |
return result; |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
327 |
}, |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
328 |
|
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
329 |
/** |
7284
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
330 |
* returns the last element of an array-like object or undefined if empty |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
331 |
*/ |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
332 |
lastOf: function(array) { |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
333 |
if (array.length) { |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
334 |
return array[array.length-1]; |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
335 |
} else { |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
336 |
return undefined; |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
337 |
} |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
338 |
}, |
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
339 |
|
7649
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
340 |
|
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
341 |
/** |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
342 |
* .. function:: extend(array1, array2) |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
343 |
* |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
344 |
* equivalent of python ``+=`` statement on lists (array1 += array2) |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
345 |
*/ |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
346 |
extend: function(array1, array2) { |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
347 |
array1.push.apply(array1, array2); |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
348 |
return array1; // return array1 for convenience |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
349 |
}, |
ede740bd7077
[ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7284
diff
changeset
|
350 |
|
7284
a474cb989546
[js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6448
diff
changeset
|
351 |
/** |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
352 |
* .. function:: difference(lst1, lst2) |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
353 |
* |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
354 |
* returns a list containing all elements in `lst1` that are not |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
355 |
* in `lst2`. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
356 |
*/ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
357 |
difference: function(lst1, lst2) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
358 |
return jQuery.grep(lst1, function(elt, i) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
359 |
return jQuery.inArray(elt, lst2) == -1; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
360 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
361 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
362 |
/** |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
363 |
* .. function:: domid(string) |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
364 |
* |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
365 |
* return a valid DOM id from a string (should also be usable in jQuery |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
366 |
* search expression...). This is the javascript implementation of |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
367 |
* :func:`cubicweb.uilib.domid`. |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
368 |
*/ |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
369 |
domid: function (string) { |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
370 |
var newstring = string.replace(".", "_").replace("-", "_"); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
371 |
while (newstring != string) { |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
372 |
string = newstring; |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
373 |
newstring = newstring.replace(".", "_").replace("-", "_"); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
374 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
375 |
return newstring; // XXX |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
376 |
}, |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
377 |
|
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
378 |
/** |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
379 |
* .. function:: strFuncCall(fname, *args) |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
380 |
* |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
381 |
* return a string suitable to call the `fname` javascript function with the |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
382 |
* given arguments (which should be correctly typed).. This is providing |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
383 |
* javascript implementation equivalent to :func:`cubicweb.uilib.js`. |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
384 |
*/ |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
385 |
strFuncCall: function(fname /* ...*/) { |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
386 |
return (fname + '(' + |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
387 |
$.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON).join(',') |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
388 |
+ ')' |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
389 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
390 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
391 |
|
5705
30b94973bc67
[javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5699
diff
changeset
|
392 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
393 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
394 |
/** DOM factories ************************************************************/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
395 |
A = cw.utils.createDomFunction('a'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
396 |
BUTTON = cw.utils.createDomFunction('button'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
397 |
BR = cw.utils.createDomFunction('br'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
398 |
CANVAS = cw.utils.createDomFunction('canvas'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
399 |
DD = cw.utils.createDomFunction('dd'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
400 |
DIV = cw.utils.createDomFunction('div'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
401 |
DL = cw.utils.createDomFunction('dl'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
402 |
DT = cw.utils.createDomFunction('dt'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
403 |
FIELDSET = cw.utils.createDomFunction('fieldset'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
404 |
FORM = cw.utils.createDomFunction('form'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
405 |
H1 = cw.utils.createDomFunction('H1'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
406 |
H2 = cw.utils.createDomFunction('H2'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
407 |
H3 = cw.utils.createDomFunction('H3'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
408 |
H4 = cw.utils.createDomFunction('H4'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
409 |
H5 = cw.utils.createDomFunction('H5'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
410 |
H6 = cw.utils.createDomFunction('H6'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
411 |
HR = cw.utils.createDomFunction('hr'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
412 |
IMG = cw.utils.createDomFunction('img'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
413 |
INPUT = cw.utils.createDomFunction('input'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
414 |
LABEL = cw.utils.createDomFunction('label'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
415 |
LEGEND = cw.utils.createDomFunction('legend'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
416 |
LI = cw.utils.createDomFunction('li'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
417 |
OL = cw.utils.createDomFunction('ol'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
418 |
OPTGROUP = cw.utils.createDomFunction('optgroup'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
419 |
OPTION = cw.utils.createDomFunction('option'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
420 |
P = cw.utils.createDomFunction('p'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
421 |
PRE = cw.utils.createDomFunction('pre'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
422 |
SELECT = cw.utils.createDomFunction('select'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
423 |
SPAN = cw.utils.createDomFunction('span'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
424 |
STRONG = cw.utils.createDomFunction('strong'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
425 |
TABLE = cw.utils.createDomFunction('table'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
426 |
TBODY = cw.utils.createDomFunction('tbody'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
427 |
TD = cw.utils.createDomFunction('td'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
428 |
TEXTAREA = cw.utils.createDomFunction('textarea'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
429 |
TFOOT = cw.utils.createDomFunction('tfoot'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
430 |
TH = cw.utils.createDomFunction('th'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
431 |
THEAD = cw.utils.createDomFunction('thead'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
432 |
TR = cw.utils.createDomFunction('tr'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
433 |
TT = cw.utils.createDomFunction('tt'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
434 |
UL = cw.utils.createDomFunction('ul'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
435 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
436 |
// cubicweb specific |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
437 |
//IFRAME = cw.utils.createDomFunction('iframe'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
438 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
439 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
440 |
function IFRAME(params) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
441 |
if ('name' in params) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
442 |
try { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
443 |
var node = document.createElement('<iframe name="' + params['name'] + '">'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
444 |
} catch (ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
445 |
var node = document.createElement('iframe'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
446 |
node.id = node.name = params.name; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
447 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
448 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
449 |
else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
450 |
var node = document.createElement('iframe'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
451 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
452 |
for (key in params) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
453 |
if (key != 'name') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
454 |
var value = params[key]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
455 |
if (key.substring(0, 2) == 'on') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
456 |
// this is an event handler definition |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
457 |
if (typeof value == 'string') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
458 |
// litteral definition |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
459 |
value = new Function(value); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
460 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
461 |
node[key] = value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
462 |
} else { // normal node attribute |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
463 |
node.setAttribute(key, params[key]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
464 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
465 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
466 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
467 |
return node; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
468 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
469 |
|
9259
68cde7431c2c
[js] remove 3.9 bw compat (where apparently unused)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8129
diff
changeset
|
470 |
// cubes: tag, keyword and apycot seem to use this, including require/provide |
68cde7431c2c
[js] remove 3.9 bw compat (where apparently unused)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8129
diff
changeset
|
471 |
// backward compat |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
472 |
CubicWeb = cw; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
473 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
474 |
jQuery.extend(cw, { |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
475 |
require: cw.utils.deprecatedFunction( |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
476 |
'[3.9] CubicWeb.require() is not used anymore', |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
477 |
function(module) {}), |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
478 |
provide: cw.utils.deprecatedFunction( |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
479 |
'[3.9] CubicWeb.provide() is not used anymore', |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
480 |
function(module) {}) |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
481 |
}); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
482 |
|
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
483 |
jQuery(document).ready(function() { |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6388
diff
changeset
|
484 |
$(cw).trigger('server-response', [false, document]); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
485 |
}); |