forked from 0x2620/oxjs
Create tooltip only on mouseenter
This commit is contained in:
parent
37d9424ec8
commit
120a9eda41
3 changed files with 39 additions and 14 deletions
|
|
@ -90,6 +90,8 @@ Ox.Element = function(options, self) {
|
|||
// stack of callbacks bound to option updates
|
||||
self.updateCallbacks = self.updateCallbacks || [];
|
||||
|
||||
self.boundTooltipEvents = {};
|
||||
|
||||
// create public object
|
||||
var that = new Ox.JQueryElement($(self.options.element || '<div>'))
|
||||
.addClass('OxElement')
|
||||
|
|
@ -104,6 +106,14 @@ Ox.Element = function(options, self) {
|
|||
|
||||
setTooltip();
|
||||
|
||||
function bindTooltipEvents(events) {
|
||||
that.off(Ox.filter(self.boundTooltipEvents, function(value, key) {
|
||||
return !events[key];
|
||||
})).on(self.boundTooltipEvents = Ox.filter(events, function(value, key) {
|
||||
return !self.boundTooltipEvents[key];
|
||||
}));
|
||||
}
|
||||
|
||||
function mousedown(e) {
|
||||
/*
|
||||
better mouse events
|
||||
|
|
@ -216,11 +226,14 @@ Ox.Element = function(options, self) {
|
|||
}
|
||||
|
||||
function mouseenter(e) {
|
||||
if (!that.$tooltip) {
|
||||
that.$tooltip = Ox.Tooltip({title: self.options.tooltip});
|
||||
}
|
||||
that.$tooltip.show(e);
|
||||
}
|
||||
|
||||
function mouseleave(e) {
|
||||
that.$tooltip.hide();
|
||||
that.$tooltip && that.$tooltip.hide();
|
||||
}
|
||||
|
||||
function mousemove(e) {
|
||||
|
|
@ -266,22 +279,26 @@ Ox.Element = function(options, self) {
|
|||
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});
|
||||
bindTooltipEvents({
|
||||
mouseenter: mouseenter,
|
||||
mouseleave: mouseleave
|
||||
});
|
||||
that.$tooltip && that.$tooltip.options({
|
||||
title: self.options.tooltip,
|
||||
animate: true
|
||||
});
|
||||
} else {
|
||||
that.$tooltip = Ox.Tooltip({animate: false});
|
||||
that.on({mousemove: mousemove}).off({mouseenter: mouseenter});
|
||||
}
|
||||
that.on({mouseleave: mouseleave});
|
||||
} else {
|
||||
if (that.$tooltip) {
|
||||
that.$tooltip.remove();
|
||||
that.off({
|
||||
mouseenter: mouseenter,
|
||||
bindTooltipEvents({
|
||||
mousemove: mousemove,
|
||||
mouseleave: mouseleave
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (that.$tooltip) {
|
||||
that.$tooltip.remove();
|
||||
}
|
||||
bindTooltipEvents({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue