web/data/cubicweb.js
author Rémi Cardona <remi.cardona@logilab.fr>
Mon, 17 Feb 2014 11:27:25 +0100
changeset 9815 12e6d911027a
parent 9661 c170ec8a4525
child 9821 2077c8da1893
permissions -rw-r--r--
[views] Rewrite cw.utils.formContents() with jQuery (closes #3747244) Use jQuery's serializeArray() method instead. Just keep a bit of compatibility with FCKEditor...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
    /**
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   210
     * .. function:: formContents(elem)
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
     *
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   212
     * cannot use jQuery.serializeArray() directly because of FCKeditor
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
     */
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   214
    formContents: function (elem) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   215
        var $elem, array, names, values;
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   216
        $elem = cw.jqNode(elem);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   217
        array = $elem.serializeArray();
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   218
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   219
        if (typeof FCKeditor !== 'undefined') {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   220
            $elem.find('textarea').each(function (idx, textarea) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   221
                var fck = FCKeditorAPI.GetInstance(textarea.id);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   222
                if (fck) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   223
                    array = jQuery.map(array, function (dict) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   224
                        if (dict.name === textarea.name) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   225
                            // filter out the textarea's - likely empty - value ...
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
                            return null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
                        }
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   228
                        return dict;
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   229
                    });
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   230
                    // ... so we can put the HTML coming from FCKeditor instead.
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   231
                    array.push({
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   232
                        name: textarea.name,
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   233
                        value: fck.GetHTML()
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   234
                    });
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
                }
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   236
            });
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   237
        }
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   238
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   239
        names = [];
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   240
        values = [];
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   241
        jQuery.each(array, function (idx, dict) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   242
            names.push(dict.name);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   243
            values.push(dict.value);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
        return [names, values];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
    },
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
    /**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
     * .. function:: sliceList(lst, start, stop, step)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
     * 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
   252
     * start, stop might be negative
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
     * >>> 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
   255
     * ['c', 'd', 'e', 'f']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
     * >>> 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
   257
     * ['c', 'd']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
     * >>> 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
   259
     * ['d', 'e', 'f']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
     */
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
    sliceList: function (lst, start, stop, step) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
        start = start || 0;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        stop = stop || lst.length;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
        step = step || 1;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        if (stop < 0) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
            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
   267
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
        if (start < 0) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
            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
   270
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
        var result = [];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        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
   273
            result.push(lst[i]);
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 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
   276
    },
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
   277
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
   278
    /**
7284
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   279
     * 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
   280
     */
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   281
    lastOf: function(array) {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   282
        if (array.length) {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   283
            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
   284
        } else {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   285
            return undefined;
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   286
        }
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   287
    },
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   288
7649
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   289
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   290
    /**
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   291
     * .. 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
   292
     *
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   293
     * 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
   294
     */
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   295
    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
   296
        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
   297
        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
   298
    },
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   299
7284
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   300
    /**
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
   301
     * .. 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
   302
     *
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
   303
     * 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
   304
     * 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
   305
     */
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
   306
    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
   307
        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
   308
            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
   309
        });
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
   310
    },
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
   311
    /**
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
   312
     * .. 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
   313
     *
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
   314
     * 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
   315
     * 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
   316
     * :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
   317
     */
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
   318
    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
   319
	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
   320
	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
   321
	    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
   322
	    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
   323
	}
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
   324
	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
   325
    },
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
   326
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
     * .. 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
   329
     *
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
   330
     * 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
   331
     * 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
   332
     * 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
   333
     */
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
   334
    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
   335
	    return (fname + '(' +
9661
c170ec8a4525 [web/data] Remove broken jquery-json plugin (closes #3590335)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9534
diff changeset
   336
		    $.map(cw.utils.sliceList(arguments, 1), JSON.stringify).join(',')
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
   337
		    + ')'
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
   338
		    );
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
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
   341
});
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
/** DOM factories ************************************************************/
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
A = cw.utils.createDomFunction('a');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
BUTTON = cw.utils.createDomFunction('button');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
BR = cw.utils.createDomFunction('br');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
CANVAS = cw.utils.createDomFunction('canvas');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
DD = cw.utils.createDomFunction('dd');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
DIV = cw.utils.createDomFunction('div');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
DL = cw.utils.createDomFunction('dl');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
DT = cw.utils.createDomFunction('dt');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
FIELDSET = cw.utils.createDomFunction('fieldset');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
FORM = cw.utils.createDomFunction('form');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
H1 = cw.utils.createDomFunction('H1');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
H2 = cw.utils.createDomFunction('H2');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
H3 = cw.utils.createDomFunction('H3');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
H4 = cw.utils.createDomFunction('H4');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
H5 = cw.utils.createDomFunction('H5');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
H6 = cw.utils.createDomFunction('H6');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
HR = cw.utils.createDomFunction('hr');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
IMG = cw.utils.createDomFunction('img');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
INPUT = cw.utils.createDomFunction('input');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
LABEL = cw.utils.createDomFunction('label');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
LEGEND = cw.utils.createDomFunction('legend');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
LI = cw.utils.createDomFunction('li');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
OL = cw.utils.createDomFunction('ol');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
OPTGROUP = cw.utils.createDomFunction('optgroup');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
OPTION = cw.utils.createDomFunction('option');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
P = cw.utils.createDomFunction('p');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
PRE = cw.utils.createDomFunction('pre');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
SELECT = cw.utils.createDomFunction('select');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
SPAN = cw.utils.createDomFunction('span');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
STRONG = cw.utils.createDomFunction('strong');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
TABLE = cw.utils.createDomFunction('table');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
TBODY = cw.utils.createDomFunction('tbody');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
TD = cw.utils.createDomFunction('td');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
TEXTAREA = cw.utils.createDomFunction('textarea');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
TFOOT = cw.utils.createDomFunction('tfoot');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
TH = cw.utils.createDomFunction('th');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
THEAD = cw.utils.createDomFunction('thead');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
TR = cw.utils.createDomFunction('tr');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
TT = cw.utils.createDomFunction('tt');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
UL = cw.utils.createDomFunction('ul');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
// cubicweb specific
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
//IFRAME = cw.utils.createDomFunction('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
function IFRAME(params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
    if ('name' in params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
        try {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
            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
   393
        } catch (ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
            var node = document.createElement('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
            node.id = node.name = params.name;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   397
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
    else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
        var node = document.createElement('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
    for (key in params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
        if (key != 'name') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
            var value = params[key];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
            if (key.substring(0, 2) == 'on') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
                // this is an event handler definition
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
                if (typeof value == 'string') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
                    // litteral definition
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
                    value = new Function(value);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
                node[key] = value;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
            } else { // normal node attribute
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   412
                node.setAttribute(key, params[key]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    return node;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
}
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
   418
9259
68cde7431c2c [js] remove 3.9 bw compat (where apparently unused)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8129
diff changeset
   419
// 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
   420
// 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
   421
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
   422
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
   423
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
   424
    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
   425
        '[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
   426
        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
   427
    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
   428
        '[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
   429
        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
   430
});
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
   431
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
   432
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
   433
    $(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
   434
});