web/data/cubicweb.compat.js
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 08 Apr 2010 12:42:47 +0200
branchstable
changeset 5186 f3c2cb460ad9
parent 3096 8ee9529d8367
child 5658 7b9553a9db65
permissions -rw-r--r--
[doc] note on pytestconf, fixlets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
/* MochiKit -> jQuery compatibility module */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
function forEach(array, func) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
    for (var i=0, length=array.length; i<length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
	func(array[i]);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
     9
// XXX looks completely unused (candidate for removal)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
function getElementsByTagAndClassName(tag, klass, root) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
    root = root || document;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
    // FIXME root is not used in this compat implementation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
    return jQuery(tag + '.' + klass);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    16
/* jQUery flattens arrays returned by the mapping function:
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    17
   >>> y = ['a:b:c', 'd:e']
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    18
   >>> jQuery.map(y, function(y) { return y.split(':');})
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    19
   ["a", "b", "c", "d", "e"]
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    20
   // where one would expect:
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    21
   [ ["a", "b", "c"], ["d", "e"] ]
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    22
   XXX why not the same argument order as $.map and forEach ?
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    23
*/
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
function map(func, array) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    var result = [];
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    26
    for (var i=0, length=array.length;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    27
         i<length;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    28
         i++) {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
	result.push(func(array[i]));
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
    return result;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
function findValue(array, element) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    return jQuery.inArray(element, array);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
function filter(func, array) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    return jQuery.grep(array, func);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
function noop() {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
function addElementClass(node, klass) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
    jQuery(node).addClass(klass);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
    48
// XXX looks completely unused (candidate for removal)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
function toggleElementClass(node, klass) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    jQuery(node).toggleClass(klass);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
function removeElementClass(node, klass) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    jQuery(node).removeClass(klass);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
12
95bc1d15349b javascript cleaning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    57
hasElementClass = jQuery.className.has;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
function partial(func) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    var args = sliceList(arguments, 1);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
    return function() {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
	return func.apply(null, merge(args, arguments));
12
95bc1d15349b javascript cleaning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    64
    };
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
function log() {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    // XXX dummy implementation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
    // console.log.apply(arguments); ???
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    var args = [];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
    for (var i=0; i<arguments.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
	args.push(arguments[i]);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    if (typeof(window) != "undefined" && window.console
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        && window.console.log) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
	window.console.log(args.join(' '));
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
function getNodeAttribute(node, attribute) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    return jQuery(node).attr(attribute);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
function isArray(it){ // taken from dojo
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    return it && (it instanceof Array || typeof it == "array");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
function isString(it){ // taken from dojo
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
    return !!arguments.length && it != null && (typeof it == "string" || it instanceof String);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
function isArrayLike(it) { // taken from dojo
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
    return (it && it !== undefined &&
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
	    // keep out built-in constructors (Number, String, ...) which have length
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
	    // properties
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
	    !isString(it) && !jQuery.isFunction(it) &&
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
	    !(it.tagName && it.tagName.toLowerCase() == 'form') &&
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
	    (isArray(it) || isFinite(it.length)));
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
function getNode(node) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    if (typeof(node) == 'string') {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        return document.getElementById(node);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    return node;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
/* safe version of jQuery('#nodeid') because we use ':' in nodeids
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
 * which messes with jQuery selection mechanism
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
function jqNode(node) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    node = getNode(node);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
    if (node) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
	return jQuery(node);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
    return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
function evalJSON(json) { // trust source
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    return eval("(" + json + ")");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
function urlEncode(str) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
    if (typeof(encodeURIComponent) != "undefined") {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        return encodeURIComponent(str).replace(/\'/g, '%27');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
    } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        return escape(str).replace(/\+/g, '%2B').replace(/\"/g,'%22').rval.replace(/\'/g, '%27');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
function swapDOM(dest, src) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
    dest = getNode(dest);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
    var parent = dest.parentNode;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    if (src) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        src = getNode(src);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        parent.replaceChild(src, dest);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
    } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        parent.removeChild(dest);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
    return src;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
function replaceChildNodes(node/*, nodes...*/) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    var elem = getNode(node);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    arguments[0] = elem;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    var child;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
    while ((child = elem.firstChild)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
        elem.removeChild(child);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    if (arguments.length < 2) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        return elem;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
	for (var i=1; i<arguments.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
	    elem.appendChild(arguments[i]);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
	return elem;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
update = jQuery.extend;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
function createDomFunction(tag) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    function builddom(params, children) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
	var node = document.createElement(tag);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
	for (key in params) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
	    var value = params[key];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
	    if (key.substring(0, 2) == 'on') {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
		// this is an event handler definition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
		if (typeof value == 'string') {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
		    // litteral definition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
		    value = new Function(value);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
		}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
		node[key] = value;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
	    } else { // normal node attribute
3096
8ee9529d8367 [views] #343641: fix calendar with IE6/7
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2537
diff changeset
   180
		jQuery(node).attr(key, params[key]);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
	    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
	if (children) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
	    if (!isArrayLike(children)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
		children = [children];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
		for (var i=2; i<arguments.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
		    var arg = arguments[i];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
		    if (isArray(arg)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
			children = merge(children, arg);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
		    } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
			children.push(arg);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
		    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
		}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
	    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
	    for (var i=0; i<children.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
		var child = children[i];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
		if (typeof child == "string" || typeof child == "number") {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
		    child = document.createTextNode(child);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
		}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
		node.appendChild(child);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
	    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
	return node;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
    return builddom;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
A = createDomFunction('a');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
BUTTON = createDomFunction('button');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
BR = createDomFunction('br');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
CANVAS = createDomFunction('canvas');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
DD = createDomFunction('dd');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
DIV = createDomFunction('div');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
DL = createDomFunction('dl');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
DT = createDomFunction('dt');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
FIELDSET = createDomFunction('fieldset');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
FORM = createDomFunction('form');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
H1 = createDomFunction('H1');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
H2 = createDomFunction('H2');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
H3 = createDomFunction('H3');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
H4 = createDomFunction('H4');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
H5 = createDomFunction('H5');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
H6 = createDomFunction('H6');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
HR = createDomFunction('hr');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
IMG = createDomFunction('img');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
INPUT = createDomFunction('input');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
LABEL = createDomFunction('label');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
LEGEND = createDomFunction('legend');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
LI = createDomFunction('li');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
OL = createDomFunction('ol');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
OPTGROUP = createDomFunction('optgroup');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
OPTION = createDomFunction('option');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
P = createDomFunction('p');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
PRE = createDomFunction('pre');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
SELECT = createDomFunction('select');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
SPAN = createDomFunction('span');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
STRONG = createDomFunction('strong');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
TABLE = createDomFunction('table');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
TBODY = createDomFunction('tbody');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
TD = createDomFunction('td');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
TEXTAREA = createDomFunction('textarea');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
TFOOT = createDomFunction('tfoot');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
TH = createDomFunction('th');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
THEAD = createDomFunction('thead');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
TR = createDomFunction('tr');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
TT = createDomFunction('tt');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
UL = createDomFunction('ul');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
// cubicweb specific
1117
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   250
//IFRAME = createDomFunction('iframe');
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   251
function IFRAME(params){
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   252
  if ('name' in params){
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   253
    try {
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   254
      var node = document.createElement('<iframe name="'+params['name']+'">');
2537
73c83c14dd2c [javascript] fix IFRAME implementation and make it work in IE 6/7 + FF3 with text/html served pages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1563
diff changeset
   255
    } catch (ex) {
73c83c14dd2c [javascript] fix IFRAME implementation and make it work in IE 6/7 + FF3 with text/html served pages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1563
diff changeset
   256
      var node = document.createElement('iframe');
73c83c14dd2c [javascript] fix IFRAME implementation and make it work in IE 6/7 + FF3 with text/html served pages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1563
diff changeset
   257
      node.id = node.name = params.name;
73c83c14dd2c [javascript] fix IFRAME implementation and make it work in IE 6/7 + FF3 with text/html served pages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1563
diff changeset
   258
    }
1117
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   259
  }
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   260
  else{
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   261
    var node = document.createElement('iframe');
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   262
  }
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   263
  for (key in params) {
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   264
    if (key != 'name'){
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   265
      var value = params[key];
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   266
      if (key.substring(0, 2) == 'on') {
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   267
	// this is an event handler definition
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   268
	if (typeof value == 'string') {
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   269
	  // litteral definition
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   270
	  value = new Function(value);
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   271
	}
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   272
	node[key] = value;
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   273
      } else { // normal node attribute
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   274
	node.setAttribute(key, params[key]);
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   275
      }
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   276
    }
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   277
  }
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   278
  return node;
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   279
}
20a21b3153b0 define an IFRAME function to fix a bug on IE6 and IE7 to avoid to open a new window
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 226
diff changeset
   280
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   281
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   282
// dummy ultra minimalist implementation on deferred for jQuery
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   283
function Deferred() {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   284
    this.__init__(this);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   285
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   286
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   287
jQuery.extend(Deferred.prototype, {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
    __init__: function() {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   289
	this._onSuccess = [];
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   290
	this._onFailure = [];
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   291
	this._req = null;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   292
        this._result = null;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   293
        this._error = null;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
    },
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    addCallback: function(callback) {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   297
        if (this._req.readyState == 4) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   298
            if (this._result) { callback.apply(null, this._result, this._req); }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   299
        }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   300
        else { this._onSuccess.push([callback, sliceList(arguments, 1)]); }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
	return this;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
    },
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
    addErrback: function(callback) {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   305
        if (this._req.readyState == 4) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   306
            if (this._error) { callback.apply(null, this._error, this._req); }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   307
        }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   308
        else { this._onFailure.push([callback, sliceList(arguments, 1)]); }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
	return this;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
    },
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
    success: function(result) {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   313
        this._result = result;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
	try {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   315
	    for (var i=0; i<this._onSuccess.length; i++) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   316
		var callback = this._onSuccess[i][0];
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   317
		var args = merge([result, this._req], this._onSuccess[i][1]);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
		callback.apply(null, args);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
	    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
	} catch (error) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
	    this.error(this.xhr, null, error);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
    },
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
    error: function(xhr, status, error) {
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   326
        this._error = error;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   327
	for (var i=0; i<this._onFailure.length; i++) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   328
	    var callback = this._onFailure[i][0];
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   329
	    var args = merge([error, this._req], this._onFailure[i][1]);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
	    callback.apply(null, args);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
});
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
5186
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   337
/*
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   338
 * Asynchronously load an url and return a deferred
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   339
 * whose callbacks args are decoded according to
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   340
 * the Content-Type response header
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   341
 */
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   342
function loadRemote(url, data, reqtype) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   343
    var d = new Deferred();
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   344
    jQuery.ajax({
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   345
	url: url,
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   346
	type: reqtype,
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   347
	data: data,
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   348
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   349
	beforeSend: function(xhr) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   350
	    d._req = xhr;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   351
	},
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   352
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   353
	success: function(data, status) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   354
            if (d._req.getResponseHeader("content-type") == 'application/json') {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   355
              data = evalJSON(data);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   356
            }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   357
	    d.success(data);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   358
	},
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   359
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   360
	error: function(xhr, status, error) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   361
          try {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   362
            if (xhr.status == 500) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   363
                var reason_dict = evalJSON(xhr.responseText);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   364
                d.error(xhr, status, reason_dict['reason']);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   365
                return;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   366
            }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   367
          } catch(exc) {
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   368
            log('error with server side error report:' + exc);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   369
          }
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   370
          d.error(xhr, status, null);
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   371
	}
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   372
    });
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   373
    return d;
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   374
}
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   375
f3c2cb460ad9 [doc] note on pytestconf, fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3096
diff changeset
   376
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
/** @id MochiKit.DateTime.toISOTime */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
toISOTime = function (date, realISO/* = false */) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
    if (typeof(date) == "undefined" || date === null) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
        return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
    var hh = date.getHours();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
    var mm = date.getMinutes();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
    var ss = date.getSeconds();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
    var lst = [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
        ((realISO && (hh < 10)) ? "0" + hh : hh),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
        ((mm < 10) ? "0" + mm : mm),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
        ((ss < 10) ? "0" + ss : ss)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
    ];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
    return lst.join(":");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
};
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
_padTwo = function (n) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
    return (n > 9) ? n : "0" + n;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
};
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   397
/** @id MochiKit.DateTime.toISODate */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
toISODate = function (date) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
    if (typeof(date) == "undefined" || date === null) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
        return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
    return [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        date.getFullYear(),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
        _padTwo(date.getMonth() + 1),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
        _padTwo(date.getDate())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
    ].join("-");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
};
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
/** @id MochiKit.DateTime.toISOTimeStamp */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
toISOTimestamp = function (date, realISO/* = false*/) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   412
    if (typeof(date) == "undefined" || date === null) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
        return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    var sep = realISO ? "T" : " ";
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    var foot = realISO ? "Z" : "";
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
    if (realISO) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
        date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
    return toISODate(date) + sep + toISOTime(date, realISO) + foot;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   421
};
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
/* depth-first implementation of the nodeWalk function found
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   426
 * in MochiKit.Base
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
 * cf. http://mochikit.com/doc/html/MochiKit/Base.html#fn-nodewalk
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
function nodeWalkDepthFirst(node, visitor) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
    var children = visitor(node);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
    if (children) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   432
	for(var i=0; i<children.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
	    nodeWalkDepthFirst(children[i], visitor);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
/* Returns true if all the given Array-like or string arguments are not empty (obj.length > 0) */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
function isNotEmpty(obj) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   441
    for (var i = 0; i < arguments.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        var o = arguments[i];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
        if (!(o && o.length)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
            return false;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   445
        }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
    return true;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
/** this implementation comes from MochiKit  */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   451
function formContents(elem/* = document.body */) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
    var names = [];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
    var values = [];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
    if (typeof(elem) == "undefined" || elem === null) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
        elem = document.body;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   456
    } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   457
        elem = getNode(elem);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   458
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   459
    nodeWalkDepthFirst(elem, function (elem) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
        var name = elem.name;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   461
        if (isNotEmpty(name)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   462
            var tagName = elem.tagName.toUpperCase();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
            if (tagName === "INPUT"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
                && (elem.type == "radio" || elem.type == "checkbox")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   465
                && !elem.checked
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   466
               ) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   467
                return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   468
            }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   469
            if (tagName === "SELECT") {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   470
                if (elem.type == "select-one") {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
                    if (elem.selectedIndex >= 0) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
                        var opt = elem.options[elem.selectedIndex];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   473
                        var v = opt.value;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
                        if (!v) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
                            var h = opt.outerHTML;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
                            // internet explorer sure does suck.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
                            if (h && !h.match(/^[^>]+\svalue\s*=/i)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
                                v = opt.text;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
                            }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
                        }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
                        names.push(name);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
                        values.push(v);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
                        return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
                    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
                    // no form elements?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
                    names.push(name);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
                    values.push("");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
                    return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   489
                } else {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
                    var opts = elem.options;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
                    if (!opts.length) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
                        names.push(name);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
                        values.push("");
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
                        return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
                    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
                    for (var i = 0; i < opts.length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
                        var opt = opts[i];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
                        if (!opt.selected) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
                            continue;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
                        }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
                        var v = opt.value;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
                        if (!v) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
                            var h = opt.outerHTML;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
                            // internet explorer sure does suck.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
                            if (h && !h.match(/^[^>]+\svalue\s*=/i)) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
                                v = opt.text;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
                            }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
                        }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
                        names.push(name);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
                        values.push(v);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
                    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
                    return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   513
                }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   514
            }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   515
            if (tagName === "FORM" || tagName === "P" || tagName === "SPAN"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
                || tagName === "DIV"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   517
               ) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
                return elem.childNodes;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
            }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
            names.push(name);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   521
            values.push(elem.value || '');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   522
            return null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   523
        }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   524
        return elem.childNodes;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   525
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   526
    return [names, values];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   527
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   528
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   529
function merge(array1, array2) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   530
    var result = [];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   531
    for (var i=0,length=arguments.length; i<length; i++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   532
	var array = arguments[i];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   533
	for (var j=0,alength=array.length; j<alength; j++) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   534
	    result.push(array[j]);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   535
	}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   536
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   537
    return result;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   538
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   539
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   540
var KEYS = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   541
    KEY_ESC: 27,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   542
    KEY_ENTER: 13
1563
b130c6cec8c2 loadJSON -> loadRemote, correctly handle json
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1419
diff changeset
   543
};
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   544
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   545
1563
b130c6cec8c2 loadJSON -> loadRemote, correctly handle json
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1419
diff changeset
   546