~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/js/admin-bar.dev.js

  • Committer: Andrew Glen-Young
  • Date: 2011-03-08 14:47:51 UTC
  • Revision ID: andrew.glen-young@canonical.com-20110308144751-1n6spqgayztf9h77
[AGY] import 3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function(d, w) {
 
2
        var addEvent = function( obj, type, fn ) {
 
3
                if (obj.addEventListener)
 
4
                        obj.addEventListener(type, fn, false);
 
5
                else if (obj.attachEvent)
 
6
                        obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
 
7
        },
 
8
 
 
9
        aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
 
10
        rselected = new RegExp('\\bselected\\b', 'g'),
 
11
 
 
12
        /**
 
13
         * Get the timeout ID of the given element
 
14
         */
 
15
        getTOID = function(el) {
 
16
                var i = q.length;
 
17
                while( i-- )
 
18
                        if ( q[i] && el == q[i][1] )
 
19
                                return q[i][0];
 
20
                return false;
 
21
        },
 
22
 
 
23
        addHoverClass = function(t) {
 
24
                var i, id, inA, hovering, ul, li,
 
25
                        ancestors = [],
 
26
                        ancestorLength = 0;
 
27
 
 
28
                while ( t && t != aB && t != d ) {
 
29
                        if( 'LI' == t.nodeName.toUpperCase() ) {
 
30
                                ancestors[ ancestors.length ] = t;
 
31
                                id = getTOID(t);
 
32
                                if ( id )
 
33
                                        clearTimeout( id );
 
34
                                t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
 
35
                                hovering = t;
 
36
                        }
 
37
                        t = t.parentNode;
 
38
                }
 
39
 
 
40
                // Remove any selected classes.
 
41
                if ( hovering && hovering.parentNode ) {
 
42
                        ul = hovering.parentNode;
 
43
                        if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
 
44
                                i = ul.childNodes.length;
 
45
                                while ( i-- ) {
 
46
                                        li = ul.childNodes[i];
 
47
                                        if ( li != hovering )
 
48
                                                li.className = li.className ? li.className.replace( rselected, '' ) : '';
 
49
                                }
 
50
                        }
 
51
                }
 
52
 
 
53
                /* remove the hover class for any objects not in the immediate element's ancestry */
 
54
                i = q.length;
 
55
                while ( i-- ) {
 
56
                        inA = false;
 
57
                        ancestorLength = ancestors.length;
 
58
                        while( ancestorLength-- ) {
 
59
                                if ( ancestors[ ancestorLength ] == q[i][1] )
 
60
                                        inA = true;
 
61
                        }
 
62
 
 
63
                        if ( ! inA )
 
64
                                q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
 
65
                }
 
66
        },
 
67
 
 
68
        removeHoverClass = function(t) {
 
69
                while ( t && t != aB && t != d ) {
 
70
                        if( 'LI' == t.nodeName.toUpperCase() ) {
 
71
                                (function(t) {
 
72
                                        var to = setTimeout(function() {
 
73
                                                t.className = t.className ? t.className.replace(hc, '') : '';
 
74
                                        }, 500);
 
75
                                        q[q.length] = [to, t];
 
76
                                })(t);
 
77
                        }
 
78
                        t = t.parentNode;
 
79
                }
 
80
        },
 
81
 
 
82
        clickShortlink = function(e) {
 
83
                var i, l, node,
 
84
                        t = e.target || e.srcElement;
 
85
 
 
86
                // Make t the shortlink menu item, or return.
 
87
                while ( true ) {
 
88
                        // Check if we've gone past the shortlink node,
 
89
                        // or if the user is clicking on the input.
 
90
                        if ( ! t || t == d || t == aB )
 
91
                                return;
 
92
                        // Check if we've found the shortlink node.
 
93
                        if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
 
94
                                break;
 
95
                        t = t.parentNode;
 
96
                }
 
97
 
 
98
                // IE doesn't support preventDefault, and does support returnValue
 
99
                if ( e.preventDefault )
 
100
                        e.preventDefault();
 
101
                e.returnValue = false;
 
102
 
 
103
                if ( -1 == t.className.indexOf('selected') )
 
104
                        t.className += ' selected';
 
105
 
 
106
                for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
 
107
                        node = t.childNodes[i];
 
108
                        if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
 
109
                                node.focus();
 
110
                                node.select();
 
111
                                node.onblur = function() {
 
112
                                        t.className = t.className ? t.className.replace( rselected, '' ) : '';
 
113
                                };
 
114
                                break;
 
115
                        }
 
116
                }
 
117
                return false;
 
118
        };
 
119
 
 
120
        addEvent(w, 'load', function() {
 
121
                aB = d.getElementById('wpadminbar');
 
122
 
 
123
                if ( d.body && aB ) {
 
124
                        d.body.appendChild( aB );
 
125
 
 
126
                        addEvent(aB, 'mouseover', function(e) {
 
127
                                addHoverClass( e.target || e.srcElement );
 
128
                        });
 
129
 
 
130
                        addEvent(aB, 'mouseout', function(e) {
 
131
                                removeHoverClass( e.target || e.srcElement );
 
132
                        });
 
133
 
 
134
                        addEvent(aB, 'click', clickShortlink );
 
135
                }
 
136
 
 
137
                if ( w.location.hash )
 
138
                        w.scrollBy(0,-32);
 
139
        });
 
140
})(document, window);