diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index 7aef5dca..1fa00ea2 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -79,28 +79,23 @@ Ox.Element = function(options, self) { self = self || {}; // create defaults and options objects self.defaults = {}; - self.options = options || {}; - // allow for Ox.TestElement('') - // or Ox.TestElement('cssSelector') - if (Ox.isString(self.options)) { - self.options = { - element: self.options - }; - } - // create event handler - // (this can be passed as part of self) - if (!self.$eventHandler) { - self.$eventHandler = $('
'); - } + // allow for Ox.TestElement('') or Ox.TestElement('cssSelector') + self.options = Ox.isString(options) ? {element: options} : options || {}; + // the actual event handler + self.$eventHandler = self.$eventHandler || $('
'); // array of callbacks bound to any event - self.eventCallbacks = []; - // stack of callbacks bound to option updates - self.updateCallbacks = []; + self.eventCallbacks = self.eventCallbacks || []; + // stack of callbacks bound to any option update + self.updateCallbacks = self.updateCallbacks || []; // create public object var that = new Ox.JQueryElement($(self.options.element || '
')) - .addClass('OxElement') - .mousedown(mousedown); + .addClass('OxElement') + .mousedown(mousedown); + + that._leakSelf = function() { + return self; + } setTooltip(); @@ -195,7 +190,7 @@ Ox.Element = function(options, self) { self._mouseTimeout = 0; that.triggerEvent('doubleclick', e); } - Ox.UI.$window.one('mouseup', mouseup); + Ox.UI.$window.one({mouseup: mouseup}); function dragenter(e) { that.triggerEvent('dragenter', extend(e)); } @@ -238,38 +233,22 @@ Ox.Element = function(options, self) { } function mousemove(e) { - that.$tooltip.options({ - title: self.options.tooltip(e) - }).show(e); + that.$tooltip.options({title: self.options.tooltip(e)}).show(e); } - // FIXME: in other widgets, use this, + // TODO: in other widgets, use this, // rather than some self.$tooltip that // will not get garbage collected function setTooltip() { if (self.options.tooltip) { if (Ox.isString(self.options.tooltip)) { - that.$tooltip = Ox.Tooltip({ - title: self.options.tooltip - }); - that.on({ - mouseenter: mouseenter - }).off({ - mousemove: mousemove - }); + that.$tooltip = Ox.Tooltip({title: self.options.tooltip}); + that.on({mouseenter: mouseenter}).off({mousemove: mousemove}); } else { - that.$tooltip = Ox.Tooltip({ - animate: false - }); - that.on({ - mousemove: mousemove - }).off({ - mouseenter: mouseenter - }); + that.$tooltip = Ox.Tooltip({animate: false}); + that.on({mousemove: mousemove}).off({mouseenter: mouseenter}); } - that.on({ - mouseleave: mouseleave - }); + that.on({mouseleave: mouseleave}); } else { if (that.$tooltip) { that.$tooltip.remove(); @@ -455,6 +434,7 @@ Ox.Element = function(options, self) { that.triggerEvent = function() { Ox.forEach(Ox.makeObject(arguments), function(data, event) { var type = 'ox_' + event; + // FIXME: remove this if ([ 'mousedown', 'mouserepeat', 'anyclick', 'singleclick', 'doubleclick', 'dragstart', 'drag', 'dragenter', 'dragleave', 'dragpause', 'dragend', @@ -548,9 +528,7 @@ Ox.Element = function(options, self) { ); }; - that.update({ - tooltip: setTooltip - }); + that.update({tooltip: setTooltip}); return that;