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);});
9 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
10 rselected = new RegExp('\\bselected\\b', 'g'),
13 * Get the timeout ID of the given element
15 getTOID = function(el) {
18 if ( q[i] && el == q[i][1] )
23 addHoverClass = function(t) {
24 var i, id, inA, hovering, ul, li,
28 while ( t && t != aB && t != d ) {
29 if( 'LI' == t.nodeName.toUpperCase() ) {
30 ancestors[ ancestors.length ] = t;
34 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
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;
46 li = ul.childNodes[i];
48 li.className = li.className ? li.className.replace( rselected, '' ) : '';
53 /* remove the hover class for any objects not in the immediate element's ancestry */
57 ancestorLength = ancestors.length;
58 while( ancestorLength-- ) {
59 if ( ancestors[ ancestorLength ] == q[i][1] )
64 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
68 removeHoverClass = function(t) {
69 while ( t && t != aB && t != d ) {
70 if( 'LI' == t.nodeName.toUpperCase() ) {
72 var to = setTimeout(function() {
73 t.className = t.className ? t.className.replace(hc, '') : '';
75 q[q.length] = [to, t];
82 clickShortlink = function(e) {
84 t = e.target || e.srcElement;
86 // Make t the shortlink menu item, or return.
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 )
92 // Check if we've found the shortlink node.
93 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
98 // IE doesn't support preventDefault, and does support returnValue
99 if ( e.preventDefault )
101 e.returnValue = false;
103 if ( -1 == t.className.indexOf('selected') )
104 t.className += ' selected';
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') ) {
111 node.onblur = function() {
112 t.className = t.className ? t.className.replace( rselected, '' ) : '';
120 addEvent(w, 'load', function() {
121 aB = d.getElementById('wpadminbar');
123 if ( d.body && aB ) {
124 d.body.appendChild( aB );
126 addEvent(aB, 'mouseover', function(e) {
127 addHoverClass( e.target || e.srcElement );
130 addEvent(aB, 'mouseout', function(e) {
131 removeHoverClass( e.target || e.srcElement );
134 addEvent(aB, 'click', clickShortlink );
137 if ( w.location.hash )
140 })(document, window);