2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-05 18:02:56 +00:00
|
|
|
/*@
|
2012-05-22 13:14:40 +00:00
|
|
|
Ox.JQueryElement <f> Wrapper for jQuery
|
2011-05-05 18:02:56 +00:00
|
|
|
($element) -> <object> Wrapped jQuery DOM element
|
|
|
|
$element <object> jQuery DOM Element
|
|
|
|
@*/
|
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
|
2012-05-22 14:08:09 +00:00
|
|
|
that.oxid = Ox.uid();
|
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({
|
2012-05-22 14:08:09 +00:00
|
|
|
oxid: that.oxid
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
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;
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.UI.elements[that.oxid] = that;
|
2011-04-22 22:03:10 +00:00
|
|
|
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
|
2012-05-21 20:07:40 +00:00
|
|
|
Ox.methods($('<div>'), true).forEach(function(method) {
|
|
|
|
Ox.JQueryElement.prototype[method] = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
var args = arguments, oxid, ret, that = this;
|
2012-05-21 20:07:40 +00:00
|
|
|
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
|
2012-05-22 14:08:09 +00:00
|
|
|
&& Ox.UI.elements[oxid = ret.data('oxid')]
|
|
|
|
? Ox.UI.elements[oxid] : ret;
|
2012-05-21 20:07:40 +00:00
|
|
|
};
|
2012-05-22 13:14:40 +00:00
|
|
|
});
|