diff -r f4d1d5d9ccbb -r 90f2f20367bc web/data/cubicweb.compat.js --- a/web/data/cubicweb.compat.js Tue Jul 27 12:36:03 2010 +0200 +++ b/web/data/cubicweb.compat.js Wed Nov 03 16:38:28 2010 +0100 @@ -1,546 +1,103 @@ -/* MochiKit -> jQuery compatibility module */ - -function forEach(array, func) { - for (var i=0, length=array.length; i>> y = ['a:b:c', 'd:e'] - >>> jQuery.map(y, function(y) { return y.split(':');}) - ["a", "b", "c", "d", "e"] - // where one would expect: - [ ["a", "b", "c"], ["d", "e"] ] - XXX why not the same argument order as $.map and forEach ? -*/ -function map(func, array) { - var result = []; - for (var i=0, length=array.length; - i'); - } catch (ex) { - var node = document.createElement('iframe'); - node.id = node.name = params.name; +// ========== END OF ARRAY EXTENSIONS ========== /// +forEach = cw.utils.deprecatedFunction( + '[3.9] forEach() is deprecated, use $.each() instead', + function(array, func) { + return $.each(array, func); } - } - else{ - var node = document.createElement('iframe'); - } - for (key in params) { - if (key != 'name'){ - var value = params[key]; - if (key.substring(0, 2) == 'on') { - // this is an event handler definition - if (typeof value == 'string') { - // litteral definition - value = new Function(value); - } - node[key] = value; - } else { // normal node attribute - node.setAttribute(key, params[key]); - } - } - } - return node; -} - +); -// dummy ultra minimalist implementation on deferred for jQuery -function Deferred() { - this.__init__(this); -} - -jQuery.extend(Deferred.prototype, { - __init__: function() { - this._onSuccess = []; - this._onFailure = []; - this._req = null; - this._result = null; - this._error = null; - }, - - addCallback: function(callback) { - if (this._req.readyState == 4) { - if (this._result) { callback.apply(null, this._result, this._req); } - } - else { this._onSuccess.push([callback, sliceList(arguments, 1)]); } - return this; - }, - - addErrback: function(callback) { - if (this._req.readyState == 4) { - if (this._error) { callback.apply(null, this._error, this._req); } +/** + * .. function:: cw.utils.deprecatedFunction(msg, function) + * + * jQUery flattens arrays returned by the mapping function: + * >>> y = ['a:b:c', 'd:e'] + * >>> jQuery.map(y, function(y) { return y.split(':');}) + * ["a", "b", "c", "d", "e"] + * // where one would expect: + * [ ["a", "b", "c"], ["d", "e"] ] + * XXX why not the same argument order as $.map and forEach ? + */ +map = cw.utils.deprecatedFunction( + '[3.9] map() is deprecated, use $.map instead', + function(func, array) { + var result = []; + for (var i = 0, length = array.length; i < length; i++) { + result.push(func(array[i])); } - else { this._onFailure.push([callback, sliceList(arguments, 1)]); } - return this; - }, - - success: function(result) { - this._result = result; - try { - for (var i=0; i 9) ? n : "0" + n; -}; - -/** @id MochiKit.DateTime.toISODate */ -toISODate = function (date) { - if (typeof(date) == "undefined" || date === null) { - return null; +findValue = cw.utils.deprecatedFunction( + '[3.9] findValue(array, elt) is deprecated, use $.inArray(elt, array) instead', + function(array, element) { + return jQuery.inArray(element, array); } - return [ - date.getFullYear(), - _padTwo(date.getMonth() + 1), - _padTwo(date.getDate()) - ].join("-"); -}; - - -/** @id MochiKit.DateTime.toISOTimeStamp */ -toISOTimestamp = function (date, realISO/* = false*/) { - if (typeof(date) == "undefined" || date === null) { - return null; - } - var sep = realISO ? "T" : " "; - var foot = realISO ? "Z" : ""; - if (realISO) { - date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000)); - } - return toISODate(date) + sep + toISOTime(date, realISO) + foot; -}; - - +); -/* depth-first implementation of the nodeWalk function found - * in MochiKit.Base - * cf. http://mochikit.com/doc/html/MochiKit/Base.html#fn-nodewalk - */ -function nodeWalkDepthFirst(node, visitor) { - var children = visitor(node); - if (children) { - for(var i=0; i 0) */ -function isNotEmpty(obj) { - for (var i = 0; i < arguments.length; i++) { - var o = arguments[i]; - if (!(o && o.length)) { - return false; - } +addElementClass = cw.utils.deprecatedFunction( + '[3.9] addElementClass(node, cls) is depcreated, use $(node).addClass(cls) instead', + function(node, klass) { + $(node).addClass(klass); } - return true; -} +); -/** this implementation comes from MochiKit */ -function formContents(elem/* = document.body */) { - var names = []; - var values = []; - if (typeof(elem) == "undefined" || elem === null) { - elem = document.body; - } else { - elem = getNode(elem); +removeElementClass = cw.utils.deprecatedFunction( + '[3.9] removeElementClass(node, cls) is depcreated, use $(node).removeClass(cls) instead', + function(node, klass) { + $(node).removeClass(klass); + } +); + +hasElementClass = cw.utils.deprecatedFunction( + '[3.9] hasElementClass(node, cls) is depcreated, use $.className.has(node, cls)', + function(node, klass) { + return $.className.has(node, klass); } - nodeWalkDepthFirst(elem, function (elem) { - var name = elem.name; - if (isNotEmpty(name)) { - var tagName = elem.tagName.toUpperCase(); - if (tagName === "INPUT" - && (elem.type == "radio" || elem.type == "checkbox") - && !elem.checked - ) { - return null; - } - if (tagName === "SELECT") { - if (elem.type == "select-one") { - if (elem.selectedIndex >= 0) { - var opt = elem.options[elem.selectedIndex]; - var v = opt.value; - if (!v) { - var h = opt.outerHTML; - // internet explorer sure does suck. - if (h && !h.match(/^[^>]+\svalue\s*=/i)) { - v = opt.text; - } - } - names.push(name); - values.push(v); - return null; - } - // no form elements? - names.push(name); - values.push(""); - return null; - } else { - var opts = elem.options; - if (!opts.length) { - names.push(name); - values.push(""); - return null; - } - for (var i = 0; i < opts.length; i++) { - var opt = opts[i]; - if (!opt.selected) { - continue; - } - var v = opt.value; - if (!v) { - var h = opt.outerHTML; - // internet explorer sure does suck. - if (h && !h.match(/^[^>]+\svalue\s*=/i)) { - v = opt.text; - } - } - names.push(name); - values.push(v); - } - return null; - } - } - if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" - || tagName === "DIV" - ) { - return elem.childNodes; - } - names.push(name); - values.push(elem.value || ''); - return null; - } - return elem.childNodes; - }); - return [names, values]; -} +); -function merge(array1, array2) { - var result = []; - for (var i=0,length=arguments.length; i