2 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2008. All rights reserved
4 * Originally written by Nicolas Terray, 2008
6 * This file is a part of Codendi.
8 * Codendi is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Codendi is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Codendi; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 var codendi = codendi || { };
27 codendi.Tooltip = Class.create({
28 initialize: function(element, url, options) {
29 this.element = $(element);
31 this.options = Object.extend({
34 this.fetching = false;
36 this.old_title = this.element.title;
40 this.showEvent = this.show.bindAsEventListener(this);
41 this.element.observe('mouseover', this.showEvent);
42 this.hideEvent = this.hide.bindAsEventListener(this);
43 this.element.observe('mouseout', this.hideEvent);
48 this.element.title = '';
49 new Ajax.Request(this.url, {
50 onSuccess:(function(transport) {
51 this.fetching = false;
53 if (transport.responseText) {
54 this.createTooltip(transport.responseText);
55 if (this.show_tooltip) {
59 this.element.title = this.old_title;
65 createTooltip: function(content) {
66 this.tooltip = new Element('div', {
67 'class': "codendi-tooltip",
68 style: "display:none;"
70 this.tooltip.update(content);
71 Element.insert(document.body, {
76 this.show_tooltip = true;
78 clearTimeout(this.timeout);
81 var pos = this.element.cumulativeOffset();
82 Element.setStyle(this.tooltip, {
83 top: (pos[1] + this.element.offsetHeight)+"px",
92 } else if (!this.fetched) {
97 this.show_tooltip = false;
99 this.timeout = setTimeout((function() {
101 }).bindAsEventListener(this), 200);
106 codendi.Tooltips = [];
108 document.observe('dom:loaded', function() {
109 $$('a[class=cross-reference]').each(function (a) {
110 codendi.Tooltips.push(new codendi.Tooltip(a, a.href));