1 var showNotice, adminMenu, columns, validateForm, screenMeta, autofold_menu;
4 // (perhaps) needed for back-compat
8 restoreMenuState : function() {},
9 toggle : function() {},
10 favorites : function() {}
13 // show/hide/save table columns
17 $('.hide-column-tog', '#adv-settings').click( function() {
18 var $t = $(this), column = $t.val();
19 if ( $t.prop('checked') )
22 that.unchecked(column);
24 columns.saveManageColumnsState();
28 saveManageColumnsState : function() {
29 var hidden = this.hidden();
31 action: 'hidden-columns',
33 screenoptionnonce: $('#screenoptionnonce').val(),
38 checked : function(column) {
39 $('.column-' + column).show();
40 this.colSpanChange(+1);
43 unchecked : function(column) {
44 $('.column-' + column).hide();
45 this.colSpanChange(-1);
49 return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
52 useCheckboxesForHidden : function() {
53 this.hidden = function(){
54 return $('.hide-column-tog').not(':checked').map(function() {
56 return id.substring( id, id.length - 5 );
61 colSpanChange : function(diff) {
62 var $t = $('table').find('.colspanchange'), n;
65 n = parseInt( $t.attr('colspan'), 10 ) + diff;
66 $t.attr('colspan', n.toString());
70 $(document).ready(function(){columns.init();});
72 validateForm = function( form ) {
73 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();
76 // stub for doing better warnings
79 var msg = commonL10n.warnDelete || '';
87 note : function(text) {
93 element: null, // #screen-meta
94 toggles: null, // .screen-meta-toggle
95 page: null, // #wpcontent
98 this.element = $('#screen-meta');
99 this.toggles = $('.screen-meta-toggle a');
100 this.page = $('#wpcontent');
102 this.toggles.click( this.toggleEvent );
105 toggleEvent: function( e ) {
106 var panel = $( this.href.replace(/.+#/, '#') );
112 if ( panel.is(':visible') )
113 screenMeta.close( panel, $(this) );
115 screenMeta.open( panel, $(this) );
118 open: function( panel, link ) {
120 $('.screen-meta-toggle').not( link.parent() ).css('visibility', 'hidden');
122 panel.parent().show();
123 panel.slideDown( 'fast', function() {
124 link.addClass('screen-meta-active');
128 close: function( panel, link ) {
129 panel.slideUp( 'fast', function() {
130 link.removeClass('screen-meta-active');
131 $('.screen-meta-toggle').css('visibility', '');
132 panel.parent().hide();
140 $('.contextual-help-tabs').delegate('a', 'click focus', function(e) {
146 // Don't do anything if the click is for the tab already showing.
147 if ( link.is('.active a') )
151 $('.contextual-help-tabs .active').removeClass('active');
152 link.parent('li').addClass('active');
154 panel = $( link.attr('href') );
157 $('.help-tab-content').not( panel ).removeClass('active').hide();
158 panel.addClass('active').show();
161 $(document).ready( function() {
162 var lastClicked = false, checks, first, last, checked, menu = $('#adminmenu'),
163 pageInput = $('input.current-page'), currentPage = pageInput.val(), folded, refresh;
166 refresh = function(i, el){ // force the browser to refresh the tabbing index
167 var node = $(el), tab = node.attr('tabindex');
169 node.attr('tabindex', '0').attr('tabindex', tab);
172 $('#collapse-menu', menu).click(function(){
173 var body = $(document.body);
175 if ( body.hasClass('folded') ) {
176 body.removeClass('folded');
177 setUserSetting('mfold', 'o');
179 body.addClass('folded');
180 setUserSetting('mfold', 'f');
185 $('li.wp-has-submenu', menu).hoverIntent({
187 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop;
189 if ( !$(document.body).hasClass('folded') && $(this).hasClass('wp-menu-open') )
192 menutop = $(this).offset().top;
193 wintop = $(window).scrollTop();
194 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
196 b = menutop + m.height() + 1; // Bottom offset of the menu
197 h = $('#wpwrap').height(); // Height of the entire page
199 f = $(window).height() + wintop - 15; // The fold
208 m.css({'marginTop':'-'+o+'px'});
209 else if ( m.css('marginTop') )
210 m.css({'marginTop':''});
212 menu.find('.wp-submenu').removeClass('sub-open');
213 m.addClass('sub-open');
216 $(this).find('.wp-submenu').removeClass('sub-open');
223 // Tab to select, Enter to open sub, Esc to close sub and focus the top menu
224 $('li.wp-has-submenu > a.wp-not-current-submenu', menu).bind('keydown.adminmenu', function(e){
228 var target = $(e.target);
233 menu.find('.wp-submenu').removeClass('sub-open');
234 target.siblings('.wp-submenu').toggleClass('sub-open').find('a[role="menuitem"]').each(refresh);
237 $('a[role="menuitem"]', menu).bind('keydown.adminmenu', function(e){
241 var target = $(e.target);
246 target.add( target.siblings() ).closest('.sub-open').removeClass('sub-open').siblings('a.wp-not-current-submenu').focus();
249 // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
250 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
251 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
256 // check all checkboxes
257 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
258 if ( 'undefined' == e.shiftKey ) { return true; }
260 if ( !lastClicked ) { return true; }
261 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
262 first = checks.index( lastClicked );
263 last = checks.index( this );
264 checked = $(this).prop('checked');
265 if ( 0 < first && 0 < last && first != last ) {
266 checks.slice( first, last ).prop( 'checked', function(){
267 if ( $(this).closest('tr').is(':visible') )
278 $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
279 var c = $(this).prop('checked'),
280 kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
281 toggle = e.shiftKey || kbtoggle;
283 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
284 .children().children('.check-column').find(':checkbox')
285 .prop('checked', function() {
286 if ( $(this).closest('tr').is(':hidden') )
289 return $(this).prop( 'checked' );
295 $(this).closest('table').children('thead, tfoot').filter(':visible')
296 .children().children('.check-column').find(':checkbox')
297 .prop('checked', function() {
306 $('#default-password-nag-no').click( function() {
307 setUserSetting('default_password_nag', 'hide');
308 $('div.default-password-nag').hide();
313 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
314 if ( e.keyCode != 9 )
317 var el = e.target, selStart = el.selectionStart, selEnd = el.selectionEnd, val = el.value, scroll, sel;
320 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
323 if ( document.selection ) {
325 sel = document.selection.createRange();
327 } else if ( selStart >= 0 ) {
328 scroll = this.scrollTop;
329 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
330 el.selectionStart = el.selectionEnd = selStart + 1;
331 this.scrollTop = scroll;
334 if ( e.stopPropagation )
336 if ( e.preventDefault )
340 $('#newcontent').bind('blur.wpevent_InsertTab', function(e) {
341 if ( this.lastKey && 9 == this.lastKey )
345 if ( pageInput.length ) {
346 pageInput.closest('form').submit( function(e){
348 // Reset paging var for new filters/searches but not for bulk actions. See #17685.
349 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
354 // auto-fold the menu when screen is under 800px
355 $(window).bind('resize.autofold', function(){
356 if ( getUserSetting('mfold') == 'f' )
359 var width = $(window).width();
362 if ( width <= 800 ) {
364 $(document.body).addClass('folded');
369 $(document.body).removeClass('folded');
374 }).triggerHandler('resize');
379 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
380 if ( typeof(data.cb) != 'function' )
383 if ( typeof(data.condition) != 'function' || data.condition() )