~jetsaredim/firefox-extensions/firebug.upstream

« back to all changes in this revision

Viewing changes to content/firebug/tests/.svn/text-base/outlines.js.svn-base

  • Committer: Jared Greenwald
  • Date: 2008-04-22 18:20:42 UTC
  • Revision ID: jgreenwa@4lom-20080422182042-90kbumm805h2hjt6
 * new upstream source (v1.2~b21+svn572)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// *************************************************************************************************
2
 
//   Copyright (C) Joe Hewitt.                                                All Rights Reserved.
3
 
// *************************************************************************************************
4
 
 
5
 
const edgeSize = 2;
6
 
 
7
 
var highlighter = null;
8
 
var highlightBody = null;
9
 
 
10
 
function highlight(element)
11
 
{    
12
 
    if (!element)
13
 
    {
14
 
        if (highlightBody)
15
 
        {
16
 
            for (var edge in highlighter)
17
 
                highlightBody.removeChild(highlighter[edge]);
18
 
        
19
 
            highlightBody = null;
20
 
        }
21
 
    }
22
 
    else
23
 
    {
24
 
        var offset = getClientOffset(element);
25
 
        var w = element.offsetWidth;
26
 
        var h = element.offsetHeight;
27
 
 
28
 
        //element.className = "highlighted";
29
 
 
30
 
        highlightRect(element.ownerDocument,
31
 
                offset.x, offset.y, element.offsetWidth, element.offsetHeight,
32
 
                edgeSize, 4, 6, 1);
33
 
    }
34
 
}
35
 
 
36
 
function highlightRect(doc, x, y, w, h, t, r, b, l)
37
 
{
38
 
    var highlighter = getHighlighter();
39
 
    move(highlighter.top, x, y-t);
40
 
    size(highlighter.top, w, t);
41
 
    
42
 
    move(highlighter.right, x+w, y-t);
43
 
    size(highlighter.right, r, h+t+b);
44
 
 
45
 
    move(highlighter.bottom, x, y+h);
46
 
    size(highlighter.bottom, w, b);
47
 
 
48
 
    move(highlighter.left, x-l, y-t);
49
 
    size(highlighter.left, l, h+t+b);
50
 
 
51
 
    highlightBody = doc.body;
52
 
    
53
 
    for (var edge in highlighter)
54
 
        highlightBody.appendChild(highlighter[edge]);
55
 
}
56
 
 
57
 
function getHighlighter()
58
 
{
59
 
    if (!highlighter)
60
 
    {
61
 
        function createEdge(name)
62
 
        {
63
 
            var div = document.createElement("div");
64
 
            div.className = "highlighterEdge highlighter"+name;
65
 
            
66
 
            return div;
67
 
        }
68
 
        
69
 
        highlighter = 
70
 
        {
71
 
            top: createEdge("Top"),
72
 
            right: createEdge("Right"),
73
 
            bottom: createEdge("Bottom"),
74
 
            left: createEdge("Left"),
75
 
        };
76
 
    }
77
 
    
78
 
    return highlighter;
79
 
}
80
 
 
81
 
function getClientOffset(elt)
82
 
{
83
 
    function addOffset(elt, coords, addStyle, view)
84
 
    {
85
 
        if (addStyle)
86
 
        {
87
 
            var style = view.getComputedStyle(elt, null);
88
 
            if (style.position != "absolute")
89
 
            {
90
 
                coords.x += parseInt(style.marginLeft) + parseInt(style.borderLeftWidth);
91
 
                coords.y += parseInt(style.marginTop) + parseInt(style.borderTopWidth);
92
 
            }
93
 
        }
94
 
        
95
 
        if (elt.offsetLeft)
96
 
            coords.x += elt.offsetLeft;
97
 
        if (elt.offsetTop)
98
 
            coords.y += elt.offsetTop;
99
 
        
100
 
        if (elt.offsetParent && elt.parentNode.nodeType == 1)
101
 
            addOffset(elt.offsetParent, coords, false, view);
102
 
    }
103
 
    
104
 
    var coords = {x: 0, y: 0};
105
 
    if (elt)
106
 
        addOffset(elt, coords, false, elt.ownerDocument.defaultView);
107
 
    return coords;
108
 
}
109
 
 
110
 
function ddd() { console.log.apply(console, arguments); }