2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
Ox.Tooltip <f:Ox.Element> Tooltip Object
|
|
|
|
() -> <f> Tooltip Object
|
|
|
|
(options) -> <f> Tooltip Object
|
|
|
|
(options, self) -> <f> Tooltip Object
|
|
|
|
options <o> Options object
|
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.Tooltip = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
2011-08-28 06:23:15 +00:00
|
|
|
animate: true, // fixme: shouldn't booleans be false by default?
|
2011-04-22 22:03:10 +00:00
|
|
|
title: ''
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
.addClass('OxTooltip')
|
|
|
|
.html(self.options.title);
|
|
|
|
|
|
|
|
self.options.animate && that.css({
|
|
|
|
opacity: 0
|
|
|
|
});
|
|
|
|
|
2011-04-29 12:40:51 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-04-22 22:03:10 +00:00
|
|
|
if (key == 'title') {
|
|
|
|
that.html(value);
|
2011-11-06 12:26:12 +00:00
|
|
|
value === '' && that.detach();
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
hide <f> hide tooltip
|
|
|
|
() -> <o> hide tooltip
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.hide = function() {
|
2012-04-23 08:29:37 +00:00
|
|
|
var last = Ox.last(arguments);
|
2011-08-28 19:50:06 +00:00
|
|
|
if (self.options.title) {
|
|
|
|
if (self.options.animate) {
|
|
|
|
that.animate({
|
|
|
|
opacity: 0
|
|
|
|
}, 250, function() {
|
2011-11-03 13:59:54 +00:00
|
|
|
that.detach();
|
2012-04-23 08:29:37 +00:00
|
|
|
Ox.isFunction(last) && last();
|
2011-08-28 19:50:06 +00:00
|
|
|
});
|
|
|
|
} else {
|
2011-11-03 13:59:54 +00:00
|
|
|
that.detach();
|
2011-08-28 19:50:06 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-05-14 19:32:49 +00:00
|
|
|
// can pass event instead of x/y
|
2011-05-17 18:44:53 +00:00
|
|
|
// fixme: use this in widgets
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
show <f> show tooltip
|
|
|
|
(x, y) -> <o> show tooltip at x,y
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.show = function(x, y) {
|
2012-04-23 08:29:37 +00:00
|
|
|
var last = Ox.last(arguments),
|
|
|
|
left, top, width, height;
|
2011-08-28 19:50:06 +00:00
|
|
|
if (self.options.title) {
|
2012-04-23 08:29:37 +00:00
|
|
|
if (Ox.isObject(arguments[0])) {
|
2011-09-03 23:04:18 +00:00
|
|
|
self.x = arguments[0].clientX;
|
|
|
|
self.y = arguments[0].clientY;
|
2012-04-23 08:29:37 +00:00
|
|
|
} else {
|
2011-09-03 23:04:18 +00:00
|
|
|
self.x = x;
|
|
|
|
self.y = y
|
2011-08-28 19:50:06 +00:00
|
|
|
}
|
2011-11-03 13:59:54 +00:00
|
|
|
$('.OxTooltip').detach(); // fixme: don't use DOM
|
2011-08-28 19:50:06 +00:00
|
|
|
that.appendTo(Ox.UI.$body);
|
|
|
|
width = that.width();
|
|
|
|
height = that.height();
|
2011-09-03 23:04:18 +00:00
|
|
|
left = Ox.limit(
|
2012-04-24 08:19:05 +00:00
|
|
|
self.x - Math.round(width / 2), 0, window.innerWidth - width - 8
|
2011-09-03 23:04:18 +00:00
|
|
|
);
|
|
|
|
top = self.y > window.innerHeight - height - 16
|
|
|
|
? self.y - 16 - height
|
|
|
|
: self.y + 16;
|
2011-08-28 19:50:06 +00:00
|
|
|
that.css({
|
|
|
|
left: left + 'px',
|
|
|
|
top: top + 'px'
|
|
|
|
});
|
|
|
|
self.options.animate && that.animate({
|
|
|
|
opacity: 1
|
2012-04-23 08:29:37 +00:00
|
|
|
}, 250, function() {
|
|
|
|
Ox.isFunction(last) && last();
|
|
|
|
});
|
2011-05-14 19:32:49 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|