1 var showNotice, adminMenu, columns, validateForm, screenMeta;
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() {
125 link.addClass('screen-meta-active').attr('aria-expanded', true);
129 close: function( panel, link ) {
130 panel.slideUp( 'fast', function() {
131 link.removeClass('screen-meta-active').attr('aria-expanded', false);
132 $('.screen-meta-toggle').css('visibility', '');
133 panel.parent().hide();
141 $('.contextual-help-tabs').delegate('a', 'click focus', function(e) {
147 // Don't do anything if the click is for the tab already showing.
148 if ( link.is('.active a') )
152 $('.contextual-help-tabs .active').removeClass('active');
153 link.parent('li').addClass('active');
155 panel = $( link.attr('href') );
158 $('.help-tab-content').not( panel ).removeClass('active').hide();
159 panel.addClass('active').show();
162 $(document).ready( function() {
163 var lastClicked = false, checks, first, last, checked, menu = $('#adminmenu'), mobileEvent,
164 pageInput = $('input.current-page'), currentPage = pageInput.val();
166 // when the menu is folded, make the fly-out submenu header clickable
167 menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
168 $(e.target).parent().siblings('a').get(0).click();
171 $('#collapse-menu').on('click.collapse-menu', function(e){
172 var body = $(document.body);
174 // reset any compensation for submenus near the bottom of the screen
175 $('#adminmenu div.wp-submenu').css('margin-top', '');
177 if ( $(window).width() < 900 ) {
178 if ( body.hasClass('auto-fold') ) {
179 body.removeClass('auto-fold');
180 setUserSetting('unfold', 1);
181 body.removeClass('folded');
182 deleteUserSetting('mfold');
184 body.addClass('auto-fold');
185 deleteUserSetting('unfold');
188 if ( body.hasClass('folded') ) {
189 body.removeClass('folded');
190 deleteUserSetting('mfold');
192 body.addClass('folded');
193 setUserSetting('mfold', 'f');
198 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
199 // iOS Safari works with touchstart, the rest work with click
200 mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
202 // close any open submenus when touch/click is not on the menu
203 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
204 if ( !$(e.target).closest('#adminmenu').length )
205 menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
208 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) {
209 var el = $(this), parent = el.parent();
211 // Show the sub instead of following the link if:
212 // - the submenu is not open
213 // - the submenu is not shown inline or the menu is not folded
214 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) {
216 menu.find('li.opensub').removeClass('opensub');
217 parent.addClass('opensub');
222 menu.find('li.wp-has-submenu').hoverIntent({
224 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
226 if ( isNaN(top) || top > -5 ) // meaning the submenu is visible
229 menutop = $(this).offset().top;
230 wintop = $(window).scrollTop();
231 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
233 b = menutop + m.height() + 1; // Bottom offset of the menu
234 h = $('#wpwrap').height(); // Height of the entire page
236 f = $(window).height() + wintop - 15; // The fold
245 m.css('margin-top', '-'+o+'px');
247 m.css('margin-top', '');
249 menu.find('li.menu-top').removeClass('opensub');
250 $(this).addClass('opensub');
253 $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
260 menu.on('focus.adminmenu', '.wp-submenu a', function(e){
261 $(e.target).closest('li.menu-top').addClass('opensub');
262 }).on('blur.adminmenu', '.wp-submenu a', function(e){
263 $(e.target).closest('li.menu-top').removeClass('opensub');
266 // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
267 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
268 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
273 // check all checkboxes
274 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
275 if ( 'undefined' == e.shiftKey ) { return true; }
277 if ( !lastClicked ) { return true; }
278 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
279 first = checks.index( lastClicked );
280 last = checks.index( this );
281 checked = $(this).prop('checked');
282 if ( 0 < first && 0 < last && first != last ) {
283 checks.slice( first, last ).prop( 'checked', function(){
284 if ( $(this).closest('tr').is(':visible') )
293 // toggle "check all" checkboxes
294 var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
295 $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
296 return ( 0 == unchecked.length );
302 $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
303 var c = $(this).prop('checked'),
304 kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
305 toggle = e.shiftKey || kbtoggle;
307 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
308 .children().children('.check-column').find(':checkbox')
309 .prop('checked', function() {
310 if ( $(this).closest('tr').is(':hidden') )
313 return $(this).prop( 'checked' );
319 $(this).closest('table').children('thead, tfoot').filter(':visible')
320 .children().children('.check-column').find(':checkbox')
321 .prop('checked', function() {
330 $('#default-password-nag-no').click( function() {
331 setUserSetting('default_password_nag', 'hide');
332 $('div.default-password-nag').hide();
337 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
338 var el = e.target, selStart, selEnd, val, scroll, sel;
340 if ( e.keyCode == 27 ) { // escape key
341 $(el).data('tab-out', true);
345 if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
348 if ( $(el).data('tab-out') ) {
349 $(el).data('tab-out', false);
353 selStart = el.selectionStart;
354 selEnd = el.selectionEnd;
358 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
361 if ( document.selection ) {
363 sel = document.selection.createRange();
365 } else if ( selStart >= 0 ) {
366 scroll = this.scrollTop;
367 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
368 el.selectionStart = el.selectionEnd = selStart + 1;
369 this.scrollTop = scroll;
372 if ( e.stopPropagation )
374 if ( e.preventDefault )
378 $('#newcontent').bind('blur.wpevent_InsertTab', function(e) {
379 if ( this.lastKey && 9 == this.lastKey )
383 if ( pageInput.length ) {
384 pageInput.closest('form').submit( function(e){
386 // Reset paging var for new filters/searches but not for bulk actions. See #17685.
387 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
392 // Scroll into view when focused
393 $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
394 if ( e.target.scrollIntoView )
395 e.target.scrollIntoView(false);
398 // Disable upload buttons until files are selected
400 var button, input, form = $('form.wp-upload-form');
403 button = form.find('input[type="submit"]');
404 input = form.find('input[type="file"]');
406 function toggleUploadButton() {
407 button.prop('disabled', '' === input.map( function() {
408 return $(this).val();
411 toggleUploadButton();
412 input.on('change', toggleUploadButton);
417 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
418 if ( typeof(data.cb) != 'function' )
421 if ( typeof(data.condition) != 'function' || data.condition() )