2010-10-29 03:25:58 -04:00
|
|
|
(function(d, w) {
|
|
|
|
var addEvent = function( obj, type, fn ) {
|
|
|
|
if (obj.addEventListener)
|
|
|
|
obj.addEventListener(type, fn, false);
|
|
|
|
else if (obj.attachEvent)
|
|
|
|
obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
|
|
|
|
},
|
|
|
|
|
|
|
|
aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
|
2011-01-11 17:45:14 -05:00
|
|
|
rselected = new RegExp('\\bselected\\b', 'g'),
|
2010-10-29 03:25:58 -04:00
|
|
|
|
2010-11-10 11:19:55 -05:00
|
|
|
/**
|
|
|
|
* Get the timeout ID of the given element
|
|
|
|
*/
|
2010-10-29 03:25:58 -04:00
|
|
|
getTOID = function(el) {
|
|
|
|
var i = q.length;
|
|
|
|
while( i-- )
|
|
|
|
if ( q[i] && el == q[i][1] )
|
|
|
|
return q[i][0];
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-01-11 17:45:14 -05:00
|
|
|
addHoverClass = function(t) {
|
|
|
|
var i, id, inA, hovering, ul, li,
|
|
|
|
ancestors = [],
|
|
|
|
ancestorLength = 0;
|
|
|
|
|
2010-10-29 03:25:58 -04:00
|
|
|
while ( t && t != aB && t != d ) {
|
|
|
|
if( 'LI' == t.nodeName.toUpperCase() ) {
|
2010-11-10 11:19:55 -05:00
|
|
|
ancestors[ ancestors.length ] = t;
|
2010-12-10 13:47:21 -05:00
|
|
|
id = getTOID(t);
|
2010-10-29 03:25:58 -04:00
|
|
|
if ( id )
|
|
|
|
clearTimeout( id );
|
|
|
|
t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
|
2011-01-11 17:45:14 -05:00
|
|
|
hovering = t;
|
2010-10-29 03:25:58 -04:00
|
|
|
}
|
|
|
|
t = t.parentNode;
|
|
|
|
}
|
2010-12-10 13:47:21 -05:00
|
|
|
|
2011-01-11 17:45:14 -05:00
|
|
|
// Remove any selected classes.
|
2011-01-12 01:11:18 -05:00
|
|
|
if ( hovering && hovering.parentNode ) {
|
2011-01-11 19:32:00 -05:00
|
|
|
ul = hovering.parentNode;
|
|
|
|
if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
|
|
|
|
i = ul.childNodes.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
li = ul.childNodes[i];
|
|
|
|
if ( li != hovering )
|
|
|
|
li.className = li.className ? li.className.replace( rselected, '' ) : '';
|
|
|
|
}
|
2011-01-11 17:45:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 11:19:55 -05:00
|
|
|
/* remove the hover class for any objects not in the immediate element's ancestry */
|
2011-01-11 17:45:14 -05:00
|
|
|
i = q.length;
|
2010-11-10 11:19:55 -05:00
|
|
|
while ( i-- ) {
|
2011-02-09 12:35:36 -05:00
|
|
|
inA = false;
|
2010-11-10 11:19:55 -05:00
|
|
|
ancestorLength = ancestors.length;
|
|
|
|
while( ancestorLength-- ) {
|
2011-02-09 12:35:36 -05:00
|
|
|
if ( ancestors[ ancestorLength ] == q[i][1] )
|
|
|
|
inA = true;
|
2010-11-10 11:19:55 -05:00
|
|
|
}
|
2010-12-10 13:47:21 -05:00
|
|
|
|
|
|
|
if ( ! inA )
|
2010-11-10 11:19:55 -05:00
|
|
|
q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
|
|
|
|
}
|
2010-10-29 03:25:58 -04:00
|
|
|
},
|
|
|
|
|
2011-01-11 17:45:14 -05:00
|
|
|
removeHoverClass = function(t) {
|
2010-10-29 03:25:58 -04:00
|
|
|
while ( t && t != aB && t != d ) {
|
|
|
|
if( 'LI' == t.nodeName.toUpperCase() ) {
|
|
|
|
(function(t) {
|
|
|
|
var to = setTimeout(function() {
|
|
|
|
t.className = t.className ? t.className.replace(hc, '') : '';
|
|
|
|
}, 500);
|
|
|
|
q[q.length] = [to, t];
|
|
|
|
})(t);
|
|
|
|
}
|
|
|
|
t = t.parentNode;
|
|
|
|
}
|
2010-10-29 09:27:52 -04:00
|
|
|
},
|
2010-10-29 03:25:58 -04:00
|
|
|
|
|
|
|
clickShortlink = function(e) {
|
2011-01-11 19:32:00 -05:00
|
|
|
var i, l, node,
|
|
|
|
t = e.target || e.srcElement;
|
2011-01-11 17:45:14 -05:00
|
|
|
|
|
|
|
// Make t the shortlink menu item, or return.
|
|
|
|
while ( true ) {
|
|
|
|
// Check if we've gone past the shortlink node,
|
|
|
|
// or if the user is clicking on the input.
|
2011-01-11 19:32:00 -05:00
|
|
|
if ( ! t || t == d || t == aB )
|
2011-01-11 17:45:14 -05:00
|
|
|
return;
|
|
|
|
// Check if we've found the shortlink node.
|
2011-01-12 20:34:15 -05:00
|
|
|
if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
|
2011-01-11 17:45:14 -05:00
|
|
|
break;
|
2010-10-29 03:25:58 -04:00
|
|
|
t = t.parentNode;
|
2011-01-11 17:45:14 -05:00
|
|
|
}
|
2011-01-12 20:34:15 -05:00
|
|
|
|
|
|
|
// IE doesn't support preventDefault, and does support returnValue
|
2011-01-11 17:45:14 -05:00
|
|
|
if ( e.preventDefault )
|
|
|
|
e.preventDefault();
|
|
|
|
e.returnValue = false;
|
2011-01-12 20:34:15 -05:00
|
|
|
|
2011-01-11 17:45:14 -05:00
|
|
|
if ( -1 == t.className.indexOf('selected') )
|
|
|
|
t.className += ' selected';
|
|
|
|
|
|
|
|
for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
|
|
|
|
node = t.childNodes[i];
|
|
|
|
if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
|
|
|
|
node.focus();
|
|
|
|
node.select();
|
|
|
|
node.onblur = function() {
|
|
|
|
t.className = t.className ? t.className.replace( rselected, '' ) : '';
|
|
|
|
};
|
|
|
|
break;
|
2010-10-29 03:25:58 -04:00
|
|
|
}
|
|
|
|
}
|
2011-01-11 17:45:14 -05:00
|
|
|
return false;
|
|
|
|
};
|
2010-10-29 03:25:58 -04:00
|
|
|
|
|
|
|
addEvent(w, 'load', function() {
|
|
|
|
aB = d.getElementById('wpadminbar');
|
|
|
|
|
2011-01-11 17:45:14 -05:00
|
|
|
if ( d.body && aB ) {
|
|
|
|
d.body.appendChild( aB );
|
2010-10-29 03:25:58 -04:00
|
|
|
|
|
|
|
addEvent(aB, 'mouseover', function(e) {
|
2011-01-11 17:45:14 -05:00
|
|
|
addHoverClass( e.target || e.srcElement );
|
2010-10-29 03:25:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
addEvent(aB, 'mouseout', function(e) {
|
2011-01-11 17:45:14 -05:00
|
|
|
removeHoverClass( e.target || e.srcElement );
|
2010-10-29 03:25:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
addEvent(aB, 'click', clickShortlink );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( w.location.hash )
|
|
|
|
w.scrollBy(0,-32);
|
|
|
|
});
|
|
|
|
})(document, window);
|