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 adminbar = $('#wpadminbar'), refresh, touchOpen, touchClose, disableHoverIntent = false;
9 refresh = function(i, el){ // force the browser to refresh the tabbing index
10 var node = $(el), tab = node.attr('tabindex');
12 node.attr('tabindex', '0').attr('tabindex', tab);
15 touchOpen = function(unbind) {
16 adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) {
19 if ( !el.hasClass('hover') ) {
21 adminbar.find('li.menupop.hover').removeClass('hover');
26 $('li.menupop').off('click.wp-mobile-hover');
27 disableHoverIntent = false;
32 touchClose = function() {
33 var mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
34 // close any open drop-downs when the click/touch is not on the toolbar
35 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
36 if ( !$(e.target).closest('#wpadminbar').length )
37 adminbar.find('li.menupop.hover').removeClass('hover');
41 adminbar.removeClass('nojq').removeClass('nojs');
43 if ( 'ontouchstart' in window ) {
44 adminbar.on('touchstart', function(){
46 disableHoverIntent = true;
49 } else if ( /IEMobile\/[1-9]/.test(navigator.userAgent) ) {
54 adminbar.find('li.menupop').hoverIntent({
56 if ( disableHoverIntent )
59 $(this).addClass('hover');
62 if ( disableHoverIntent )
65 $(this).removeClass('hover');
72 if ( window.location.hash )
73 window.scrollBy( 0, -32 );
75 $('#wp-admin-bar-get-shortlink').click(function(e){
77 $(this).addClass('selected').children('.shortlink-input').blur(function(){
78 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected');
82 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
86 var target = $(e.target), wrap = target.closest('ab-sub-wrapper');
92 wrap = $('#wpadminbar .quicklinks');
94 wrap.find('.menupop').removeClass('hover');
95 target.parent().toggleClass('hover');
96 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
99 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
103 var target = $(e.target);
108 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
109 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
112 $('#wpadminbar').click( function(e) {
113 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' )
117 $('html, body').animate({ scrollTop: 0 }, 'fast');
120 // fix focus bug in WebKit
121 $('.screen-reader-shortcut').keydown( function(e) {
125 var id = $(this).attr('href');
127 if ( $.browser.webkit && id && id.charAt(0) == '#' ) {
128 setTimeout(function () {
136 var addEvent = function( obj, type, fn ) {
137 if ( obj.addEventListener )
138 obj.addEventListener(type, fn, false);
139 else if ( obj.attachEvent )
140 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
143 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
144 rselected = new RegExp('\\bselected\\b', 'g'),
147 * Get the timeout ID of the given element
149 getTOID = function(el) {
152 if ( q[i] && el == q[i][1] )
158 addHoverClass = function(t) {
159 var i, id, inA, hovering, ul, li,
163 while ( t && t != aB && t != d ) {
164 if ( 'LI' == t.nodeName.toUpperCase() ) {
165 ancestors[ ancestors.length ] = t;
169 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
175 // Remove any selected classes.
176 if ( hovering && hovering.parentNode ) {
177 ul = hovering.parentNode;
178 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
179 i = ul.childNodes.length;
181 li = ul.childNodes[i];
182 if ( li != hovering )
183 li.className = li.className ? li.className.replace( rselected, '' ) : '';
188 /* remove the hover class for any objects not in the immediate element's ancestry */
192 ancestorLength = ancestors.length;
193 while( ancestorLength-- ) {
194 if ( ancestors[ ancestorLength ] == q[i][1] )
199 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
203 removeHoverClass = function(t) {
204 while ( t && t != aB && t != d ) {
205 if ( 'LI' == t.nodeName.toUpperCase() ) {
207 var to = setTimeout(function() {
208 t.className = t.className ? t.className.replace(hc, '') : '';
210 q[q.length] = [to, t];
217 clickShortlink = function(e) {
219 t = e.target || e.srcElement;
221 // Make t the shortlink menu item, or return.
223 // Check if we've gone past the shortlink node,
224 // or if the user is clicking on the input.
225 if ( ! t || t == d || t == aB )
227 // Check if we've found the shortlink node.
228 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
233 // IE doesn't support preventDefault, and does support returnValue
234 if ( e.preventDefault )
236 e.returnValue = false;
238 if ( -1 == t.className.indexOf('selected') )
239 t.className += ' selected';
241 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
242 node = t.childNodes[i];
243 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
246 node.onblur = function() {
247 t.className = t.className ? t.className.replace( rselected, '' ) : '';
255 scrollToTop = function(t) {
256 var distance, speed, step, steps, timer, speed_step;
258 // Ensure that the #wpadminbar was the target of the click.
259 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
262 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
267 speed_step = distance > 800 ? 130 : 100;
268 speed = Math.min( 12, Math.round( distance / speed_step ) );
269 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
273 // Animate scrolling to the top of the page by generating steps to
274 // the top of the page and shifting to each step at a set interval.
279 steps.push( distance );
281 setTimeout( function() {
282 window.scrollTo( 0, steps.shift() );
289 addEvent(w, 'load', function() {
290 aB = d.getElementById('wpadminbar');
292 if ( d.body && aB ) {
293 d.body.appendChild( aB );
296 aB.className = aB.className.replace(/nojs/, '');
298 addEvent(aB, 'mouseover', function(e) {
299 addHoverClass( e.target || e.srcElement );
302 addEvent(aB, 'mouseout', function(e) {
303 removeHoverClass( e.target || e.srcElement );
306 addEvent(aB, 'click', clickShortlink );
308 addEvent(aB, 'click', function(e) {
309 scrollToTop( e.target || e.srcElement );
313 if ( w.location.hash )
316 })(document, window);