oxjs/source/Ox.UI/js/Window/Ox.Tooltip.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-04-23 16:45:50 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=js
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) {
var self = self || {},
2011-04-29 12:40:51 +00:00
that = new Ox.Element({}, self)
2011-04-22 22:03:10 +00:00
.defaults({
animate: true,
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);
}
};
that.hide = function() {
if (self.options.animate) {
that.animate({
opacity: 0
}, 250, function() {
that.removeElement();
});
} else {
that.removeElement();
}
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
2011-04-22 22:03:10 +00:00
that.show = function(x, y) {
var left, top, width, height;
2011-05-14 19:32:49 +00:00
if (arguments.length == 1) {
y = arguments[0].clientY;
x = arguments[0].clientX;
}
2011-04-22 22:03:10 +00:00
$('.OxTooltip').remove(); // fixme: don't use DOM
that.appendTo(Ox.UI.$body);
width = that.width();
height = that.height();
left = Ox.limit(x - width / 2, 0, window.innerWidth - width);
top = y > window.innerHeight - height - 16 ? y - 16 - height : y + 16;
2011-04-22 22:03:10 +00:00
that.css({
left: left + 'px',
top: top + 'px'
});
self.options.animate && that.animate({
opacity: 1
}, 250);
return that;
};
return that;
};