forked from 0x2620/oxjs
fix Ox.JQueryElement fixmes
This commit is contained in:
parent
b9e80c9d75
commit
33390069b9
6 changed files with 26 additions and 33 deletions
|
|
@ -8,43 +8,30 @@ Ox.JQueryElement <f> Wrapper for jQuery
|
|||
Ox.JQueryElement = function($element) {
|
||||
var that = this;
|
||||
//@ id <number> Unique id
|
||||
that.id = Ox.uid(); // fixme: rename to oxid!
|
||||
//@ ox <string> OxJS version
|
||||
that.ox = Ox.VERSION; // fixme: remove!
|
||||
that.oxid = Ox.uid();
|
||||
//@ $element <object> The jQuery-wrapped DOM element
|
||||
that.$element = $element.data({
|
||||
oxid: that.id
|
||||
oxid: that.oxid
|
||||
});
|
||||
// FIXME: the following two lines should make it possible to do
|
||||
// $('<div>').appendTo($element) ... check if it works, then replace all
|
||||
//@ 0 <element> The DOM element
|
||||
that[0] = that.$element[0];
|
||||
//@ length <number> 1 (for compatibility with jQuery)
|
||||
that.length = 1;
|
||||
Ox.UI.elements[that.id] = that;
|
||||
Ox.UI.elements[that.oxid] = that;
|
||||
return that;
|
||||
};
|
||||
|
||||
// add all jQuery functions to the prototype of Ox.JQueryElement
|
||||
Ox.methods($('<div>'), true).forEach(function(method) {
|
||||
Ox.JQueryElement.prototype[method] = function() {
|
||||
var args = arguments, id, ret, that = this;
|
||||
Ox.forEach(args, function(arg, i) {
|
||||
// FIXME: with the changes above, is this still needed?
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
var args = arguments, oxid, ret, that = this;
|
||||
ret = that.$element[method].apply(that.$element, args);
|
||||
// if exactly one $element of an ox object was returned
|
||||
// then return the ox object instead
|
||||
// so that we can do oxObj.jqFn().oxFn()
|
||||
return ret && ret.jquery
|
||||
&& ret.length == 1
|
||||
&& Ox.UI.elements[id = ret.data('oxid')]
|
||||
? Ox.UI.elements[id] : ret;
|
||||
&& Ox.UI.elements[oxid = ret.data('oxid')]
|
||||
? Ox.UI.elements[oxid] : ret;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue