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.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.PATH = Ox.PATH + 'Ox.UI/';
Ox.UI.SCROLLBAR_SIZE = $.browser.mozilla ? 16 : 12; Ox.UI.SCROLLBAR_SIZE = $.browser.mozilla ? 16 : 12;
// fixme: the follwing should be deprecated // fixme: the follwing should be deprecated

View file

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

View file

@ -8,43 +8,30 @@ Ox.JQueryElement <f> Wrapper for jQuery
Ox.JQueryElement = function($element) { Ox.JQueryElement = function($element) {
var that = this; var that = this;
//@ id <number> Unique id //@ id <number> Unique id
that.id = Ox.uid(); // fixme: rename to oxid! that.oxid = Ox.uid();
//@ ox <string> OxJS version
that.ox = Ox.VERSION; // fixme: remove!
//@ $element <object> The jQuery-wrapped DOM element //@ $element <object> The jQuery-wrapped DOM element
that.$element = $element.data({ 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 //@ 0 <element> The DOM element
that[0] = that.$element[0]; that[0] = that.$element[0];
//@ length <number> 1 (for compatibility with jQuery) //@ length <number> 1 (for compatibility with jQuery)
that.length = 1; that.length = 1;
Ox.UI.elements[that.id] = that; Ox.UI.elements[that.oxid] = that;
return that; return that;
}; };
// add all jQuery functions to the prototype of Ox.JQueryElement // add all jQuery functions to the prototype of Ox.JQueryElement
Ox.methods($('<div>'), true).forEach(function(method) { Ox.methods($('<div>'), true).forEach(function(method) {
Ox.JQueryElement.prototype[method] = function() { Ox.JQueryElement.prototype[method] = function() {
var args = arguments, id, ret, that = this; var args = arguments, oxid, 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;
}
});
ret = that.$element[method].apply(that.$element, args); ret = that.$element[method].apply(that.$element, args);
// if exactly one $element of an ox object was returned // if exactly one $element of an ox object was returned
// then return the ox object instead // then return the ox object instead
// so that we can do oxObj.jqFn().oxFn() // so that we can do oxObj.jqFn().oxFn()
return ret && ret.jquery return ret && ret.jquery
&& ret.length == 1 && ret.length == 1
&& Ox.UI.elements[id = ret.data('oxid')] && Ox.UI.elements[oxid = ret.data('oxid')]
? Ox.UI.elements[id] : ret; ? Ox.UI.elements[oxid] : ret;
}; };
}); });

View file

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

View file

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

View file

@ -518,7 +518,7 @@ Ox.Dialog = function(options, self) {
function setContent() { function setContent() {
var animate = !!self.$content, 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) { if (animate) {
self.$content.animate({ self.$content.animate({
opacity: 0 opacity: 0