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') ) {
31 } else if ( ! $( e.target ).closest( 'div' ).hasClass( 'ab-sub-wrapper' ) ) {
32 // We're dealing with an already-touch-opened menu genericon (we know el.hasClass('hover')),
33 // so close it on a second tap and prevent propag and defaults. See #29906
36 el.removeClass('hover');
40 $('li.menupop').off('click.wp-mobile-hover');
41 disableHoverIntent = false;
46 touchClose = function() {
47 var mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
48 // close any open drop-downs when the click/touch is not on the toolbar
49 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
50 if ( !$(e.target).closest('#wpadminbar').length )
51 adminbar.find('li.menupop.hover').removeClass('hover');
55 adminbar.removeClass('nojq').removeClass('nojs');
57 if ( 'ontouchstart' in window ) {
58 adminbar.on('touchstart', function(){
60 disableHoverIntent = true;
63 } else if ( /IEMobile\/[1-9]/.test(navigator.userAgent) ) {
68 adminbar.find('li.menupop').hoverIntent({
70 if ( disableHoverIntent )
73 $(this).addClass('hover');
76 if ( disableHoverIntent )
79 $(this).removeClass('hover');
86 if ( window.location.hash )
87 window.scrollBy( 0, -32 );
89 $('#wp-admin-bar-get-shortlink').click(function(e){
91 $(this).addClass('selected').children('.shortlink-input').blur(function(){
92 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected');
96 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
100 var target = $(e.target),
101 wrap = target.closest('.ab-sub-wrapper'),
102 parentHasHover = target.parent().hasClass('hover');
108 wrap = $('#wpadminbar .quicklinks');
110 wrap.find('.menupop').removeClass('hover');
112 if ( ! parentHasHover ) {
113 target.parent().toggleClass('hover');
116 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
119 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
123 var target = $(e.target);
128 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
129 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
132 adminbar.click( function(e) {
133 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) {
137 adminbar.find( 'li.menupop.hover' ).removeClass( 'hover' );
138 $( 'html, body' ).animate( { scrollTop: 0 }, 'fast' );
142 // fix focus bug in WebKit
143 $('.screen-reader-shortcut').keydown( function(e) {
149 id = $( this ).attr( 'href' );
151 ua = navigator.userAgent.toLowerCase();
153 if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) {
154 setTimeout(function () {
160 $( '#adminbar-search' ).on({
162 $( '#adminbarsearch' ).addClass( 'adminbar-focused' );
163 }, blur: function() {
164 $( '#adminbarsearch' ).removeClass( 'adminbar-focused' );
168 // Empty sessionStorage on logging out
169 if ( 'sessionStorage' in window ) {
170 $('#wp-admin-bar-logout a').click( function() {
172 for ( var key in sessionStorage ) {
173 if ( key.indexOf('wp-autosave-') != -1 )
174 sessionStorage.removeItem(key);
180 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
181 /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 ) ) {
183 document.body.className += ' no-font-face';
188 var addEvent = function( obj, type, fn ) {
189 if ( obj.addEventListener )
190 obj.addEventListener(type, fn, false);
191 else if ( obj.attachEvent )
192 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
195 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
196 rselected = new RegExp('\\bselected\\b', 'g'),
199 * Get the timeout ID of the given element
201 getTOID = function(el) {
204 if ( q[i] && el == q[i][1] )
210 addHoverClass = function(t) {
211 var i, id, inA, hovering, ul, li,
215 while ( t && t != aB && t != d ) {
216 if ( 'LI' == t.nodeName.toUpperCase() ) {
217 ancestors[ ancestors.length ] = t;
221 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
227 // Remove any selected classes.
228 if ( hovering && hovering.parentNode ) {
229 ul = hovering.parentNode;
230 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
231 i = ul.childNodes.length;
233 li = ul.childNodes[i];
234 if ( li != hovering )
235 li.className = li.className ? li.className.replace( rselected, '' ) : '';
240 /* remove the hover class for any objects not in the immediate element's ancestry */
244 ancestorLength = ancestors.length;
245 while( ancestorLength-- ) {
246 if ( ancestors[ ancestorLength ] == q[i][1] )
251 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
255 removeHoverClass = function(t) {
256 while ( t && t != aB && t != d ) {
257 if ( 'LI' == t.nodeName.toUpperCase() ) {
259 var to = setTimeout(function() {
260 t.className = t.className ? t.className.replace(hc, '') : '';
262 q[q.length] = [to, t];
269 clickShortlink = function(e) {
271 t = e.target || e.srcElement;
273 // Make t the shortlink menu item, or return.
275 // Check if we've gone past the shortlink node,
276 // or if the user is clicking on the input.
277 if ( ! t || t == d || t == aB )
279 // Check if we've found the shortlink node.
280 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
285 // IE doesn't support preventDefault, and does support returnValue
286 if ( e.preventDefault )
288 e.returnValue = false;
290 if ( -1 == t.className.indexOf('selected') )
291 t.className += ' selected';
293 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
294 node = t.childNodes[i];
295 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
298 node.onblur = function() {
299 t.className = t.className ? t.className.replace( rselected, '' ) : '';
307 scrollToTop = function(t) {
308 var distance, speed, step, steps, timer, speed_step;
310 // Ensure that the #wpadminbar was the target of the click.
311 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
314 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
319 speed_step = distance > 800 ? 130 : 100;
320 speed = Math.min( 12, Math.round( distance / speed_step ) );
321 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
325 // Animate scrolling to the top of the page by generating steps to
326 // the top of the page and shifting to each step at a set interval.
331 steps.push( distance );
333 setTimeout( function() {
334 window.scrollTo( 0, steps.shift() );
341 addEvent(w, 'load', function() {
342 aB = d.getElementById('wpadminbar');
344 if ( d.body && aB ) {
345 d.body.appendChild( aB );
348 aB.className = aB.className.replace(/nojs/, '');
350 addEvent(aB, 'mouseover', function(e) {
351 addHoverClass( e.target || e.srcElement );
354 addEvent(aB, 'mouseout', function(e) {
355 removeHoverClass( e.target || e.srcElement );
358 addEvent(aB, 'click', clickShortlink );
360 addEvent(aB, 'click', function(e) {
361 scrollToTop( e.target || e.srcElement );
364 addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() {
365 if ( 'sessionStorage' in window ) {
367 for ( var key in sessionStorage ) {
368 if ( key.indexOf('wp-autosave-') != -1 )
369 sessionStorage.removeItem(key);
376 if ( w.location.hash )
379 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
380 /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 ) ) {
382 document.body.className += ' no-font-face';
385 })(document, window);