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