1
// *************************************************************************************************
2
// Copyright (C) Joe Hewitt. All Rights Reserved.
3
// *************************************************************************************************
7
var highlighter = null;
8
var highlightBody = null;
10
function highlight(element)
16
for (var edge in highlighter)
17
highlightBody.removeChild(highlighter[edge]);
24
var offset = getClientOffset(element);
25
var w = element.offsetWidth;
26
var h = element.offsetHeight;
28
//element.className = "highlighted";
30
highlightRect(element.ownerDocument,
31
offset.x, offset.y, element.offsetWidth, element.offsetHeight,
36
function highlightRect(doc, x, y, w, h, t, r, b, l)
38
var highlighter = getHighlighter();
39
move(highlighter.top, x, y-t);
40
size(highlighter.top, w, t);
42
move(highlighter.right, x+w, y-t);
43
size(highlighter.right, r, h+t+b);
45
move(highlighter.bottom, x, y+h);
46
size(highlighter.bottom, w, b);
48
move(highlighter.left, x-l, y-t);
49
size(highlighter.left, l, h+t+b);
51
highlightBody = doc.body;
53
for (var edge in highlighter)
54
highlightBody.appendChild(highlighter[edge]);
57
function getHighlighter()
61
function createEdge(name)
63
var div = document.createElement("div");
64
div.className = "highlighterEdge highlighter"+name;
71
top: createEdge("Top"),
72
right: createEdge("Right"),
73
bottom: createEdge("Bottom"),
74
left: createEdge("Left"),
81
function getClientOffset(elt)
83
function addOffset(elt, coords, addStyle, view)
87
var style = view.getComputedStyle(elt, null);
88
if (style.position != "absolute")
90
coords.x += parseInt(style.marginLeft) + parseInt(style.borderLeftWidth);
91
coords.y += parseInt(style.marginTop) + parseInt(style.borderTopWidth);
96
coords.x += elt.offsetLeft;
98
coords.y += elt.offsetTop;
100
if (elt.offsetParent && elt.parentNode.nodeType == 1)
101
addOffset(elt.offsetParent, coords, false, view);
104
var coords = {x: 0, y: 0};
106
addOffset(elt, coords, false, elt.ownerDocument.defaultView);
110
function ddd() { console.log.apply(console, arguments); }