| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 // use jQuery and hoverIntent if loaded 2 if ( typeof(jQuery) != 'undefined' ) { 3 if ( typeof(jQuery.fn.hoverIntent) == 'undefined' ) 4 (function(a){a.fn.hoverIntent=function(l,j){var m={sensitivity:7,interval:100,timeout:0};m=a.extend(m,j?{over:l,out:j}:l);var o,n,h,d;var e=function(f){o=f.pageX;n=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-o)+Math.abs(d-n))<m.sensitivity){a(f).unbind("mousemove",e);f.hoverIntent_s=1;return m.over.apply(f,[g])}else{h=o;d=n;f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return m.out.apply(f,[g])};var b=function(q){var f=this;var g=(q.type=="mouseover"?q.fromElement:q.toElement)||q.relatedTarget;while(g&&g!=this){try{g=g.parentNode}catch(q){g=this}}if(g==this){if(a.browser.mozilla){if(q.type=="mouseout"){f.mtout=setTimeout(function(){k(q,f)},30)}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}}}return}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}k(q,f)}};var k=function(p,f){var g=jQuery.extend({},p);if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(p.type=="mouseover"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},m.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery); 5 6 jQuery(document).ready(function($){ 7 var refresh = function(i, el){ // force the browser to refresh the tabbing index 8 var node = $(el), tab = node.attr('tabindex'); 9 if ( tab ) 10 node.attr('tabindex', '0').attr('tabindex', tab); 11 }; 12 13 $('#wpadminbar').removeClass('nojq').removeClass('nojs').find('li.menupop').hoverIntent({ 14 over: function(e){ 15 $(this).addClass('hover'); 16 }, 17 out: function(e){ 18 $(this).removeClass('hover'); 19 }, 20 timeout: 180, 21 sensitivity: 7, 22 interval: 100 23 }); 24 25 $('#wp-admin-bar-get-shortlink').click(function(e){ 26 e.preventDefault(); 27 $(this).addClass('selected').children('.shortlink-input').blur(function(){ 28 $(this).parents('#wp-admin-bar-get-shortlink').removeClass('selected'); 29 }).focus().select(); 30 }); 31 32 $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){ 33 if ( e.which != 13 ) 34 return; 35 36 var target = $(e.target), wrap = target.closest('ab-sub-wrapper'); 37 38 e.stopPropagation(); 39 e.preventDefault(); 40 41 if ( !wrap.length ) 42 wrap = $('#wpadminbar .quicklinks'); 43 44 wrap.find('.menupop').removeClass('hover'); 45 target.parent().toggleClass('hover'); 46 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); 47 }).each(refresh); 48 49 $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){ 50 if ( e.which != 27 ) 51 return; 52 53 var target = $(e.target); 54 55 e.stopPropagation(); 56 e.preventDefault(); 57 58 target.closest('.hover').removeClass('hover').children('.ab-item').focus(); 59 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh); 60 }); 61 62 $('#wpadminbar').click( function(e) { 63 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) 64 return; 65 66 e.preventDefault(); 67 $('html, body').animate({ scrollTop: 0 }, 'fast'); 68 }); 69 70 }); 71 } else { 72 (function(d, w) { 73 var addEvent = function( obj, type, fn ) { 74 if (obj.addEventListener) 75 obj.addEventListener(type, fn, false); 76 else if (obj.attachEvent) 77 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);}); 78 }, 79 80 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [], 81 rselected = new RegExp('\\bselected\\b', 'g'), 82 83 /** 84 * Get the timeout ID of the given element 85 */ 86 getTOID = function(el) { 87 var i = q.length; 88 while( i-- ) 89 if ( q[i] && el == q[i][1] ) 90 return q[i][0]; 91 return false; 92 }, 93 94 addHoverClass = function(t) { 95 var i, id, inA, hovering, ul, li, 96 ancestors = [], 97 ancestorLength = 0; 98 99 while ( t && t != aB && t != d ) { 100 if( 'LI' == t.nodeName.toUpperCase() ) { 101 ancestors[ ancestors.length ] = t; 102 id = getTOID(t); 103 if ( id ) 104 clearTimeout( id ); 105 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover'; 106 hovering = t; 107 } 108 t = t.parentNode; 109 } 110 111 // Remove any selected classes. 112 if ( hovering && hovering.parentNode ) { 113 ul = hovering.parentNode; 114 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) { 115 i = ul.childNodes.length; 116 while ( i-- ) { 117 li = ul.childNodes[i]; 118 if ( li != hovering ) 119 li.className = li.className ? li.className.replace( rselected, '' ) : ''; 120 } 121 } 122 } 123 124 /* remove the hover class for any objects not in the immediate element's ancestry */ 125 i = q.length; 126 while ( i-- ) { 127 inA = false; 128 ancestorLength = ancestors.length; 129 while( ancestorLength-- ) { 130 if ( ancestors[ ancestorLength ] == q[i][1] ) 131 inA = true; 132 } 133 134 if ( ! inA ) 135 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : ''; 136 } 137 }, 138 139 removeHoverClass = function(t) { 140 while ( t && t != aB && t != d ) { 141 if( 'LI' == t.nodeName.toUpperCase() ) { 142 (function(t) { 143 var to = setTimeout(function() { 144 t.className = t.className ? t.className.replace(hc, '') : ''; 145 }, 500); 146 q[q.length] = [to, t]; 147 })(t); 148 } 149 t = t.parentNode; 150 } 151 }, 152 153 clickShortlink = function(e) { 154 var i, l, node, 155 t = e.target || e.srcElement; 156 157 // Make t the shortlink menu item, or return. 158 while ( true ) { 159 // Check if we've gone past the shortlink node, 160 // or if the user is clicking on the input. 161 if ( ! t || t == d || t == aB ) 162 return; 163 // Check if we've found the shortlink node. 164 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' ) 165 break; 166 t = t.parentNode; 167 } 168 169 // IE doesn't support preventDefault, and does support returnValue 170 if ( e.preventDefault ) 171 e.preventDefault(); 172 e.returnValue = false; 173 174 if ( -1 == t.className.indexOf('selected') ) 175 t.className += ' selected'; 176 177 for ( i = 0, l = t.childNodes.length; i < l; i++ ) { 178 node = t.childNodes[i]; 179 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) { 180 node.focus(); 181 node.select(); 182 node.onblur = function() { 183 t.className = t.className ? t.className.replace( rselected, '' ) : ''; 184 }; 185 break; 186 } 187 } 188 return false; 189 }, 190 191 scrollToTop = function(t) { 192 var distance, speed, step, steps, timer, speed_step; 193 194 // Ensure that the #wpadminbar was the target of the click. 195 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' ) 196 return; 197 198 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; 199 200 if ( distance < 1 ) 201 return; 202 203 speed_step = distance > 800 ? 130 : 100; 204 speed = Math.min( 12, Math.round( distance / speed_step ) ); 205 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 ); 206 steps = []; 207 timer = 0; 208 209 // Animate scrolling to the top of the page by generating steps to 210 // the top of the page and shifting to each step at a set interval. 211 while ( distance ) { 212 distance -= step; 213 if ( distance < 0 ) 214 distance = 0; 215 steps.push( distance ); 216 217 setTimeout( function() { 218 window.scrollTo( 0, steps.shift() ); 219 }, timer * speed ); 220 221 timer++; 222 } 223 }; 224 225 addEvent(w, 'load', function() { 226 aB = d.getElementById('wpadminbar'); 227 228 if ( d.body && aB ) { 229 d.body.appendChild( aB ); 230 231 if ( aB.className ) 232 aB.className = aB.className.replace(/nojs/, ''); 233 234 addEvent(aB, 'mouseover', function(e) { 235 addHoverClass( e.target || e.srcElement ); 236 }); 237 238 addEvent(aB, 'mouseout', function(e) { 239 removeHoverClass( e.target || e.srcElement ); 240 }); 241 242 addEvent(aB, 'click', clickShortlink ); 243 244 addEvent(aB, 'click', function(e) { 245 scrollToTop( e.target || e.srcElement ); 246 }); 247 } 248 249 if ( w.location.hash ) 250 w.scrollBy(0,-32); 251 }); 252 })(document, window); 253 254 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |