]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/admin-bar.dev.js
Wordpress 3.3
[autoinstalls/wordpress.git] / wp-includes / js / admin-bar.dev.js
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         });
63 } else {
64         (function(d, w) {
65                 var addEvent = function( obj, type, fn ) {
66                         if (obj.addEventListener)
67                                 obj.addEventListener(type, fn, false);
68                         else if (obj.attachEvent)
69                                 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
70                 },
71
72                 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
73                 rselected = new RegExp('\\bselected\\b', 'g'),
74
75                 /**
76                  * Get the timeout ID of the given element
77                  */
78                 getTOID = function(el) {
79                         var i = q.length;
80                         while( i-- )
81                                 if ( q[i] && el == q[i][1] )
82                                         return q[i][0];
83                         return false;
84                 },
85
86                 addHoverClass = function(t) {
87                         var i, id, inA, hovering, ul, li,
88                                 ancestors = [],
89                                 ancestorLength = 0;
90
91                         while ( t && t != aB && t != d ) {
92                                 if( 'LI' == t.nodeName.toUpperCase() ) {
93                                         ancestors[ ancestors.length ] = t;
94                                         id = getTOID(t);
95                                         if ( id )
96                                                 clearTimeout( id );
97                                         t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover';
98                                         hovering = t;
99                                 }
100                                 t = t.parentNode;
101                         }
102
103                         // Remove any selected classes.
104                         if ( hovering && hovering.parentNode ) {
105                                 ul = hovering.parentNode;
106                                 if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
107                                         i = ul.childNodes.length;
108                                         while ( i-- ) {
109                                                 li = ul.childNodes[i];
110                                                 if ( li != hovering )
111                                                         li.className = li.className ? li.className.replace( rselected, '' ) : '';
112                                         }
113                                 }
114                         }
115
116                         /* remove the hover class for any objects not in the immediate element's ancestry */
117                         i = q.length;
118                         while ( i-- ) {
119                                 inA = false;
120                                 ancestorLength = ancestors.length;
121                                 while( ancestorLength-- ) {
122                                         if ( ancestors[ ancestorLength ] == q[i][1] )
123                                                 inA = true;
124                                 }
125
126                                 if ( ! inA )
127                                         q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : '';
128                         }
129                 },
130
131                 removeHoverClass = function(t) {
132                         while ( t && t != aB && t != d ) {
133                                 if( 'LI' == t.nodeName.toUpperCase() ) {
134                                         (function(t) {
135                                                 var to = setTimeout(function() {
136                                                         t.className = t.className ? t.className.replace(hc, '') : '';
137                                                 }, 500);
138                                                 q[q.length] = [to, t];
139                                         })(t);
140                                 }
141                                 t = t.parentNode;
142                         }
143                 },
144
145                 clickShortlink = function(e) {
146                         var i, l, node,
147                                 t = e.target || e.srcElement;
148
149                         // Make t the shortlink menu item, or return.
150                         while ( true ) {
151                                 // Check if we've gone past the shortlink node,
152                                 // or if the user is clicking on the input.
153                                 if ( ! t || t == d || t == aB )
154                                         return;
155                                 // Check if we've found the shortlink node.
156                                 if ( t.id && t.id == 'wp-admin-bar-get-shortlink' )
157                                         break;
158                                 t = t.parentNode;
159                         }
160
161                         // IE doesn't support preventDefault, and does support returnValue
162                         if ( e.preventDefault )
163                                 e.preventDefault();
164                         e.returnValue = false;
165
166                         if ( -1 == t.className.indexOf('selected') )
167                                 t.className += ' selected';
168
169                         for ( i = 0, l = t.childNodes.length; i < l; i++ ) {
170                                 node = t.childNodes[i];
171                                 if ( node.className && -1 != node.className.indexOf('shortlink-input') ) {
172                                         node.focus();
173                                         node.select();
174                                         node.onblur = function() {
175                                                 t.className = t.className ? t.className.replace( rselected, '' ) : '';
176                                         };
177                                         break;
178                                 }
179                         }
180                         return false;
181                 };
182
183                 addEvent(w, 'load', function() {
184                         aB = d.getElementById('wpadminbar');
185
186                         if ( d.body && aB ) {
187                                 d.body.appendChild( aB );
188
189                                 if ( aB.className )
190                                         aB.className = aB.className.replace(/nojs/, '');
191
192                                 addEvent(aB, 'mouseover', function(e) {
193                                         addHoverClass( e.target || e.srcElement );
194                                 });
195
196                                 addEvent(aB, 'mouseout', function(e) {
197                                         removeHoverClass( e.target || e.srcElement );
198                                 });
199
200                                 addEvent(aB, 'click', clickShortlink );
201                         }
202
203                         if ( w.location.hash )
204                                 w.scrollBy(0,-32);
205                 });
206         })(document, window);
207
208 }
209