4988 |
kaklik |
1 |
// Find all tags that match <a class="blame-revision" ...> and add events. |
|
|
2 |
var a = document.getElementsByTagName('a'); |
|
|
3 |
for (var i = 0; i < a.length; i++) { |
|
|
4 |
if (a[i].className == 'blame-revision') { |
|
|
5 |
addEvent(a[i], 'mouseover', function() { mouseover(this) } ); |
|
|
6 |
addEvent(a[i], 'mouseout', function() { mouseout(this) } ); |
|
|
7 |
} |
|
|
8 |
} |
|
|
9 |
|
|
|
10 |
function addEvent(obj, type, func) { |
|
|
11 |
if (obj.addEventListener) { |
|
|
12 |
obj.addEventListener(type, func, false); |
|
|
13 |
return true; |
|
|
14 |
} else if (obj.attachEvent) { |
|
|
15 |
return obj.attachEvent('on'+type, func); |
|
|
16 |
} else { |
|
|
17 |
return false; |
|
|
18 |
} |
|
|
19 |
} |
|
|
20 |
|
|
|
21 |
function mouseover(a) { |
|
|
22 |
// Find the revision number within the hyperlink text |
|
|
23 |
var m = /rev=(\d+)/.exec(a.href); |
|
|
24 |
var r = m[1]; |
|
|
25 |
if (rev[r]) { |
|
|
26 |
var div = document.createElement('div'); |
|
|
27 |
div.className = 'blame-popup'; |
|
|
28 |
div.innerHTML = rev[r]; |
|
|
29 |
a.parentNode.appendChild(div); |
|
|
30 |
} |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
function mouseout(a) { |
|
|
34 |
var div = a.parentNode.parentNode.getElementsByTagName('div'); |
|
|
35 |
for (var i = 0; i < div.length; i++) { |
|
|
36 |
if (div[i].className = 'blame-popup') { |
|
|
37 |
div[i].parentNode.removeChild(div[i]); |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
} |