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 r6 - Copy of wp-includes/js/hoverIntent.min.js
7 (function(a){a.fn.hoverIntent=function(m,d,h){var j={interval:100,sensitivity:7,timeout:0};if(typeof m==="object"){j=a.extend(j,m)}else{if(a.isFunction(d)){j=a.extend(j,{over:m,out:d,selector:h})}else{j=a.extend(j,{over:m,out:m,selector:d})}}var l,k,g,f;var e=function(n){l=n.pageX;k=n.pageY};var c=function(o,n){n.hoverIntent_t=clearTimeout(n.hoverIntent_t);if((Math.abs(g-l)+Math.abs(f-k))<j.sensitivity){a(n).off("mousemove.hoverIntent",e);n.hoverIntent_s=1;return j.over.apply(n,[o])}else{g=l;f=k;n.hoverIntent_t=setTimeout(function(){c(o,n)},j.interval)}};var i=function(o,n){n.hoverIntent_t=clearTimeout(n.hoverIntent_t);n.hoverIntent_s=0;return j.out.apply(n,[o])};var b=function(p){var o=jQuery.extend({},p);var n=this;if(n.hoverIntent_t){n.hoverIntent_t=clearTimeout(n.hoverIntent_t)}if(p.type=="mouseenter"){g=o.pageX;f=o.pageY;a(n).on("mousemove.hoverIntent",e);if(n.hoverIntent_s!=1){n.hoverIntent_t=setTimeout(function(){c(o,n)},j.interval)}}else{a(n).off("mousemove.hoverIntent",e);if(n.hoverIntent_s==1){n.hoverIntent_t=setTimeout(function(){i(o,n)},j.timeout)}}};return this.on({"mouseenter.hoverIntent":b,"mouseleave.hoverIntent":b},j.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), wrap = target.closest('ab-sub-wrapper');
100 wrap = $('#wpadminbar .quicklinks');
102 wrap.find('.menupop').removeClass('hover');
103 target.parent().toggleClass('hover');
104 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
107 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
111 var target = $(e.target);
116 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
117 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
120 $('#wpadminbar').click( function(e) {
121 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' )
125 $('html, body').animate({ scrollTop: 0 }, 'fast');
128 // fix focus bug in WebKit
129 $('.screen-reader-shortcut').keydown( function(e) {
135 id = $( this ).attr( 'href' );
137 ua = navigator.userAgent.toLowerCase();
139 if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) {
140 setTimeout(function () {
146 // Empty sessionStorage on logging out
147 if ( 'sessionStorage' in window ) {
148 $('#wp-admin-bar-logout a').click( function() {
150 for ( var key in sessionStorage ) {
151 if ( key.indexOf('wp-autosave-') != -1 )
152 sessionStorage.removeItem(key);
158 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
159 /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 ) ) {
161 document.body.className += ' no-font-face';
166 var addEvent = function( obj, type, fn ) {
167 if ( obj.addEventListener )
168 obj.addEventListener(type, fn, false);
169 else if ( obj.attachEvent )
170 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
173 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
174 rselected = new RegExp('\\bselected\\b', 'g'),
177 * Get the timeout ID of the given element
179 getTOID = function(el) {
182 if ( q[i] && el == q[i][1] )
188 addHoverClass = function(t) {
189 var i, id, inA, hovering, ul, li,
193 while ( t && t != aB && t != d ) {
194 if ( 'LI' == t.nodeName.toUpperCase() ) {
195 ancestors[ ancestors.length ] = t;
199 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
205 // Remove any selected classes.
206 if ( hovering && hovering.parentNode ) {
207 ul = hovering.parentNode;
208 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
209 i = ul.childNodes.length;
211 li = ul.childNodes[i];
212 if ( li != hovering )
213 li.className = li.className ? li.className.replace( rselected, '' ) : '';
218 /* remove the hover class for any objects not in the immediate element's ancestry */
222 ancestorLength = ancestors.length;
223 while( ancestorLength-- ) {
224 if ( ancestors[ ancestorLength ] == q[i][1] )
229 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
233 removeHoverClass = function(t) {
234 while ( t && t != aB && t != d ) {
235 if ( 'LI' == t.nodeName.toUpperCase() ) {
237 var to = setTimeout(function() {
238 t.className = t.className ? t.className.replace(hc, '') : '';
240 q[q.length] = [to, t];
247 clickShortlink = function(e) {
249 t = e.target || e.srcElement;
251 // Make t the shortlink menu item, or return.
253 // Check if we've gone past the shortlink node,
254 // or if the user is clicking on the input.
255 if ( ! t || t == d || t == aB )
257 // Check if we've found the shortlink node.
258 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
263 // IE doesn't support preventDefault, and does support returnValue
264 if ( e.preventDefault )
266 e.returnValue = false;
268 if ( -1 == t.className.indexOf('selected') )
269 t.className += ' selected';
271 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
272 node = t.childNodes[i];
273 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
276 node.onblur = function() {
277 t.className = t.className ? t.className.replace( rselected, '' ) : '';
285 scrollToTop = function(t) {
286 var distance, speed, step, steps, timer, speed_step;
288 // Ensure that the #wpadminbar was the target of the click.
289 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
292 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
297 speed_step = distance > 800 ? 130 : 100;
298 speed = Math.min( 12, Math.round( distance / speed_step ) );
299 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
303 // Animate scrolling to the top of the page by generating steps to
304 // the top of the page and shifting to each step at a set interval.
309 steps.push( distance );
311 setTimeout( function() {
312 window.scrollTo( 0, steps.shift() );
319 addEvent(w, 'load', function() {
320 aB = d.getElementById('wpadminbar');
322 if ( d.body && aB ) {
323 d.body.appendChild( aB );
326 aB.className = aB.className.replace(/nojs/, '');
328 addEvent(aB, 'mouseover', function(e) {
329 addHoverClass( e.target || e.srcElement );
332 addEvent(aB, 'mouseout', function(e) {
333 removeHoverClass( e.target || e.srcElement );
336 addEvent(aB, 'click', clickShortlink );
338 addEvent(aB, 'click', function(e) {
339 scrollToTop( e.target || e.srcElement );
342 addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() {
343 if ( 'sessionStorage' in window ) {
345 for ( var key in sessionStorage ) {
346 if ( key.indexOf('wp-autosave-') != -1 )
347 sessionStorage.removeItem(key);
354 if ( w.location.hash )
357 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
358 /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 ) ) {
360 document.body.className += ' no-font-face';
363 })(document, window);