comparison geotemco/lib/slider/local/helptip.js @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 /*
2 * This script was created by Erik Arvidsson (erik(at)eae.net)
3 * for WebFX (http://webfx.eae.net)
4 * Copyright 2001
5 *
6 * For usage see license at http://webfx.eae.net/license.html
7 *
8 * Version: 1.0
9 * Created: 2001-09-27
10 * Updated: 2001-11-25 Added a resize to the tooltip if the document width is too small
11 *
12 * Dependencies: helptip.css (To set up the CSS of the help-tooltip class)
13 *
14 * Usage:
15 *
16 * <script type="text/javascript" src="helptip.js"></script>
17 * <link type="text/css" rel="StyleSheet" href="helptip.css" />
18 *
19 * <a class="helpLink" href="?" onclick="showHelp(event, 'String to show'); return false">Help</a>
20 *
21 */
22
23 function showHelpTip(e, s) {
24 // find anchor element
25 var el = e.target ? e.target : e.srcElement;
26 while (el.tagName != "A")
27 el = el.parentNode;
28
29 // is there already a tooltip? If so, remove it
30 if (el._helpTip) {
31 document.body.removeChild(el._helpTip);
32 el._helpTip = null;
33 el.onblur = null;
34 return;
35 }
36
37 // create element and insert last into the body
38 var d = document.createElement("DIV");
39 d.className = "help-tooltip";
40 document.body.appendChild(d);
41 d.innerHTML = s;
42
43 // Allow clicks on A elements inside tooltip
44 d.onmousedown = function (e) {
45 if (!e) e = event;
46 var t = e.target ? e.target : e.srcElement;
47 while (t.tagName != "A" && t != d)
48 t = t.parentNode;
49 if (t == d) return;
50
51 el._onblur = el.onblur;
52 el.onblur = null;
53 };
54 d.onmouseup = function () {
55 el.onblur = el._onblur;
56 el.focus();
57 };
58
59 // position tooltip
60 var dw = document.width ? document.width : document.documentElement.offsetWidth - 25;
61
62 if (d.offsetWidth >= dw)
63 d.style.width = dw - 10 + "px";
64 else
65 d.style.width = "";
66
67 var scroll = getScroll();
68 if (e.clientX > dw - d.offsetWidth)
69 d.style.left = dw - d.offsetWidth + scroll.x + "px";
70 else
71 d.style.left = e.clientX - 2 + scroll.x + "px";
72 d.style.top = e.clientY + 18 + scroll.y + "px";
73
74 // add a listener to the blur event. When blurred remove tooltip and restore anchor
75 el.onblur = function () {
76 document.body.removeChild(d);
77 el.onblur = null;
78 el._helpTip = null;
79 };
80
81 // store a reference to the tooltip div
82 el._helpTip = d;
83 }
84
85 // returns the scroll left and top for the browser viewport.
86 function getScroll() {
87 if (document.all && document.body.scrollTop != undefined) { // IE model
88 var ieBox = document.compatMode != "CSS1Compat";
89 var cont = ieBox ? document.body : document.documentElement;
90 return {x : cont.scrollLeft, y : cont.scrollTop};
91 }
92 else {
93 return {x : window.pageXOffset, y : window.pageYOffset};
94 }
95 }