Ox.Element: don't overwrite callbacks; reformatting
This commit is contained in:
parent
3636a3fe98
commit
b9e4f565ca
1 changed files with 23 additions and 45 deletions
|
@ -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('<tagname>')
|
||||
// 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 = $('<div>');
|
||||
}
|
||||
// allow for Ox.TestElement('<tagname>') or Ox.TestElement('cssSelector')
|
||||
self.options = Ox.isString(options) ? {element: options} : options || {};
|
||||
// the actual event handler
|
||||
self.$eventHandler = self.$eventHandler || $('<div>');
|
||||
// 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 || '<div>'))
|
||||
.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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue