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