1 // use jQuery and hoverIntent if loaded
2 if ( typeof(jQuery) != 'undefined' ) {
3 if ( typeof(jQuery.fn.hoverIntent) == 'undefined' )
4 (function(a){a.fn.hoverIntent=function(l,j){var m={sensitivity:7,interval:100,timeout:0};m=a.extend(m,j?{over:l,out:j}:l);var o,n,h,d;var e=function(f){o=f.pageX;n=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-o)+Math.abs(d-n))<m.sensitivity){a(f).unbind("mousemove",e);f.hoverIntent_s=1;return m.over.apply(f,[g])}else{h=o;d=n;f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return m.out.apply(f,[g])};var b=function(q){var f=this;var g=(q.type=="mouseover"?q.fromElement:q.toElement)||q.relatedTarget;while(g&&g!=this){try{g=g.parentNode}catch(q){g=this}}if(g==this){if(a.browser.mozilla){if(q.type=="mouseout"){f.mtout=setTimeout(function(){k(q,f)},30)}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}}}return}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}k(q,f)}};var k=function(p,f){var g=jQuery.extend({},p);if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(p.type=="mouseover"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},m.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery);
6 jQuery(document).ready(function($){
7 var refresh = function(i, el){ // force the browser to refresh the tabbing index
8 var node = $(el), tab = node.attr('tabindex');
10 node.attr('tabindex', '0').attr('tabindex', tab);
13 $('#wpadminbar').removeClass('nojq').removeClass('nojs').find('li.menupop').hoverIntent({
15 $(this).addClass('hover');
18 $(this).removeClass('hover');
25 $('#wp-admin-bar-get-shortlink').click(function(e){
27 $(this).addClass('selected').children('.shortlink-input').blur(function(){
28 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected');
32 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
36 var target = $(e.target), wrap = target.closest('ab-sub-wrapper');
42 wrap = $('#wpadminbar .quicklinks');
44 wrap.find('.menupop').removeClass('hover');
45 target.parent().toggleClass('hover');
46 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
49 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
53 var target = $(e.target);
58 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
59 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
62 $('#wpadminbar').click( function(e) {
63 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' )
67 $('html, body').animate({ scrollTop: 0 }, 'fast');
73 var addEvent = function( obj, type, fn ) {
74 if (obj.addEventListener)
75 obj.addEventListener(type, fn, false);
76 else if (obj.attachEvent)
77 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
80 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
81 rselected = new RegExp('\\bselected\\b', 'g'),
84 * Get the timeout ID of the given element
86 getTOID = function(el) {
89 if ( q[i] && el == q[i][1] )
94 addHoverClass = function(t) {
95 var i, id, inA, hovering, ul, li,
99 while ( t && t != aB && t != d ) {
100 if( 'LI' == t.nodeName.toUpperCase() ) {
101 ancestors[ ancestors.length ] = t;
105 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
111 // Remove any selected classes.
112 if ( hovering && hovering.parentNode ) {
113 ul = hovering.parentNode;
114 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
115 i = ul.childNodes.length;
117 li = ul.childNodes[i];
118 if ( li != hovering )
119 li.className = li.className ? li.className.replace( rselected, '' ) : '';
124 /* remove the hover class for any objects not in the immediate element's ancestry */
128 ancestorLength = ancestors.length;
129 while( ancestorLength-- ) {
130 if ( ancestors[ ancestorLength ] == q[i][1] )
135 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
139 removeHoverClass = function(t) {
140 while ( t && t != aB && t != d ) {
141 if( 'LI' == t.nodeName.toUpperCase() ) {
143 var to = setTimeout(function() {
144 t.className = t.className ? t.className.replace(hc, '') : '';
146 q[q.length] = [to, t];
153 clickShortlink = function(e) {
155 t = e.target || e.srcElement;
157 // Make t the shortlink menu item, or return.
159 // Check if we've gone past the shortlink node,
160 // or if the user is clicking on the input.
161 if ( ! t || t == d || t == aB )
163 // Check if we've found the shortlink node.
164 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
169 // IE doesn't support preventDefault, and does support returnValue
170 if ( e.preventDefault )
172 e.returnValue = false;
174 if ( -1 == t.className.indexOf('selected') )
175 t.className += ' selected';
177 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
178 node = t.childNodes[i];
179 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
182 node.onblur = function() {
183 t.className = t.className ? t.className.replace( rselected, '' ) : '';
191 scrollToTop = function(t) {
192 var distance, speed, step, steps, timer, speed_step;
194 // Ensure that the #wpadminbar was the target of the click.
195 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
198 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
203 speed_step = distance > 800 ? 130 : 100;
204 speed = Math.min( 12, Math.round( distance / speed_step ) );
205 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
209 // Animate scrolling to the top of the page by generating steps to
210 // the top of the page and shifting to each step at a set interval.
215 steps.push( distance );
217 setTimeout( function() {
218 window.scrollTo( 0, steps.shift() );
225 addEvent(w, 'load', function() {
226 aB = d.getElementById('wpadminbar');
228 if ( d.body && aB ) {
229 d.body.appendChild( aB );
232 aB.className = aB.className.replace(/nojs/, '');
234 addEvent(aB, 'mouseover', function(e) {
235 addHoverClass( e.target || e.srcElement );
238 addEvent(aB, 'mouseout', function(e) {
239 removeHoverClass( e.target || e.srcElement );
242 addEvent(aB, 'click', clickShortlink );
244 addEvent(aB, 'click', function(e) {
245 scrollToTop( e.target || e.srcElement );
249 if ( w.location.hash )
252 })(document, window);