X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..6c8f14c09105d0afa4c1574215c59b5021040e76:/wp-includes/js/admin-bar.js diff --git a/wp-includes/js/admin-bar.js b/wp-includes/js/admin-bar.js index ea90a69f..cb4e1184 100644 --- a/wp-includes/js/admin-bar.js +++ b/wp-includes/js/admin-bar.js @@ -1 +1,318 @@ -(function(i,k){var c=function(n,m,d){if(n.addEventListener){n.addEventListener(m,d,false)}else{if(n.attachEvent){n.attachEvent("on"+m,function(){return d.call(n,window.event)})}}},e,f=new RegExp("\\bhover\\b","g"),a=[],j=new RegExp("\\bselected\\b","g"),g=function(m){var d=a.length;while(d--){if(a[d]&&m==a[d][1]){return a[d][0]}}return false},h=function(s){var n,d,q,m,p,r,u=[],o=0;while(s&&s!=e&&s!=i){if("LI"==s.nodeName.toUpperCase()){u[u.length]=s;d=g(s);if(d){clearTimeout(d)}s.className=s.className?(s.className.replace(f,"")+" hover"):"hover";m=s}s=s.parentNode}if(m&&m.parentNode){p=m.parentNode;if(p&&"UL"==p.nodeName.toUpperCase()){n=p.childNodes.length;while(n--){r=p.childNodes[n];if(r!=m){r.className=r.className?r.className.replace(j,""):""}}}}n=a.length;while(n--){q=false;o=u.length;while(o--){if(u[o]==a[n][1]){q=true}}if(!q){a[n][1].className=a[n][1].className?a[n][1].className.replace(f,""):""}}},l=function(d){while(d&&d!=e&&d!=i){if("LI"==d.nodeName.toUpperCase()){(function(m){var n=setTimeout(function(){m.className=m.className?m.className.replace(f,""):""},500);a[a.length]=[n,m]})(d)}d=d.parentNode}},b=function(p){var n,d,o,m=p.target||p.srcElement;while(true){if(!m||m==i||m==e){return}if(m.id&&m.id=="wp-admin-bar-get-shortlink"){break}m=m.parentNode}if(p.preventDefault){p.preventDefault()}p.returnValue=false;if(-1==m.className.indexOf("selected")){m.className+=" selected"}for(n=0,d=m.childNodes.length;n .ab-item').bind('keydown.adminbar', function(e){ + if ( e.which != 13 ) + return; + + var target = $(e.target), wrap = target.closest('ab-sub-wrapper'); + + e.stopPropagation(); + e.preventDefault(); + + if ( !wrap.length ) + wrap = $('#wpadminbar .quicklinks'); + + wrap.find('.menupop').removeClass('hover'); + target.parent().toggleClass('hover'); + target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); + }).each(refresh); + + $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){ + if ( e.which != 27 ) + return; + + var target = $(e.target); + + e.stopPropagation(); + e.preventDefault(); + + target.closest('.hover').removeClass('hover').children('.ab-item').focus(); + target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); + }); + + $('#wpadminbar').click( function(e) { + if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) + return; + + e.preventDefault(); + $('html, body').animate({ scrollTop: 0 }, 'fast'); + }); + + // fix focus bug in WebKit + $('.screen-reader-shortcut').keydown( function(e) { + if ( 13 != e.which ) + return; + + var id = $(this).attr('href'); + + if ( $.browser.webkit && id && id.charAt(0) == '#' ) { + setTimeout(function () { + $(id).focus(); + }, 100); + } + }); + }); +} else { + (function(d, w) { + var addEvent = function( obj, type, fn ) { + if ( obj.addEventListener ) + obj.addEventListener(type, fn, false); + else if ( obj.attachEvent ) + obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);}); + }, + + aB, hc = new RegExp('\\bhover\\b', 'g'), q = [], + rselected = new RegExp('\\bselected\\b', 'g'), + + /** + * Get the timeout ID of the given element + */ + getTOID = function(el) { + var i = q.length; + while ( i-- ) { + if ( q[i] && el == q[i][1] ) + return q[i][0]; + } + return false; + }, + + addHoverClass = function(t) { + var i, id, inA, hovering, ul, li, + ancestors = [], + ancestorLength = 0; + + while ( t && t != aB && t != d ) { + if ( 'LI' == t.nodeName.toUpperCase() ) { + ancestors[ ancestors.length ] = t; + id = getTOID(t); + if ( id ) + clearTimeout( id ); + t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover'; + hovering = t; + } + t = t.parentNode; + } + + // Remove any selected classes. + if ( hovering && hovering.parentNode ) { + ul = hovering.parentNode; + if ( ul && 'UL' == ul.nodeName.toUpperCase() ) { + i = ul.childNodes.length; + while ( i-- ) { + li = ul.childNodes[i]; + if ( li != hovering ) + li.className = li.className ? li.className.replace( rselected, '' ) : ''; + } + } + } + + /* remove the hover class for any objects not in the immediate element's ancestry */ + i = q.length; + while ( i-- ) { + inA = false; + ancestorLength = ancestors.length; + while( ancestorLength-- ) { + if ( ancestors[ ancestorLength ] == q[i][1] ) + inA = true; + } + + if ( ! inA ) + q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : ''; + } + }, + + removeHoverClass = function(t) { + while ( t && t != aB && t != d ) { + if ( 'LI' == t.nodeName.toUpperCase() ) { + (function(t) { + var to = setTimeout(function() { + t.className = t.className ? t.className.replace(hc, '') : ''; + }, 500); + q[q.length] = [to, t]; + })(t); + } + t = t.parentNode; + } + }, + + clickShortlink = function(e) { + var i, l, node, + t = e.target || e.srcElement; + + // Make t the shortlink menu item, or return. + while ( true ) { + // Check if we've gone past the shortlink node, + // or if the user is clicking on the input. + if ( ! t || t == d || t == aB ) + return; + // Check if we've found the shortlink node. + if ( t.id && t.id == 'wp-admin-bar-get-shortlink' ) + break; + t = t.parentNode; + } + + // IE doesn't support preventDefault, and does support returnValue + if ( e.preventDefault ) + e.preventDefault(); + e.returnValue = false; + + if ( -1 == t.className.indexOf('selected') ) + t.className += ' selected'; + + for ( i = 0, l = t.childNodes.length; i < l; i++ ) { + node = t.childNodes[i]; + if ( node.className && -1 != node.className.indexOf('shortlink-input') ) { + node.focus(); + node.select(); + node.onblur = function() { + t.className = t.className ? t.className.replace( rselected, '' ) : ''; + }; + break; + } + } + return false; + }, + + scrollToTop = function(t) { + var distance, speed, step, steps, timer, speed_step; + + // Ensure that the #wpadminbar was the target of the click. + if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' ) + return; + + distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; + + if ( distance < 1 ) + return; + + speed_step = distance > 800 ? 130 : 100; + speed = Math.min( 12, Math.round( distance / speed_step ) ); + step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 ); + steps = []; + timer = 0; + + // Animate scrolling to the top of the page by generating steps to + // the top of the page and shifting to each step at a set interval. + while ( distance ) { + distance -= step; + if ( distance < 0 ) + distance = 0; + steps.push( distance ); + + setTimeout( function() { + window.scrollTo( 0, steps.shift() ); + }, timer * speed ); + + timer++; + } + }; + + addEvent(w, 'load', function() { + aB = d.getElementById('wpadminbar'); + + if ( d.body && aB ) { + d.body.appendChild( aB ); + + if ( aB.className ) + aB.className = aB.className.replace(/nojs/, ''); + + addEvent(aB, 'mouseover', function(e) { + addHoverClass( e.target || e.srcElement ); + }); + + addEvent(aB, 'mouseout', function(e) { + removeHoverClass( e.target || e.srcElement ); + }); + + addEvent(aB, 'click', clickShortlink ); + + addEvent(aB, 'click', function(e) { + scrollToTop( e.target || e.srcElement ); + }); + } + + if ( w.location.hash ) + w.scrollBy(0,-32); + }); + })(document, window); + +}