1 // use jQuery and hoverIntent if loaded
2 if ( typeof(jQuery) != 'undefined' ) {
3 if ( typeof(jQuery.fn.hoverIntent) == 'undefined' ) {
4 // hoverIntent r6 - Copy of wp-includes/js/hoverIntent.min.js
5 (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);
7 jQuery(document).ready(function($){
8 var adminbar = $('#wpadminbar'), refresh, touchOpen, touchClose, disableHoverIntent = false;
10 refresh = function(i, el){ // force the browser to refresh the tabbing index
11 var node = $(el), tab = node.attr('tabindex');
13 node.attr('tabindex', '0').attr('tabindex', tab);
16 touchOpen = function(unbind) {
17 adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) {
20 if ( !el.hasClass('hover') ) {
22 adminbar.find('li.menupop.hover').removeClass('hover');
27 $('li.menupop').off('click.wp-mobile-hover');
28 disableHoverIntent = false;
33 touchClose = function() {
34 var mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
35 // close any open drop-downs when the click/touch is not on the toolbar
36 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
37 if ( !$(e.target).closest('#wpadminbar').length )
38 adminbar.find('li.menupop.hover').removeClass('hover');
42 adminbar.removeClass('nojq').removeClass('nojs');
44 if ( 'ontouchstart' in window ) {
45 adminbar.on('touchstart', function(){
47 disableHoverIntent = true;
50 } else if ( /IEMobile\/[1-9]/.test(navigator.userAgent) ) {
55 adminbar.find('li.menupop').hoverIntent({
57 if ( disableHoverIntent )
60 $(this).addClass('hover');
63 if ( disableHoverIntent )
66 $(this).removeClass('hover');
73 if ( window.location.hash )
74 window.scrollBy( 0, -32 );
76 $('#wp-admin-bar-get-shortlink').click(function(e){
78 $(this).addClass('selected').children('.shortlink-input').blur(function(){
79 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected');
83 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
87 var target = $(e.target), wrap = target.closest('ab-sub-wrapper');
93 wrap = $('#wpadminbar .quicklinks');
95 wrap.find('.menupop').removeClass('hover');
96 target.parent().toggleClass('hover');
97 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
100 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
104 var target = $(e.target);
109 target.closest('.hover').removeClass('hover').children('.ab-item').focus();
110 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
113 $('#wpadminbar').click( function(e) {
114 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' )
118 $('html, body').animate({ scrollTop: 0 }, 'fast');
121 // fix focus bug in WebKit
122 $('.screen-reader-shortcut').keydown( function(e) {
126 var id = $(this).attr('href');
128 var ua = navigator.userAgent.toLowerCase();
129 if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) {
130 setTimeout(function () {
136 // Empty sessionStorage on logging out
137 if ( 'sessionStorage' in window ) {
138 $('#wp-admin-bar-logout a').click( function() {
140 for ( var key in sessionStorage ) {
141 if ( key.indexOf('wp-autosave-') != -1 )
142 sessionStorage.removeItem(key);
150 var addEvent = function( obj, type, fn ) {
151 if ( obj.addEventListener )
152 obj.addEventListener(type, fn, false);
153 else if ( obj.attachEvent )
154 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
157 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
158 rselected = new RegExp('\\bselected\\b', 'g'),
161 * Get the timeout ID of the given element
163 getTOID = function(el) {
166 if ( q[i] && el == q[i][1] )
172 addHoverClass = function(t) {
173 var i, id, inA, hovering, ul, li,
177 while ( t && t != aB && t != d ) {
178 if ( 'LI' == t.nodeName.toUpperCase() ) {
179 ancestors[ ancestors.length ] = t;
183 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
189 // Remove any selected classes.
190 if ( hovering && hovering.parentNode ) {
191 ul = hovering.parentNode;
192 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
193 i = ul.childNodes.length;
195 li = ul.childNodes[i];
196 if ( li != hovering )
197 li.className = li.className ? li.className.replace( rselected, '' ) : '';
202 /* remove the hover class for any objects not in the immediate element's ancestry */
206 ancestorLength = ancestors.length;
207 while( ancestorLength-- ) {
208 if ( ancestors[ ancestorLength ] == q[i][1] )
213 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
217 removeHoverClass = function(t) {
218 while ( t && t != aB && t != d ) {
219 if ( 'LI' == t.nodeName.toUpperCase() ) {
221 var to = setTimeout(function() {
222 t.className = t.className ? t.className.replace(hc, '') : '';
224 q[q.length] = [to, t];
231 clickShortlink = function(e) {
233 t = e.target || e.srcElement;
235 // Make t the shortlink menu item, or return.
237 // Check if we've gone past the shortlink node,
238 // or if the user is clicking on the input.
239 if ( ! t || t == d || t == aB )
241 // Check if we've found the shortlink node.
242 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
247 // IE doesn't support preventDefault, and does support returnValue
248 if ( e.preventDefault )
250 e.returnValue = false;
252 if ( -1 == t.className.indexOf('selected') )
253 t.className += ' selected';
255 for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
256 node = t.childNodes[i];
257 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
260 node.onblur = function() {
261 t.className = t.className ? t.className.replace( rselected, '' ) : '';
269 scrollToTop = function(t) {
270 var distance, speed, step, steps, timer, speed_step;
272 // Ensure that the #wpadminbar was the target of the click.
273 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' )
276 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
281 speed_step = distance > 800 ? 130 : 100;
282 speed = Math.min( 12, Math.round( distance / speed_step ) );
283 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );
287 // Animate scrolling to the top of the page by generating steps to
288 // the top of the page and shifting to each step at a set interval.
293 steps.push( distance );
295 setTimeout( function() {
296 window.scrollTo( 0, steps.shift() );
303 addEvent(w, 'load', function() {
304 aB = d.getElementById('wpadminbar');
306 if ( d.body && aB ) {
307 d.body.appendChild( aB );
310 aB.className = aB.className.replace(/nojs/, '');
312 addEvent(aB, 'mouseover', function(e) {
313 addHoverClass( e.target || e.srcElement );
316 addEvent(aB, 'mouseout', function(e) {
317 removeHoverClass( e.target || e.srcElement );
320 addEvent(aB, 'click', clickShortlink );
322 addEvent(aB, 'click', function(e) {
323 scrollToTop( e.target || e.srcElement );
326 addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() {
327 if ( 'sessionStorage' in window ) {
329 for ( var key in sessionStorage ) {
330 if ( key.indexOf('wp-autosave-') != -1 )
331 sessionStorage.removeItem(key);
338 if ( w.location.hash )
341 })(document, window);