fix Ox.JQueryElement fixmes

This commit is contained in:
j 2012-05-22 16:08:09 +02:00
parent b9e80c9d75
commit 33390069b9
6 changed files with 26 additions and 33 deletions

View file

@ -354,6 +354,13 @@ Ox.load.UI = function(options, callback) {
});
};
Ox.UI.IMAGE_CACHE = [];
/*@
Ox.UI.isElement <f> check if object is an Ox.Element
(obj) -> <b> true if object is an Ox.Element
@*/
Ox.UI.isElement = function(obj) {
return Ox.isObject(obj) && 'oxid' in obj;
};
Ox.UI.PATH = Ox.PATH + 'Ox.UI/';
Ox.UI.SCROLLBAR_SIZE = $.browser.mozilla ? 16 : 12;
// fixme: the follwing should be deprecated

View file

@ -324,7 +324,7 @@ Ox.Element = function(options, self) {
() -> <o> object
@*/
that.bindKeyboard = function() {
Ox.Keyboard.bind(that.id);
Ox.Keyboard.bind(that.oxid);
return that;
};
@ -353,7 +353,7 @@ Ox.Element = function(options, self) {
() -> <obj> This element object
@*/
that.gainFocus = function() {
Ox.Focus.focus(that.id);
Ox.Focus.focus(that.oxid);
return that;
};
@ -362,7 +362,7 @@ Ox.Element = function(options, self) {
() -> <boolean> True if the element has focus
@*/
that.hasFocus = function() {
return Ox.Focus.focused() == that.id;
return Ox.Focus.focused() == that.oxid;
};
/*@
@ -370,7 +370,7 @@ Ox.Element = function(options, self) {
() -> <object> This element object
@*/
that.loseFocus = function() {
Ox.Focus.blur(that.id);
Ox.Focus.blur(that.oxid);
return that;
};
@ -403,10 +403,10 @@ Ox.Element = function(options, self) {
element = Ox.UI.elements[oxid];
element && element.remove(false);
});
Ox.Focus.remove(that.id);
Ox.Keyboard.unbind(that.id);
Ox.Focus.remove(that.oxid);
Ox.Keyboard.unbind(that.oxid);
delete self.$eventHandler;
delete Ox.UI.elements[that.id];
delete Ox.UI.elements[that.oxid];
that.$tooltip && that.$tooltip.remove();
remove !== false && that.$element.remove();
return that;
@ -417,8 +417,7 @@ Ox.Element = function(options, self) {
($element) -> null
@*/
that.setElement = function($element) {
//$element[0].className = that.$element[0].className;
$element.addClass('OxElement').data({oxid: that.id});
$element.addClass('OxElement').data({oxid: that.oxid});
that.$element.replaceWith($element);
that.$element = $element;
that[0] = that.$element[0];
@ -453,7 +452,7 @@ Ox.Element = function(options, self) {
'playing', 'position', 'progress', 'request'
].indexOf(event) == -1) {
if (!/^pandora_/.test(event)) {
Ox.Log('EVENT', that.id, self.options.id, 'trigger', event, data);
Ox.Log('EVENT', that.oxid, self.options.id, 'trigger', event, data);
}
}
// it is necessary to check if self.$eventHandler exists,
@ -495,7 +494,7 @@ Ox.Element = function(options, self) {
() -> <o> object
@*/
that.unbindKeyboard = function() {
Ox.Keyboard.unbind(that.id);
Ox.Keyboard.unbind(that.oxid);
return that;
};

View file

@ -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;
};
});

View file

@ -722,7 +722,7 @@ Ox.Input = function(options, self) {
var input = self.$input[0];
that.triggerEvent('insert', {
end: input.selectionEnd,
id: that.id,
id: that.oxid,
selection: input.value.substring(input.selectionStart, input.selectionEnd),
start: input.selectionStart,
value: input.value

View file

@ -783,7 +783,7 @@ Ox.List = function(options, self) {
!Ox.isUndefined(callback) && callback();
return;
}
Ox.Log('List', that.id, 'loadPage', page);
Ox.Log('List', that.oxid, 'loadPage', page);
var keys = Ox.merge(
self.options.keys.indexOf(self.options.unique) == -1
? [self.options.unique] : [], self.options.keys

View file

@ -518,7 +518,7 @@ Ox.Dialog = function(options, self) {
function setContent() {
var animate = !!self.$content,
isImage = !self.options.content.ox && self.options.content.is('img');
isImage = !Ox.UI.isElement(self.options.content) && self.options.content.is('img');
if (animate) {
self.$content.animate({
opacity: 0