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 ), respWidth;
174 // reset any compensation for submenus near the bottom of the screen
175 $('#adminmenu div.wp-submenu').css('margin-top', '');
177 // WebKit excludes the width of the vertical scrollbar when applying the CSS "@media screen and (max-width: ...)"
178 // and matches $(window).width().
179 // Firefox and IE > 8 include the scrollbar width, so after the jQuery normalization
180 // $(window).width() is 884px but window.innerWidth is 900px.
181 // (using window.innerWidth also excludes IE < 9)
182 respWidth = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $(window).width() : window.innerWidth;
184 if ( respWidth && respWidth < 900 ) {
185 if ( body.hasClass('auto-fold') ) {
186 body.removeClass('auto-fold').removeClass('folded');
187 setUserSetting('unfold', 1);
188 setUserSetting('mfold', 'o');
190 body.addClass('auto-fold');
191 setUserSetting('unfold', 0);
194 if ( body.hasClass('folded') ) {
195 body.removeClass('folded');
196 setUserSetting('mfold', 'o');
198 body.addClass('folded');
199 setUserSetting('mfold', 'f');
204 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
205 // iOS Safari works with touchstart, the rest work with click
206 mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
208 // close any open submenus when touch/click is not on the menu
209 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
210 if ( !$(e.target).closest('#adminmenu').length )
211 menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
214 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) {
215 var el = $(this), parent = el.parent();
217 // Show the sub instead of following the link if:
218 // - the submenu is not open
219 // - the submenu is not shown inline or the menu is not folded
220 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) {
222 menu.find('li.opensub').removeClass('opensub');
223 parent.addClass('opensub');
228 menu.find('li.wp-has-submenu').hoverIntent({
230 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
232 if ( isNaN(top) || top > -5 ) // meaning the submenu is visible
235 menutop = $(this).offset().top;
236 wintop = $(window).scrollTop();
237 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
239 b = menutop + m.height() + 1; // Bottom offset of the menu
240 h = $('#wpwrap').height(); // Height of the entire page
242 f = $(window).height() + wintop - 15; // The fold
251 m.css('margin-top', '-'+o+'px');
253 m.css('margin-top', '');
255 menu.find('li.menu-top').removeClass('opensub');
256 $(this).addClass('opensub');
259 $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
266 menu.on('focus.adminmenu', '.wp-submenu a', function(e){
267 $(e.target).closest('li.menu-top').addClass('opensub');
268 }).on('blur.adminmenu', '.wp-submenu a', function(e){
269 $(e.target).closest('li.menu-top').removeClass('opensub');
272 // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
273 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
274 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
279 // check all checkboxes
280 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
281 if ( 'undefined' == e.shiftKey ) { return true; }
283 if ( !lastClicked ) { return true; }
284 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
285 first = checks.index( lastClicked );
286 last = checks.index( this );
287 checked = $(this).prop('checked');
288 if ( 0 < first && 0 < last && first != last ) {
289 checks.slice( first, last ).prop( 'checked', function(){
290 if ( $(this).closest('tr').is(':visible') )
299 // toggle "check all" checkboxes
300 var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
301 $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
302 return ( 0 == unchecked.length );
308 $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
309 var c = $(this).prop('checked'),
310 kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
311 toggle = e.shiftKey || kbtoggle;
313 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
314 .children().children('.check-column').find(':checkbox')
315 .prop('checked', function() {
316 if ( $(this).is(':hidden') )
319 return $(this).prop( 'checked' );
325 $(this).closest('table').children('thead, tfoot').filter(':visible')
326 .children().children('.check-column').find(':checkbox')
327 .prop('checked', function() {
336 $('#default-password-nag-no').click( function() {
337 setUserSetting('default_password_nag', 'hide');
338 $('div.default-password-nag').hide();
343 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
344 var el = e.target, selStart, selEnd, val, scroll, sel;
346 if ( e.keyCode == 27 ) { // escape key
347 $(el).data('tab-out', true);
351 if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
354 if ( $(el).data('tab-out') ) {
355 $(el).data('tab-out', false);
359 selStart = el.selectionStart;
360 selEnd = el.selectionEnd;
364 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
367 if ( document.selection ) {
369 sel = document.selection.createRange();
371 } else if ( selStart >= 0 ) {
372 scroll = this.scrollTop;
373 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
374 el.selectionStart = el.selectionEnd = selStart + 1;
375 this.scrollTop = scroll;
378 if ( e.stopPropagation )
380 if ( e.preventDefault )
384 $('#newcontent').bind('blur.wpevent_InsertTab', function(e) {
385 if ( this.lastKey && 9 == this.lastKey )
389 if ( pageInput.length ) {
390 pageInput.closest('form').submit( function(e){
392 // Reset paging var for new filters/searches but not for bulk actions. See #17685.
393 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
398 // Scroll into view when focused
399 $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
400 if ( e.target.scrollIntoView )
401 e.target.scrollIntoView(false);
404 // Disable upload buttons until files are selected
406 var button, input, form = $('form.wp-upload-form');
409 button = form.find('input[type="submit"]');
410 input = form.find('input[type="file"]');
412 function toggleUploadButton() {
413 button.prop('disabled', '' === input.map( function() {
414 return $(this).val();
417 toggleUploadButton();
418 input.on('change', toggleUploadButton);
423 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
424 if ( typeof(data.cb) != 'function' )
427 if ( typeof(data.condition) != 'function' || data.condition() )