1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/**
* Horde tooltips javascript.
*
* @copyright 2014 Horde LLC
* @license LGPL-2.1 (http://www.horde.org/licenses/lgpl21)
*/
var Horde_ToolTips =
{
// Vars used and defaulting to null: attached, timeout
attachBehavior: function()
{
if (!this.attached) {
document.on('mouseover', 'a[nicetitle]', this.onMouseover.bindAsEventListener(this));
document.on('mouseout', 'a[nicetitle]', this.out.bind(this));
document.on('focus', 'a[nicetitle]', this.onFocus.bindAsEventListener(this));
document.on('blur', 'a[nicetitle]', this.out.bind(this));
this.attached = true;
}
},
onMouseover: function(e)
{
this.onOver(e, [ e.pointerX(), e.pointerY() ]);
},
onFocus: function(e)
{
this.onOver(e, e.element().cumulativeOffset());
},
onOver: function(e, p)
{
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = this.show.bind(this, e, p).delay(0.3);
},
out: function()
{
var t = $('toolTip');
if (this.timeout) {
clearTimeout(this.timeout);
}
if (t) {
t.hide();
}
},
show: function(e, pos)
{
var left, w,
d = $('toolTip'),
s_offset = document.viewport.getScrollOffsets(),
v_dimens = document.viewport.getDimensions();
if (d) {
this.out();
}
if (!d) {
d = new Element('DIV', {
id: 'toolTip', className: 'nicetitle'
}).hide();
$(document.body).insert(d);
}
d.update('<pre>' + e.element().readAttribute('nicetitle').evalJSON(true).invoke('toString').invoke('escapeHTML').join("<br>") + '</pre>');
// Make sure all of the tooltip is visible.
left = pos[0] + 10;
w = d.getWidth();
if ((left + w) > (v_dimens.width + s_offset.left)) {
left = v_dimens.width - w - 40 + s_offset.left;
}
if (document.body.scrollWidth && ((left + w) > (document.body.scrollWidth + s_offset.left))) {
left = document.body.scrollWidth - w - 25 + s_offset.left;
}
d.setStyle({
left: Math.max(left, 5) + 'px',
top: (pos[1] + 10) + 'px'
}).show();
}
};
if (typeof Horde_ToolTips_Autoload == 'undefined' || !Horde_ToolTips_Autoload) {
document.observe('dom:loaded', Horde_ToolTips.attachBehavior.bind(Horde_ToolTips));
}
|