Introduction
Introduction Statistics Contact Development Disclaimer Help
tooltipxhr.js - jscancer - Javascript crap (relatively small)
git clone git://git.codemadness.org/jscancer
Log
Files
Refs
README
LICENSE
---
tooltipxhr.js (2430B)
---
1 (function() {
2 var open = false, timershow;
3 var el = document.createElement("div");
4 el.style.display = "none";
5 el.className = "tooltip";
6 document.body.appendChild(el);
7
8 var position = function(x, y) {
9 // position optimally, try to adjust when outside window.
10 if (y + el.offsetHeight + 32 > window.innerHeight)
11 el.style.top = String(y - el.offsetHeight - 18) …
12 else
13 el.style.top = String(y + 18) + "px"; // + space…
14 // NOTE, this is a mess: document.body.clientWidth exclu…
15 // window.innerWidth is the window including scroll…
16 // window.outerWidth is the window including scroll…
17 if (x + el.offsetWidth >= document.body.parentNode.offse…
18 el.style.right = "0px";
19 el.style.left = "auto";
20 } else {
21 el.style.left = String(x) + "px";
22 el.style.right = "auto";
23 }
24 };
25 document.addEventListener("keyup", function(e) {
26 // close on escape key.
27 if (e.which === 27) {
28 open = false;
29 el.style.display = "none";
30 clearTimeout(timershow);
31 }
32 });
33 // don't close if mouse over popup or it's children.
34 document.addEventListener("mouseover", function(e) {
35 for (var p = e.target; !!p.parentNode; p = p.parentNode)
36 if (p === el)
37 return;
38 open = false;
39 el.style.display = "none";
40 clearTimeout(timershow);
41 return !!e.stopPropagation();
42 }, false);
43 document.addEventListener("mousemove", function(e) {
44 if (open)
45 return position(e.clientX, e.clientY);
46 clearTimeout(timershow);
47 timershow = setTimeout((function(target, x, y) {
48 return function() {
49 var uri = null;
50 for (var p = target; !!p.parentNode; p =…
51 if ((uri = p.getAttribute("data-…
52 break;
53 if (uri === null)
54 return;
55
56 var xhr = new(XMLHttpRequest);
57 xhr.open("GET", uri + ((uri.indexOf("?")…
58 xhr.setRequestHeader("X-Requested-With",…
59 xhr.onreadystatechange = function() {
60 if (xhr.readyState != 4 || [ 0, …
61 return;
62 el.innerHTML = xhr.responseText …
63 el.style.display = "block";
64 open = true;
65 position(x, y);
66 };
67 xhr.timeout = 10000;
68 xhr.overrideMimeType("text/html");
69 xhr.send();
70 };
71 })(e.target, e.clientX, e.clientY), 500);
72 return !!e.stopPropagation();
73 }, false);
74 })();
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.