1 /* jshint loopfunc: true */
2 // use jQuery and hoverIntent if loaded
3 if ( typeof(jQuery) != 'undefined' ) {
4 if ( typeof(jQuery.fn.hoverIntent) == 'undefined' ) {
5 /* jshint ignore:start */
6 // hoverIntent v1.8.1 - Copy of wp-includes/js/hoverIntent.min.js
7 !function(a){a.fn.hoverIntent=function(b,c,d){var e={interval:100,sensitivity:6,timeout:0};e="object"==typeof b?a.extend(e,b):a.isFunction(c)?a.extend(e,{over:b,out:c,selector:d}):a.extend(e,{over:b,out:b,selector:c});var f,g,h,i,j=function(a){f=a.pageX,g=a.pageY},k=function(b,c){return c.hoverIntent_t=clearTimeout(c.hoverIntent_t),Math.sqrt((h-f)*(h-f)+(i-g)*(i-g))<e.sensitivity?(a(c).off("mousemove.hoverIntent",j),c.hoverIntent_s=!0,e.over.apply(c,[b])):(h=f,i=g,c.hoverIntent_t=setTimeout(function(){k(b,c)},e.interval),void 0)},l=function(a,b){return b.hoverIntent_t=clearTimeout(b.hoverIntent_t),b.hoverIntent_s=!1,e.out.apply(b,[a])},m=function(b){var c=a.extend({},b),d=this;d.hoverIntent_t&&(d.hoverIntent_t=clearTimeout(d.hoverIntent_t)),"mouseenter"===b.type?(h=c.pageX,i=c.pageY,a(d).on("mousemove.hoverIntent",j),d.hoverIntent_s||(d.hoverIntent_t=setTimeout(function(){k(c,d)},e.interval))):(a(d).off("mousemove.hoverIntent",j),d.hoverIntent_s&&(d.hoverIntent_t=setTimeout(function(){l(c,d)},e.timeout)))};return this.on({"mouseenter.hoverIntent":m,"mouseleave.hoverIntent":m},e.selector)}}(jQuery);
8 /* jshint ignore:end */
10 jQuery(document).ready(function($){
11 var adminbar = $('#wpadminbar'), refresh, touchOpen, touchClose, disableHoverIntent = false;
13 refresh = function(i, el){ // force the browser to refresh the tabbing index
14 var node = $(el), tab = node.attr('tabindex');
16 node.attr('tabindex', '0').attr('tabindex', tab);
19 touchOpen = function(unbind) {
20 adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) {
23 if ( el.parent().is('#wp-admin-bar-root-default') && !el.hasClass('hover') ) {
25 adminbar.find('li.menupop.hover').removeClass('hover');
27 } else if ( !el.hasClass('hover') ) {
34 $('li.menupop').off('click.wp-mobile-hover');
35 disableHoverIntent = false;
40 touchClose = function() {
41 var mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
42 // close any open drop-downs when the click/touch is not on the toolbar
43 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
44 if ( !$(e.target).closest('#wpadminbar').length )
45 adminbar.find('li.menupop.hover').removeClass('hover');
49 adminbar.removeClass('nojq').removeClass('nojs');
51 if ( 'ontouchstart' in window ) {
52 adminbar.on('touchstart', function(){
54 disableHoverIntent = true;
57 } else if ( /IEMobile\/[1-9]/.test(navigator.userAgent) ) {
62 adminbar.find('li.menupop').hoverIntent({
64 if ( disableHoverIntent )
67 $(this).addClass('hover');
70 if ( disableHoverIntent )
73 $(this).removeClass('hover');
80 if ( window.location.hash )
81 window.scrollBy( 0, -32 );
83 $('#wp-admin-bar-get-shortlink').click(function(e){
85 $(this).addClass('selected').children('.shortlink-input').blur(function(){
86 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected');
90 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
94 var target = $(e.target),
95 wrap = target.closest('.ab-sub-wrapper'),
96 parentHasHover = target.parent().hasClass('hover');
102 wrap = $('#wpadminbar .quicklinks');
104 wrap.find('.menupop').removeClass('hover');
106 if ( ! parentHasHover ) {
107 target.parent().toggleClass('hover');
110 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
113 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
117 var target = $(e.target);
122 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
123 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
126 $('#wpadminbar').click( function(e) {
127 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' )
131 $('html, body').animate({ scrollTop: 0 }, 'fast');
134 // fix focus bug in WebKit
135 $('.screen-reader-shortcut').keydown( function(e) {
141 id = $( this ).attr( 'href' );
143 ua = navigator.userAgent.toLowerCase();
145 if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) {
146 setTimeout(function () {
152 $( '#adminbar-search' ).on({
154 $( '#adminbarsearch' ).addClass( 'adminbar-focused' );
155 }, blur: function() {
156 $( '#adminbarsearch' ).removeClass( 'adminbar-focused' );
160 // Empty sessionStorage on logging out
161 if ( 'sessionStorage' in window ) {
162 $('#wp-admin-bar-logout a').click( function() {
164 for ( var key in sessionStorage ) {
165 if ( key.indexOf('wp-autosave-') != -1 )
166 sessionStorage.removeItem(key);
172 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
173 /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) {
175 document.body.className += ' no-font-face';
180 var addEvent = function( obj, type, fn ) {
181 if ( obj.addEventListener )
182 obj.addEventListener(type, fn, false);
183 else if ( obj.attachEvent )
184 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
187 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
188 rselected = new RegExp('\\bselected\\b', 'g'),
191 * Get the timeout ID of the given element
193 getTOID = function(el) {
196 if ( q[i] && el == q[i][1] )
202 addHoverClass = function(t) {
203 var i, id, inA, hovering, ul, li,
207 while ( t && t != aB && t != d ) {
208 if ( 'LI' == t.nodeName.toUpperCase() ) {
209 ancestors[ ancestors.length ] = t;
213 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
219 // Remove any selected classes.
220 if ( hovering && hovering.parentNode ) {
221 ul = hovering.parentNode;
222 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
223 i = ul.childNodes.length;
225 li = ul.childNodes[i];
226 if ( li != hovering )
227 li.className = li.className ? li.className.replace( rselected, '' ) : '';
232 /* remove the hover class for any objects not in the immediate element's ancestry */
236 ancestorLength = ancestors.length;
237 while( ancestorLength-- ) {
238 if ( ancestors[ ancestorLength ] == q[i][1] )
243 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
247 removeHoverClass = function(t) {
248 while ( t && t != aB && t != d ) {
249 if ( 'LI' == t.nodeName.toUpperCase() ) {
251 var to = setTimeout(function() {
252 t.className = t.className ? t.className.replace(hc, '') : '';
254 q[q.length] = [to, t];
261 clickShortlink = function(e) {
263 t = e.target || e.srcElement;
265 // Make t the shortlink menu item, or return.
267 // Check if we've gone past the shortlink node,
268 // or if the user is clicking on the input.
269 if ( ! t || t == d || t == aB )
271 // Check if we've found the shortlink node.
272 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
277 // IE doesn't support preventDefault, and does support returnValue
278 if ( e.preventDefault )
280 e.returnValue = false;
282 if ( -1 == t.className.indexOf('selected') )
283 t.className += ' selected';
285 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
286 node = t.childNodes[i];
287 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
290 node.onblur = function() {
291 t.className = t.className ? t.className.replace( rselected, '' ) : '';
299 scrollToTop = function(t) {
300 var distance, speed, step, steps, timer, speed_step;
302 // Ensure that the #wpadminbar was the target of the click.
303 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
306 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
311 speed_step = distance > 800 ? 130 : 100;
312 speed = Math.min( 12, Math.round( distance / speed_step ) );
313 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
317 // Animate scrolling to the top of the page by generating steps to
318 // the top of the page and shifting to each step at a set interval.
323 steps.push( distance );
325 setTimeout( function() {
326 window.scrollTo( 0, steps.shift() );
333 addEvent(w, 'load', function() {
334 aB = d.getElementById('wpadminbar');
336 if ( d.body && aB ) {
337 d.body.appendChild( aB );
340 aB.className = aB.className.replace(/nojs/, '');
342 addEvent(aB, 'mouseover', function(e) {
343 addHoverClass( e.target || e.srcElement );
346 addEvent(aB, 'mouseout', function(e) {
347 removeHoverClass( e.target || e.srcElement );
350 addEvent(aB, 'click', clickShortlink );
352 addEvent(aB, 'click', function(e) {
353 scrollToTop( e.target || e.srcElement );
356 addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() {
357 if ( 'sessionStorage' in window ) {
359 for ( var key in sessionStorage ) {
360 if ( key.indexOf('wp-autosave-') != -1 )
361 sessionStorage.removeItem(key);
368 if ( w.location.hash )
371 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
372 /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) {
374 document.body.className += ' no-font-face';
377 })(document, window);