2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-05 18:02:56 +00:00
|
|
|
/*@
|
|
|
|
Ox.JQueryElement <function> Wrapper for jQuery
|
|
|
|
($element) -> <object> Wrapped jQuery DOM element
|
|
|
|
$element <object> jQuery DOM Element
|
|
|
|
@*/
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2011-12-29 10:10:08 +00:00
|
|
|
// fixme: now that children(), find() work, change code to call find directly.
|
2011-05-27 09:15:55 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.JQueryElement = function($element) {
|
|
|
|
var that = this;
|
2011-05-07 17:52:33 +00:00
|
|
|
//@ id <number> Unique id
|
2011-11-02 08:22:55 +00:00
|
|
|
that.id = Ox.uid(); // fixme: rename to oxid!
|
2011-05-07 17:52:33 +00:00
|
|
|
//@ ox <string> OxJS version
|
2011-11-02 08:22:55 +00:00
|
|
|
that.ox = Ox.VERSION; // fixme: remove!
|
2011-08-23 21:31:08 +00:00
|
|
|
//@ $element <object> The jQuery-wrapped DOM element
|
2011-04-22 22:03:10 +00:00
|
|
|
that.$element = $element.data({
|
2011-11-02 00:46:42 +00:00
|
|
|
oxid: that.id
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
2011-08-23 19:08:08 +00:00
|
|
|
// FIXME: the following two lines should make it possible to do
|
|
|
|
// $('<div>').appendTo($element) ... check if it works, then replace all
|
2011-08-23 21:31:08 +00:00
|
|
|
//@ 0 <element> The DOM element
|
2011-08-23 19:08:08 +00:00
|
|
|
that[0] = that.$element[0];
|
2011-08-23 21:31:08 +00:00
|
|
|
//@ length <number> 1 (for compatibility with jQuery)
|
2011-08-23 19:08:08 +00:00
|
|
|
that.length = 1;
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.UI.elements[that.id] = that;
|
|
|
|
return that;
|
|
|
|
};
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2011-05-05 18:02:56 +00:00
|
|
|
// add all jQuery functions to the prototype of Ox.JQueryElement
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.forEach($('<div>'), function(val, key) {
|
|
|
|
if (Ox.isFunction(val)) {
|
|
|
|
Ox.JQueryElement.prototype[key] = function() {
|
|
|
|
var args = arguments, id, ret, that = this;
|
|
|
|
Ox.forEach(args, function(arg, i) {
|
2011-08-23 21:31:08 +00:00
|
|
|
// FIXME: with the changes above, is this still needed?
|
2011-04-22 22:03:10 +00:00
|
|
|
// if an ox object was passed
|
|
|
|
// then pass its $element instead
|
|
|
|
// so that we can do oxObj.jqFn(oxObj)
|
|
|
|
if (arg && arg.ox) {
|
|
|
|
args[i] = arg.$element;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ret = that.$element[key].apply(that.$element, args);
|
2011-12-29 10:10:08 +00:00
|
|
|
// if exactly one $element of an ox object was returned
|
2011-04-22 22:03:10 +00:00
|
|
|
// then return the ox object instead
|
|
|
|
// so that we can do oxObj.jqFn().oxFn()
|
2011-12-29 10:10:08 +00:00
|
|
|
return ret && ret.jquery
|
|
|
|
&& ret.length == 1
|
|
|
|
&& Ox.UI.elements[id = ret.data('oxid')]
|
2011-11-01 23:14:29 +00:00
|
|
|
? Ox.UI.elements[id] : ret;
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|
|
|
|
}
|
2011-09-03 13:18:20 +00:00
|
|
|
}, true);
|