]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/common.dev.js
Wordpress 3.1.4-scripts
[autoinstalls/wordpress.git] / wp-admin / js / common.dev.js
1 var showNotice, adminMenu, columns, validateForm;
2 (function($){
3 // sidebar admin menu
4 adminMenu = {
5         init : function() {
6                 var menu = $('#adminmenu');
7
8                 $('.wp-menu-toggle', menu).each( function() {
9                         var t = $(this), sub = t.siblings('.wp-submenu');
10                         if ( sub.length )
11                                 t.click(function(){ adminMenu.toggle( sub ); });
12                         else
13                                 t.hide();
14                 });
15
16                 this.favorites();
17
18                 $('.separator', menu).click(function(){
19                         if ( $('body').hasClass('folded') ) {
20                                 adminMenu.fold(1);
21                                 deleteUserSetting( 'mfold' );
22                         } else {
23                                 adminMenu.fold();
24                                 setUserSetting( 'mfold', 'f' );
25                         }
26                         return false;
27                 });
28
29                 if ( $('body').hasClass('folded') )
30                         this.fold();
31
32                 this.restoreMenuState();
33         },
34
35         restoreMenuState : function() {
36                 $('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
37                         var v = getUserSetting( 'm'+i );
38                         if ( $(e).hasClass('wp-has-current-submenu') )
39                                 return true; // leave the current parent open
40
41                         if ( 'o' == v )
42                                 $(e).addClass('wp-menu-open');
43                         else if ( 'c' == v )
44                                 $(e).removeClass('wp-menu-open');
45                 });
46         },
47
48         toggle : function(el) {
49                 el.slideToggle(150, function() {
50                         var id = el.parent().toggleClass( 'wp-menu-open' ).attr('id');
51                         if ( id ) {
52                                 $('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
53                                         if ( id == e.id ) {
54                                                 var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
55                                                 setUserSetting( 'm'+i, v );
56                                         }
57                                 });
58                         }
59                 });
60
61                 return false;
62         },
63
64         fold : function(off) {
65                 if (off) {
66                         $('body').removeClass('folded');
67                         $('#adminmenu li.wp-has-submenu').unbind();
68                 } else {
69                         $('body').addClass('folded');
70                         $('#adminmenu li.wp-has-submenu').hoverIntent({
71                                 over: function(e){
72                                         var m, b, h, o, f;
73                                         m = $(this).find('.wp-submenu');
74                                         b = $(this).offset().top + m.height() + 1; // Bottom offset of the menu
75                                         h = $('#wpwrap').height(); // Height of the entire page
76                                         o = 60 + b - h;
77                                         f = $(window).height() + $(window).scrollTop() - 15; // The fold
78                                         if ( f < (b - o) ) {
79                                                 o = b - f;
80                                         }
81                                         if ( o > 1 ) {
82                                                 m.css({'marginTop':'-'+o+'px'});
83                                         } else if ( m.css('marginTop') ) {
84                                                 m.css({'marginTop':''});
85                                         }
86                                         m.addClass('sub-open');
87                                 },
88                                 out: function(){ $(this).find('.wp-submenu').removeClass('sub-open').css({'marginTop':''}); },
89                                 timeout: 220,
90                                 sensitivity: 8,
91                                 interval: 100
92                         });
93
94                 }
95         },
96
97         favorites : function() {
98                 $('#favorite-inside').width( $('#favorite-actions').width() - 4 );
99                 $('#favorite-toggle, #favorite-inside').bind('mouseenter', function() {
100                         $('#favorite-inside').removeClass('slideUp').addClass('slideDown');
101                         setTimeout(function() {
102                                 if ( $('#favorite-inside').hasClass('slideDown') ) {
103                                         $('#favorite-inside').slideDown(100);
104                                         $('#favorite-first').addClass('slide-down');
105                                 }
106                         }, 200);
107                 }).bind('mouseleave', function() {
108                         $('#favorite-inside').removeClass('slideDown').addClass('slideUp');
109                         setTimeout(function() {
110                                 if ( $('#favorite-inside').hasClass('slideUp') ) {
111                                         $('#favorite-inside').slideUp(100, function() {
112                                                 $('#favorite-first').removeClass('slide-down');
113                                         });
114                                 }
115                         }, 300);
116                 });
117         }
118 };
119
120 $(document).ready(function(){ adminMenu.init(); });
121
122 // show/hide/save table columns
123 columns = {
124         init : function() {
125                 var that = this;
126                 $('.hide-column-tog', '#adv-settings').click( function() {
127                         var $t = $(this), column = $t.val();
128                         if ( $t.attr('checked') )
129                                 that.checked(column);
130                         else
131                                 that.unchecked(column);
132
133                         columns.saveManageColumnsState();
134                 });
135         },
136
137         saveManageColumnsState : function() {
138                 var hidden = this.hidden();
139                 $.post(ajaxurl, {
140                         action: 'hidden-columns',
141                         hidden: hidden,
142                         screenoptionnonce: $('#screenoptionnonce').val(),
143                         page: pagenow
144                 });
145         },
146
147         checked : function(column) {
148                 $('.column-' + column).show();
149                 this.colSpanChange(+1);
150         },
151
152         unchecked : function(column) {
153                 $('.column-' + column).hide();
154                 this.colSpanChange(-1);
155         },
156
157         hidden : function() {
158                 return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
159         },
160
161         useCheckboxesForHidden : function() {
162                 this.hidden = function(){
163                         return $('.hide-column-tog').not(':checked').map(function() {
164                                 var id = this.id;
165                                 return id.substring( id, id.length - 5 );
166                         }).get().join(',');
167                 };
168         },
169
170         colSpanChange : function(diff) {
171                 var $t = $('table').find('.colspanchange'), n;
172                 if ( !$t.length )
173                         return;
174                 n = parseInt( $t.attr('colspan'), 10 ) + diff;
175                 $t.attr('colspan', n.toString());
176         }
177 }
178
179 $(document).ready(function(){columns.init();});
180
181 validateForm = function( form ) {
182         return !$( form ).find('.form-required').filter( function() { return $('input:visible', this).val() == ''; } ).addClass( 'form-invalid' ).find('input:visible').change( function() { $(this).closest('.form-invalid').removeClass( 'form-invalid' ); } ).size();
183 }
184
185 })(jQuery);
186
187 // stub for doing better warnings
188 showNotice = {
189         warn : function() {
190                 var msg = commonL10n.warnDelete || '';
191                 if ( confirm(msg) ) {
192                         return true;
193                 }
194
195                 return false;
196         },
197
198         note : function(text) {
199                 alert(text);
200         }
201 };
202
203 jQuery(document).ready( function($) {
204         var lastClicked = false, checks, first, last, checked, bgx = ( isRtl ? 'left' : 'right' );
205
206         // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
207         $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
208         $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
209
210         // screen settings tab
211         $('#show-settings-link').click(function () {
212                 if ( ! $('#screen-options-wrap').hasClass('screen-options-open') )
213                         $('#contextual-help-link-wrap').css('visibility', 'hidden');
214
215                 $('#screen-options-wrap').slideToggle('fast', function(){
216                         if ( $(this).hasClass('screen-options-open') ) {
217                                 $('#show-settings-link').css({'backgroundPosition':'top '+bgx});
218                                 $('#contextual-help-link-wrap').css('visibility', '');
219                                 $(this).removeClass('screen-options-open');
220                         } else {
221                                 $('#show-settings-link').css({'backgroundPosition':'bottom '+bgx});
222                                 $(this).addClass('screen-options-open');
223                         }
224                 });
225                 return false;
226         });
227
228         // help tab
229         $('#contextual-help-link').click(function () {
230                 if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') )
231                         $('#screen-options-link-wrap').css('visibility', 'hidden');
232
233                 $('#contextual-help-wrap').slideToggle('fast', function() {
234                         if ( $(this).hasClass('contextual-help-open') ) {
235                                 $('#contextual-help-link').css({'backgroundPosition':'top '+bgx});
236                                 $('#screen-options-link-wrap').css('visibility', '');
237                                 $(this).removeClass('contextual-help-open');
238                         } else {
239                                 $('#contextual-help-link').css({'backgroundPosition':'bottom '+bgx});
240                                 $(this).addClass('contextual-help-open');
241                         }
242                 });
243                 return false;
244         });
245
246         // check all checkboxes
247         $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
248                 if ( 'undefined' == e.shiftKey ) { return true; }
249                 if ( e.shiftKey ) {
250                         if ( !lastClicked ) { return true; }
251                         checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
252                         first = checks.index( lastClicked );
253                         last = checks.index( this );
254                         checked = $(this).attr('checked');
255                         if ( 0 < first && 0 < last && first != last ) {
256                                 checks.slice( first, last ).attr( 'checked', function(){
257                                         if ( $(this).closest('tr').is(':visible') )
258                                                 return checked ? 'checked' : '';
259
260                                         return '';
261                                 });
262                         }
263                 }
264                 lastClicked = this;
265                 return true;
266         });
267
268         $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
269                 var c = $(this).attr('checked'),
270                         kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
271                         toggle = e.shiftKey || kbtoggle;
272
273                 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
274                 .children().children('.check-column').find(':checkbox')
275                 .attr('checked', function() {
276                         if ( $(this).closest('tr').is(':hidden') )
277                                 return '';
278                         if ( toggle )
279                                 return $(this).attr( 'checked' ) ? '' : 'checked';
280                         else if (c)
281                                 return 'checked';
282                         return '';
283                 });
284
285                 $(this).closest('table').children('thead,  tfoot').filter(':visible')
286                 .children().children('.check-column').find(':checkbox')
287                 .attr('checked', function() {
288                         if ( toggle )
289                                 return '';
290                         else if (c)
291                                 return 'checked';
292                         return '';
293                 });
294         });
295
296         $('#default-password-nag-no').click( function() {
297                 setUserSetting('default_password_nag', 'hide');
298                 $('div.default-password-nag').hide();
299                 return false;
300         });
301
302         // tab in textareas
303         $('#newcontent').keydown(function(e) {
304                 if ( e.keyCode != 9 )
305                         return true;
306
307                 var el = e.target, selStart = el.selectionStart, selEnd = el.selectionEnd, val = el.value, scroll, sel;
308
309                 try {
310                         this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event.  See blur handler below.
311                 } catch(err) {}
312
313                 if ( document.selection ) {
314                         el.focus();
315                         sel = document.selection.createRange();
316                         sel.text = '\t';
317                 } else if ( selStart >= 0 ) {
318                         scroll = this.scrollTop;
319                         el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
320                         el.selectionStart = el.selectionEnd = selStart + 1;
321                         this.scrollTop = scroll;
322                 }
323
324                 if ( e.stopPropagation )
325                         e.stopPropagation();
326                 if ( e.preventDefault )
327                         e.preventDefault();
328         });
329
330         $('#newcontent').blur(function(e) {
331                 if ( this.lastKey && 9 == this.lastKey )
332                         this.focus();
333         });
334 });