5
|
1 |
/* jshint loopfunc: true */ |
0
|
2 |
// use jQuery and hoverIntent if loaded |
|
3 |
if ( typeof(jQuery) != 'undefined' ) { |
|
4 |
if ( typeof(jQuery.fn.hoverIntent) == 'undefined' ) { |
5
|
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 */ |
0
|
9 |
} |
|
10 |
jQuery(document).ready(function($){ |
|
11 |
var adminbar = $('#wpadminbar'), refresh, touchOpen, touchClose, disableHoverIntent = false; |
|
12 |
|
|
13 |
refresh = function(i, el){ // force the browser to refresh the tabbing index |
|
14 |
var node = $(el), tab = node.attr('tabindex'); |
|
15 |
if ( tab ) |
|
16 |
node.attr('tabindex', '0').attr('tabindex', tab); |
|
17 |
}; |
|
18 |
|
|
19 |
touchOpen = function(unbind) { |
|
20 |
adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) { |
|
21 |
var el = $(this); |
|
22 |
|
5
|
23 |
if ( el.parent().is('#wp-admin-bar-root-default') && !el.hasClass('hover') ) { |
0
|
24 |
e.preventDefault(); |
|
25 |
adminbar.find('li.menupop.hover').removeClass('hover'); |
|
26 |
el.addClass('hover'); |
5
|
27 |
} else if ( !el.hasClass('hover') ) { |
|
28 |
e.stopPropagation(); |
|
29 |
e.preventDefault(); |
|
30 |
el.addClass('hover'); |
0
|
31 |
} |
|
32 |
|
|
33 |
if ( unbind ) { |
|
34 |
$('li.menupop').off('click.wp-mobile-hover'); |
|
35 |
disableHoverIntent = false; |
|
36 |
} |
|
37 |
}); |
|
38 |
}; |
|
39 |
|
|
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'); |
|
46 |
}); |
|
47 |
}; |
|
48 |
|
|
49 |
adminbar.removeClass('nojq').removeClass('nojs'); |
|
50 |
|
|
51 |
if ( 'ontouchstart' in window ) { |
|
52 |
adminbar.on('touchstart', function(){ |
|
53 |
touchOpen(true); |
|
54 |
disableHoverIntent = true; |
|
55 |
}); |
|
56 |
touchClose(); |
|
57 |
} else if ( /IEMobile\/[1-9]/.test(navigator.userAgent) ) { |
|
58 |
touchOpen(); |
|
59 |
touchClose(); |
|
60 |
} |
|
61 |
|
|
62 |
adminbar.find('li.menupop').hoverIntent({ |
5
|
63 |
over: function() { |
0
|
64 |
if ( disableHoverIntent ) |
|
65 |
return; |
|
66 |
|
|
67 |
$(this).addClass('hover'); |
|
68 |
}, |
5
|
69 |
out: function() { |
0
|
70 |
if ( disableHoverIntent ) |
|
71 |
return; |
|
72 |
|
|
73 |
$(this).removeClass('hover'); |
|
74 |
}, |
|
75 |
timeout: 180, |
|
76 |
sensitivity: 7, |
|
77 |
interval: 100 |
|
78 |
}); |
|
79 |
|
|
80 |
if ( window.location.hash ) |
|
81 |
window.scrollBy( 0, -32 ); |
|
82 |
|
|
83 |
$('#wp-admin-bar-get-shortlink').click(function(e){ |
|
84 |
e.preventDefault(); |
|
85 |
$(this).addClass('selected').children('.shortlink-input').blur(function(){ |
|
86 |
$(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected'); |
|
87 |
}).focus().select(); |
|
88 |
}); |
|
89 |
|
|
90 |
$('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){ |
|
91 |
if ( e.which != 13 ) |
|
92 |
return; |
|
93 |
|
5
|
94 |
var target = $(e.target), |
|
95 |
wrap = target.closest('.ab-sub-wrapper'), |
|
96 |
parentHasHover = target.parent().hasClass('hover'); |
0
|
97 |
|
|
98 |
e.stopPropagation(); |
|
99 |
e.preventDefault(); |
|
100 |
|
|
101 |
if ( !wrap.length ) |
|
102 |
wrap = $('#wpadminbar .quicklinks'); |
|
103 |
|
|
104 |
wrap.find('.menupop').removeClass('hover'); |
5
|
105 |
|
|
106 |
if ( ! parentHasHover ) { |
|
107 |
target.parent().toggleClass('hover'); |
|
108 |
} |
|
109 |
|
0
|
110 |
target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); |
|
111 |
}).each(refresh); |
|
112 |
|
|
113 |
$('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){ |
|
114 |
if ( e.which != 27 ) |
|
115 |
return; |
|
116 |
|
|
117 |
var target = $(e.target); |
|
118 |
|
|
119 |
e.stopPropagation(); |
|
120 |
e.preventDefault(); |
|
121 |
|
|
122 |
target.closest('.hover').removeClass('hover').children('.ab-item').focus(); |
|
123 |
target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); |
|
124 |
}); |
|
125 |
|
|
126 |
$('#wpadminbar').click( function(e) { |
|
127 |
if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) |
|
128 |
return; |
|
129 |
|
|
130 |
e.preventDefault(); |
|
131 |
$('html, body').animate({ scrollTop: 0 }, 'fast'); |
|
132 |
}); |
|
133 |
|
|
134 |
// fix focus bug in WebKit |
|
135 |
$('.screen-reader-shortcut').keydown( function(e) { |
5
|
136 |
var id, ua; |
|
137 |
|
0
|
138 |
if ( 13 != e.which ) |
|
139 |
return; |
|
140 |
|
5
|
141 |
id = $( this ).attr( 'href' ); |
0
|
142 |
|
5
|
143 |
ua = navigator.userAgent.toLowerCase(); |
|
144 |
|
0
|
145 |
if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) { |
|
146 |
setTimeout(function () { |
|
147 |
$(id).focus(); |
|
148 |
}, 100); |
|
149 |
} |
|
150 |
}); |
|
151 |
|
5
|
152 |
$( '#adminbar-search' ).on({ |
|
153 |
focus: function() { |
|
154 |
$( '#adminbarsearch' ).addClass( 'adminbar-focused' ); |
|
155 |
}, blur: function() { |
|
156 |
$( '#adminbarsearch' ).removeClass( 'adminbar-focused' ); |
|
157 |
} |
|
158 |
} ); |
|
159 |
|
0
|
160 |
// Empty sessionStorage on logging out |
|
161 |
if ( 'sessionStorage' in window ) { |
|
162 |
$('#wp-admin-bar-logout a').click( function() { |
|
163 |
try { |
|
164 |
for ( var key in sessionStorage ) { |
|
165 |
if ( key.indexOf('wp-autosave-') != -1 ) |
|
166 |
sessionStorage.removeItem(key); |
|
167 |
} |
|
168 |
} catch(e) {} |
|
169 |
}); |
|
170 |
} |
5
|
171 |
|
|
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 ) ) { |
|
174 |
|
|
175 |
document.body.className += ' no-font-face'; |
|
176 |
} |
0
|
177 |
}); |
|
178 |
} else { |
|
179 |
(function(d, w) { |
|
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);}); |
|
185 |
}, |
|
186 |
|
|
187 |
aB, hc = new RegExp('\\bhover\\b', 'g'), q = [], |
|
188 |
rselected = new RegExp('\\bselected\\b', 'g'), |
|
189 |
|
|
190 |
/** |
|
191 |
* Get the timeout ID of the given element |
|
192 |
*/ |
|
193 |
getTOID = function(el) { |
|
194 |
var i = q.length; |
|
195 |
while ( i-- ) { |
|
196 |
if ( q[i] && el == q[i][1] ) |
|
197 |
return q[i][0]; |
|
198 |
} |
|
199 |
return false; |
|
200 |
}, |
|
201 |
|
|
202 |
addHoverClass = function(t) { |
|
203 |
var i, id, inA, hovering, ul, li, |
|
204 |
ancestors = [], |
|
205 |
ancestorLength = 0; |
|
206 |
|
|
207 |
while ( t && t != aB && t != d ) { |
|
208 |
if ( 'LI' == t.nodeName.toUpperCase() ) { |
|
209 |
ancestors[ ancestors.length ] = t; |
|
210 |
id = getTOID(t); |
|
211 |
if ( id ) |
|
212 |
clearTimeout( id ); |
|
213 |
t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover'; |
|
214 |
hovering = t; |
|
215 |
} |
|
216 |
t = t.parentNode; |
|
217 |
} |
|
218 |
|
|
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; |
|
224 |
while ( i-- ) { |
|
225 |
li = ul.childNodes[i]; |
|
226 |
if ( li != hovering ) |
|
227 |
li.className = li.className ? li.className.replace( rselected, '' ) : ''; |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
/* remove the hover class for any objects not in the immediate element's ancestry */ |
|
233 |
i = q.length; |
|
234 |
while ( i-- ) { |
|
235 |
inA = false; |
|
236 |
ancestorLength = ancestors.length; |
|
237 |
while( ancestorLength-- ) { |
|
238 |
if ( ancestors[ ancestorLength ] == q[i][1] ) |
|
239 |
inA = true; |
|
240 |
} |
|
241 |
|
|
242 |
if ( ! inA ) |
|
243 |
q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : ''; |
|
244 |
} |
|
245 |
}, |
|
246 |
|
|
247 |
removeHoverClass = function(t) { |
|
248 |
while ( t && t != aB && t != d ) { |
|
249 |
if ( 'LI' == t.nodeName.toUpperCase() ) { |
|
250 |
(function(t) { |
|
251 |
var to = setTimeout(function() { |
|
252 |
t.className = t.className ? t.className.replace(hc, '') : ''; |
|
253 |
}, 500); |
|
254 |
q[q.length] = [to, t]; |
|
255 |
})(t); |
|
256 |
} |
|
257 |
t = t.parentNode; |
|
258 |
} |
|
259 |
}, |
|
260 |
|
|
261 |
clickShortlink = function(e) { |
|
262 |
var i, l, node, |
|
263 |
t = e.target || e.srcElement; |
|
264 |
|
|
265 |
// Make t the shortlink menu item, or return. |
|
266 |
while ( true ) { |
|
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 ) |
|
270 |
return; |
|
271 |
// Check if we've found the shortlink node. |
|
272 |
if ( t.id && t.id == 'wp-admin-bar-get-shortlink' ) |
|
273 |
break; |
|
274 |
t = t.parentNode; |
|
275 |
} |
|
276 |
|
|
277 |
// IE doesn't support preventDefault, and does support returnValue |
|
278 |
if ( e.preventDefault ) |
|
279 |
e.preventDefault(); |
|
280 |
e.returnValue = false; |
|
281 |
|
|
282 |
if ( -1 == t.className.indexOf('selected') ) |
|
283 |
t.className += ' selected'; |
|
284 |
|
|
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') ) { |
|
288 |
node.focus(); |
|
289 |
node.select(); |
|
290 |
node.onblur = function() { |
|
291 |
t.className = t.className ? t.className.replace( rselected, '' ) : ''; |
|
292 |
}; |
|
293 |
break; |
|
294 |
} |
|
295 |
} |
|
296 |
return false; |
|
297 |
}, |
|
298 |
|
|
299 |
scrollToTop = function(t) { |
|
300 |
var distance, speed, step, steps, timer, speed_step; |
|
301 |
|
|
302 |
// Ensure that the #wpadminbar was the target of the click. |
|
303 |
if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' ) |
|
304 |
return; |
|
305 |
|
|
306 |
distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; |
|
307 |
|
|
308 |
if ( distance < 1 ) |
|
309 |
return; |
|
310 |
|
|
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 ); |
|
314 |
steps = []; |
|
315 |
timer = 0; |
|
316 |
|
|
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. |
|
319 |
while ( distance ) { |
|
320 |
distance -= step; |
|
321 |
if ( distance < 0 ) |
|
322 |
distance = 0; |
|
323 |
steps.push( distance ); |
|
324 |
|
|
325 |
setTimeout( function() { |
|
326 |
window.scrollTo( 0, steps.shift() ); |
|
327 |
}, timer * speed ); |
|
328 |
|
|
329 |
timer++; |
|
330 |
} |
|
331 |
}; |
|
332 |
|
|
333 |
addEvent(w, 'load', function() { |
|
334 |
aB = d.getElementById('wpadminbar'); |
|
335 |
|
|
336 |
if ( d.body && aB ) { |
|
337 |
d.body.appendChild( aB ); |
|
338 |
|
|
339 |
if ( aB.className ) |
|
340 |
aB.className = aB.className.replace(/nojs/, ''); |
|
341 |
|
|
342 |
addEvent(aB, 'mouseover', function(e) { |
|
343 |
addHoverClass( e.target || e.srcElement ); |
|
344 |
}); |
|
345 |
|
|
346 |
addEvent(aB, 'mouseout', function(e) { |
|
347 |
removeHoverClass( e.target || e.srcElement ); |
|
348 |
}); |
|
349 |
|
|
350 |
addEvent(aB, 'click', clickShortlink ); |
|
351 |
|
|
352 |
addEvent(aB, 'click', function(e) { |
|
353 |
scrollToTop( e.target || e.srcElement ); |
|
354 |
}); |
|
355 |
|
|
356 |
addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() { |
|
357 |
if ( 'sessionStorage' in window ) { |
|
358 |
try { |
|
359 |
for ( var key in sessionStorage ) { |
|
360 |
if ( key.indexOf('wp-autosave-') != -1 ) |
|
361 |
sessionStorage.removeItem(key); |
|
362 |
} |
|
363 |
} catch(e) {} |
|
364 |
} |
|
365 |
}); |
|
366 |
} |
|
367 |
|
|
368 |
if ( w.location.hash ) |
|
369 |
w.scrollBy(0,-32); |
5
|
370 |
|
|
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 ) ) { |
|
373 |
|
|
374 |
document.body.className += ' no-font-face'; |
|
375 |
} |
0
|
376 |
}); |
|
377 |
})(document, window); |
|
378 |
|
|
379 |
} |