wp/wp-admin/js/common.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
       
     1 /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
     1 var showNotice, adminMenu, columns, validateForm, screenMeta;
     2 var showNotice, adminMenu, columns, validateForm, screenMeta;
     2 (function($){
     3 ( function( $, window, undefined ) {
     3 // Removed in 3.3.
     4 // Removed in 3.3.
     4 // (perhaps) needed for back-compat
     5 // (perhaps) needed for back-compat
     5 adminMenu = {
     6 adminMenu = {
     6 	init : function() {},
     7 	init : function() {},
     7 	fold : function() {},
     8 	fold : function() {},
    63 		if ( !$t.length )
    64 		if ( !$t.length )
    64 			return;
    65 			return;
    65 		n = parseInt( $t.attr('colspan'), 10 ) + diff;
    66 		n = parseInt( $t.attr('colspan'), 10 ) + diff;
    66 		$t.attr('colspan', n.toString());
    67 		$t.attr('colspan', n.toString());
    67 	}
    68 	}
    68 }
    69 };
    69 
    70 
    70 $(document).ready(function(){columns.init();});
    71 $(document).ready(function(){columns.init();});
    71 
    72 
    72 validateForm = function( form ) {
    73 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();
    74 	return !$( form )
    74 }
    75 		.find( '.form-required' )
       
    76 		.filter( function() { return $( 'input:visible', this ).val() === ''; } )
       
    77 		.addClass( 'form-invalid' )
       
    78 		.find( 'input:visible' )
       
    79 		.change( function() { $( this ).closest( '.form-invalid' ).removeClass( 'form-invalid' ); } )
       
    80 		.size();
       
    81 };
    75 
    82 
    76 // stub for doing better warnings
    83 // stub for doing better warnings
    77 showNotice = {
    84 showNotice = {
    78 	warn : function() {
    85 	warn : function() {
    79 		var msg = commonL10n.warnDelete || '';
    86 		var msg = commonL10n.warnDelete || '';
   122 		panel.parent().show();
   129 		panel.parent().show();
   123 		panel.slideDown( 'fast', function() {
   130 		panel.slideDown( 'fast', function() {
   124 			panel.focus();
   131 			panel.focus();
   125 			link.addClass('screen-meta-active').attr('aria-expanded', true);
   132 			link.addClass('screen-meta-active').attr('aria-expanded', true);
   126 		});
   133 		});
       
   134 
       
   135 		$( document ).trigger( 'screen:options:open' );
   127 	},
   136 	},
   128 
   137 
   129 	close: function( panel, link ) {
   138 	close: function( panel, link ) {
   130 		panel.slideUp( 'fast', function() {
   139 		panel.slideUp( 'fast', function() {
   131 			link.removeClass('screen-meta-active').attr('aria-expanded', false);
   140 			link.removeClass('screen-meta-active').attr('aria-expanded', false);
   132 			$('.screen-meta-toggle').css('visibility', '');
   141 			$('.screen-meta-toggle').css('visibility', '');
   133 			panel.parent().hide();
   142 			panel.parent().hide();
   134 		});
   143 		});
       
   144 
       
   145 		$( document ).trigger( 'screen:options:close' );
   135 	}
   146 	}
   136 };
   147 };
   137 
   148 
   138 /**
   149 /**
   139  * Help tabs.
   150  * Help tabs.
   140  */
   151  */
   141 $('.contextual-help-tabs').delegate('a', 'click focus', function(e) {
   152 $('.contextual-help-tabs').delegate('a', 'click', function(e) {
   142 	var link = $(this),
   153 	var link = $(this),
   143 		panel;
   154 		panel;
   144 
   155 
   145 	e.preventDefault();
   156 	e.preventDefault();
   146 
   157 
   158 	$('.help-tab-content').not( panel ).removeClass('active').hide();
   169 	$('.help-tab-content').not( panel ).removeClass('active').hide();
   159 	panel.addClass('active').show();
   170 	panel.addClass('active').show();
   160 });
   171 });
   161 
   172 
   162 $(document).ready( function() {
   173 $(document).ready( function() {
   163 	var lastClicked = false, checks, first, last, checked, sliced, menu = $('#adminmenu'), mobileEvent,
   174 	var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, $firstHeading,
   164 		pageInput = $('input.current-page'), currentPage = pageInput.val();
   175 		lastClicked = false,
       
   176 		pageInput = $('input.current-page'),
       
   177 		currentPage = pageInput.val(),
       
   178 		isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
       
   179 		isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
       
   180 		isIE8 = $( document.documentElement ).hasClass( 'ie8' ),
       
   181 		$document = $( document ),
       
   182 		$window = $( window ),
       
   183 		$body = $( document.body ),
       
   184 		$adminMenuWrap = $( '#adminmenuwrap' ),
       
   185 		$wpwrap = $( '#wpwrap' ),
       
   186 		$adminmenu = $( '#adminmenu' ),
       
   187 		$overlay = $( '#wp-responsive-overlay' ),
       
   188 		$toolbar = $( '#wp-toolbar' ),
       
   189 		$toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
       
   190 		$sortables = $('.meta-box-sortables'),
       
   191 		wpResponsiveActive = false,
       
   192 		$adminbar = $( '#wpadminbar' ),
       
   193 		lastScrollPosition = 0,
       
   194 		pinnedMenuTop = false,
       
   195 		pinnedMenuBottom = false,
       
   196 		menuTop = 0,
       
   197 		menuIsPinned = false,
       
   198 		height = {
       
   199 			window: $window.height(),
       
   200 			wpwrap: $wpwrap.height(),
       
   201 			adminbar: $adminbar.height(),
       
   202 			menu: $adminMenuWrap.height()
       
   203 		};
       
   204 
   165 
   205 
   166 	// when the menu is folded, make the fly-out submenu header clickable
   206 	// when the menu is folded, make the fly-out submenu header clickable
   167 	menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
   207 	$adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
   168 		$(e.target).parent().siblings('a').get(0).click();
   208 		$(e.target).parent().siblings('a').get(0).click();
   169 	});
   209 	});
   170 
   210 
   171 	$('#collapse-menu').on('click.collapse-menu', function(e){
   211 	$('#collapse-menu').on('click.collapse-menu', function() {
   172 		var body = $( document.body ), respWidth;
   212 		var body = $( document.body ), respWidth, state;
   173 
   213 
   174 		// reset any compensation for submenus near the bottom of the screen
   214 		// reset any compensation for submenus near the bottom of the screen
   175 		$('#adminmenu div.wp-submenu').css('margin-top', '');
   215 		$('#adminmenu div.wp-submenu').css('margin-top', '');
   176 
   216 
   177 		// WebKit excludes the width of the vertical scrollbar when applying the CSS "@media screen and (max-width: ...)"
   217 		if ( window.innerWidth ) {
   178 		// and matches $(window).width().
   218 			// window.innerWidth is affected by zooming on phones
   179 		// Firefox and IE > 8 include the scrollbar width, so after the jQuery normalization
   219 			respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
   180 		// $(window).width() is 884px but window.innerWidth is 900px.
   220 		} else {
   181 		// (using window.innerWidth also excludes IE < 9)
   221 			// IE < 9 doesn't support @media CSS rules
   182 		respWidth = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $(window).width() : window.innerWidth;
   222 			respWidth = 961;
   183 
   223 		}
   184 		if ( respWidth && respWidth < 900 ) {
   224 
       
   225 		if ( respWidth && respWidth < 960 ) {
   185 			if ( body.hasClass('auto-fold') ) {
   226 			if ( body.hasClass('auto-fold') ) {
   186 				body.removeClass('auto-fold').removeClass('folded');
   227 				body.removeClass('auto-fold').removeClass('folded');
   187 				setUserSetting('unfold', 1);
   228 				setUserSetting('unfold', 1);
   188 				setUserSetting('mfold', 'o');
   229 				setUserSetting('mfold', 'o');
       
   230 				state = 'open';
   189 			} else {
   231 			} else {
   190 				body.addClass('auto-fold');
   232 				body.addClass('auto-fold');
   191 				setUserSetting('unfold', 0);
   233 				setUserSetting('unfold', 0);
       
   234 				state = 'folded';
   192 			}
   235 			}
   193 		} else {
   236 		} else {
   194 			if ( body.hasClass('folded') ) {
   237 			if ( body.hasClass('folded') ) {
   195 				body.removeClass('folded');
   238 				body.removeClass('folded');
   196 				setUserSetting('mfold', 'o');
   239 				setUserSetting('mfold', 'o');
       
   240 				state = 'open';
   197 			} else {
   241 			} else {
   198 				body.addClass('folded');
   242 				body.addClass('folded');
   199 				setUserSetting('mfold', 'f');
   243 				setUserSetting('mfold', 'f');
   200 			}
   244 				state = 'folded';
   201 		}
   245 			}
       
   246 		}
       
   247 
       
   248 		$( document ).trigger( 'wp-collapse-menu', { state: state } );
   202 	});
   249 	});
       
   250 
       
   251 	/**
       
   252 	 * Ensure an admin submenu is within the visual viewport.
       
   253 	 *
       
   254 	 * @since 4.1.0
       
   255 	 *
       
   256 	 * @param {jQuery} $menuItem The parent menu item containing the submenu.
       
   257 	 */
       
   258 	function adjustSubmenu( $menuItem ) {
       
   259 		var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop,
       
   260 			$submenu = $menuItem.find( '.wp-submenu' );
       
   261 
       
   262 		menutop = $menuItem.offset().top;
       
   263 		wintop = $window.scrollTop();
       
   264 		maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
       
   265 
       
   266 		bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu
       
   267 		pageHeight = $wpwrap.height(); // Height of the entire page
       
   268 		adjustment = 60 + bottomOffset - pageHeight;
       
   269 		theFold = $window.height() + wintop - 50; // The fold
       
   270 
       
   271 		if ( theFold < ( bottomOffset - adjustment ) ) {
       
   272 			adjustment = bottomOffset - theFold;
       
   273 		}
       
   274 
       
   275 		if ( adjustment > maxtop ) {
       
   276 			adjustment = maxtop;
       
   277 		}
       
   278 
       
   279 		if ( adjustment > 1 ) {
       
   280 			$submenu.css( 'margin-top', '-' + adjustment + 'px' );
       
   281 		} else {
       
   282 			$submenu.css( 'margin-top', '' );
       
   283 		}
       
   284 	}
   203 
   285 
   204 	if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
   286 	if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
   205 		// iOS Safari works with touchstart, the rest work with click
   287 		// iOS Safari works with touchstart, the rest work with click
   206 		mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
   288 		mobileEvent = isIOS ? 'touchstart' : 'click';
   207 
   289 
   208 		// close any open submenus when touch/click is not on the menu
   290 		// close any open submenus when touch/click is not on the menu
   209 		$(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
   291 		$(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
   210 			if ( !$(e.target).closest('#adminmenu').length )
   292 			if ( $adminmenu.data('wp-responsive') ) {
   211 				menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
   293 				return;
   212 		});
   294 			}
   213 
   295 
   214 		menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) {
   296 			if ( ! $( e.target ).closest( '#adminmenu' ).length ) {
   215 			var el = $(this), parent = el.parent();
   297 				$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
       
   298 			}
       
   299 		});
       
   300 
       
   301 		$adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) {
       
   302 			var $menuItem = $(this).parent();
       
   303 
       
   304 			if ( $adminmenu.data( 'wp-responsive' ) ) {
       
   305 				return;
       
   306 			}
   216 
   307 
   217 			// Show the sub instead of following the link if:
   308 			// Show the sub instead of following the link if:
   218 			//	- the submenu is not open
   309 			//	- the submenu is not open
   219 			//	- the submenu is not shown inline or the menu is not folded
   310 			//	- 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 ) ) {
   311 			if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) {
   221 				e.preventDefault();
   312 				event.preventDefault();
   222 				menu.find('li.opensub').removeClass('opensub');
   313 				adjustSubmenu( $menuItem );
   223 				parent.addClass('opensub');
   314 				$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
   224 			}
   315 				$menuItem.addClass('opensub');
   225 		});
   316 			}
   226 	}
   317 		});
   227 
   318 	}
   228 	menu.find('li.wp-has-submenu').hoverIntent({
   319 
   229 		over: function(e){
   320 	if ( ! isIOS && ! isAndroid ) {
   230 			var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
   321 		$adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({
   231 
   322 			over: function() {
   232 			if ( isNaN(top) || top > -5 ) // meaning the submenu is visible
   323 				var $menuItem = $( this ),
       
   324 					$submenu = $menuItem.find( '.wp-submenu' ),
       
   325 					top = parseInt( $submenu.css( 'top' ), 10 );
       
   326 
       
   327 				if ( isNaN( top ) || top > -5 ) { // the submenu is visible
       
   328 					return;
       
   329 				}
       
   330 
       
   331 				if ( $adminmenu.data( 'wp-responsive' ) ) {
       
   332 					// The menu is in responsive mode, bail
       
   333 					return;
       
   334 				}
       
   335 
       
   336 				adjustSubmenu( $menuItem );
       
   337 				$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' );
       
   338 				$menuItem.addClass( 'opensub' );
       
   339 			},
       
   340 			out: function(){
       
   341 				if ( $adminmenu.data( 'wp-responsive' ) ) {
       
   342 					// The menu is in responsive mode, bail
       
   343 					return;
       
   344 				}
       
   345 
       
   346 				$( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' );
       
   347 			},
       
   348 			timeout: 200,
       
   349 			sensitivity: 7,
       
   350 			interval: 90
       
   351 		});
       
   352 
       
   353 		$adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) {
       
   354 			if ( $adminmenu.data( 'wp-responsive' ) ) {
       
   355 				// The menu is in responsive mode, bail
   233 				return;
   356 				return;
   234 
   357 			}
   235 			menutop = $(this).offset().top;
   358 
   236 			wintop = $(window).scrollTop();
   359 			$( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' );
   237 			maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
   360 		}).on( 'blur.adminmenu', '.wp-submenu a', function( event ) {
   238 
   361 			if ( $adminmenu.data( 'wp-responsive' ) ) {
   239 			b = menutop + m.height() + 1; // Bottom offset of the menu
   362 				return;
   240 			h = $('#wpwrap').height(); // Height of the entire page
   363 			}
   241 			o = 60 + b - h;
   364 
   242 			f = $(window).height() + wintop - 15; // The fold
   365 			$( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' );
   243 
   366 		}).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() {
   244 			if ( f < (b - o) )
   367 			adjustSubmenu( $( this ) );
   245 				o = b - f;
   368 		});
   246 
   369 	}
   247 			if ( o > maxtop )
   370 
   248 				o = maxtop;
   371 	// Move .notice, .updated and .error alert boxes. Don't move boxes designed to be inline.
   249 
   372 	$firstHeading = $( 'div.wrap h2:first' );
   250 			if ( o > 1 )
   373 	$firstHeading.nextAll( 'div.updated, div.error, div.notice' ).addClass( 'below-h2' );
   251 				m.css('margin-top', '-'+o+'px');
   374 	$( 'div.updated, div.error, div.notice' ).not( '.below-h2, .inline' ).insertAfter( $firstHeading );
   252 			else
   375 
   253 				m.css('margin-top', '');
   376 	// Make notices dismissible
   254 
   377 	$( '.notice.is-dismissible' ).each( function() {
   255 			menu.find('li.menu-top').removeClass('opensub');
   378 		var $this = $( this ),
   256 			$(this).addClass('opensub');
   379 			$button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
   257 		},
   380 			btnText = commonL10n.dismiss || '';
   258 		out: function(){
   381 
   259 			$(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
   382 		// Ensure plain text
   260 		},
   383 		$button.find( '.screen-reader-text' ).text( btnText );
   261 		timeout: 200,
   384 
   262 		sensitivity: 7,
   385 		$this.append( $button );
   263 		interval: 90
   386 
       
   387 		$button.on( 'click.wp-dismiss-notice', function( event ) {
       
   388 			event.preventDefault();
       
   389 			$this.fadeTo( 100 , 0, function() {
       
   390 				$(this).slideUp( 100, function() {
       
   391 					$(this).remove();
       
   392 				});
       
   393 			});
       
   394 		});
   264 	});
   395 	});
   265 
       
   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');
       
   270 	});
       
   271 
       
   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') );
       
   275 
   396 
   276 	// Init screen meta
   397 	// Init screen meta
   277 	screenMeta.init();
   398 	screenMeta.init();
   278 
   399 
   279 	// check all checkboxes
   400 	// check all checkboxes
   298 		lastClicked = this;
   419 		lastClicked = this;
   299 
   420 
   300 		// toggle "check all" checkboxes
   421 		// toggle "check all" checkboxes
   301 		var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
   422 		var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
   302 		$(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
   423 		$(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
   303 			return ( 0 == unchecked.length );
   424 			return ( 0 === unchecked.length );
   304 		});
   425 		});
   305 
   426 
   306 		return true;
   427 		return true;
   307 	});
   428 	});
   308 
   429 
   309 	$('thead, tfoot').find('.check-column :checkbox').click( function(e) {
   430 	$('thead, tfoot').find('.check-column :checkbox').on( 'click.wp-toggle-checkboxes', function( event ) {
   310 		var c = $(this).prop('checked'),
   431 		var $this = $(this),
   311 			kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
   432 			$table = $this.closest( 'table' ),
   312 			toggle = e.shiftKey || kbtoggle;
   433 			controlChecked = $this.prop('checked'),
   313 
   434 			toggle = event.shiftKey || $this.data('wp-toggle');
   314 		$(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
   435 
   315 		.children().children('.check-column').find(':checkbox')
   436 		$table.children( 'tbody' ).filter(':visible')
   316 		.prop('checked', function() {
   437 			.children().children('.check-column').find(':checkbox')
   317 			if ( $(this).is(':hidden') )
   438 			.prop('checked', function() {
       
   439 				if ( $(this).is(':hidden') ) {
       
   440 					return false;
       
   441 				}
       
   442 
       
   443 				if ( toggle ) {
       
   444 					return ! $(this).prop( 'checked' );
       
   445 				} else if ( controlChecked ) {
       
   446 					return true;
       
   447 				}
       
   448 
   318 				return false;
   449 				return false;
   319 			if ( toggle )
   450 			});
   320 				return $(this).prop( 'checked' );
   451 
   321 			else if (c)
   452 		$table.children('thead,  tfoot').filter(':visible')
   322 				return true;
   453 			.children().children('.check-column').find(':checkbox')
   323 			return false;
   454 			.prop('checked', function() {
   324 		});
   455 				if ( toggle ) {
   325 
   456 					return false;
   326 		$(this).closest('table').children('thead,  tfoot').filter(':visible')
   457 				} else if ( controlChecked ) {
   327 		.children().children('.check-column').find(':checkbox')
   458 					return true;
   328 		.prop('checked', function() {
   459 				}
   329 			if ( toggle )
   460 
   330 				return false;
   461 				return false;
   331 			else if (c)
   462 			});
   332 				return true;
       
   333 			return false;
       
   334 		});
       
   335 	});
   463 	});
   336 
   464 
   337 	// Show row actions on keyboard focus of its parent container element or any other elements contained within
   465 	// Show row actions on keyboard focus of its parent container element or any other elements contained within
   338 	var transitionTimeout, focusedRowActions;
   466 	$( '#wpbody-content' ).on({
   339 	$( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){
   467 		focusin: function() {
   340 		clearTimeout( transitionTimeout );
   468 			clearTimeout( transitionTimeout );
   341 		focusedRowActions = $(this).find( '.row-actions' );
   469 			focusedRowActions = $( this ).find( '.row-actions' );
   342 		focusedRowActions.addClass( 'visible' );
   470 			// transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
   343 	}).focusout(function(){
   471 			$( '.row-actions' ).not( this ).removeClass( 'visible' );
   344 		// Tabbing between post title and .row-actions links needs a brief pause, otherwise
   472 			focusedRowActions.addClass( 'visible' );
   345 		// the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
   473 		},
   346 		transitionTimeout = setTimeout(function(){
   474 		focusout: function() {
   347 			focusedRowActions.removeClass( 'visible' );
   475 			// Tabbing between post title and .row-actions links needs a brief pause, otherwise
   348 		}, 30);
   476 			// the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
   349 	});
   477 			transitionTimeout = setTimeout( function() {
       
   478 				focusedRowActions.removeClass( 'visible' );
       
   479 			}, 30 );
       
   480 		}
       
   481 	}, 'td.post-title, td.title, td.comment, .tags td.column-name, .bookmarks td.column-name, td.blogname, .users-network td.column-blogs, td.username, .dashboard-comment-wrap' );
   350 
   482 
   351 	$('#default-password-nag-no').click( function() {
   483 	$('#default-password-nag-no').click( function() {
   352 		setUserSetting('default_password_nag', 'hide');
   484 		setUserSetting('default_password_nag', 'hide');
   353 		$('div.default-password-nag').hide();
   485 		$('div.default-password-nag').hide();
   354 		return false;
   486 		return false;
   357 	// tab in textareas
   489 	// tab in textareas
   358 	$('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
   490 	$('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
   359 		var el = e.target, selStart, selEnd, val, scroll, sel;
   491 		var el = e.target, selStart, selEnd, val, scroll, sel;
   360 
   492 
   361 		if ( e.keyCode == 27 ) { // escape key
   493 		if ( e.keyCode == 27 ) { // escape key
       
   494 			// when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them
       
   495 			e.preventDefault();
   362 			$(el).data('tab-out', true);
   496 			$(el).data('tab-out', true);
   363 			return;
   497 			return;
   364 		}
   498 		}
   365 
   499 
   366 		if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
   500 		if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
   372 		}
   506 		}
   373 
   507 
   374 		selStart = el.selectionStart;
   508 		selStart = el.selectionStart;
   375 		selEnd = el.selectionEnd;
   509 		selEnd = el.selectionEnd;
   376 		val = el.value;
   510 		val = el.value;
   377 
       
   378 		try {
       
   379 			this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
       
   380 		} catch(err) {}
       
   381 
   511 
   382 		if ( document.selection ) {
   512 		if ( document.selection ) {
   383 			el.focus();
   513 			el.focus();
   384 			sel = document.selection.createRange();
   514 			sel = document.selection.createRange();
   385 			sel.text = '\t';
   515 			sel.text = '\t';
   394 			e.stopPropagation();
   524 			e.stopPropagation();
   395 		if ( e.preventDefault )
   525 		if ( e.preventDefault )
   396 			e.preventDefault();
   526 			e.preventDefault();
   397 	});
   527 	});
   398 
   528 
   399 	$('#newcontent').bind('blur.wpevent_InsertTab', function(e) {
       
   400 		if ( this.lastKey && 9 == this.lastKey )
       
   401 			this.focus();
       
   402 	});
       
   403 
       
   404 	if ( pageInput.length ) {
   529 	if ( pageInput.length ) {
   405 		pageInput.closest('form').submit( function(e){
   530 		pageInput.closest('form').submit( function() {
   406 
   531 
   407 			// Reset paging var for new filters/searches but not for bulk actions. See #17685.
   532 			// Reset paging var for new filters/searches but not for bulk actions. See #17685.
   408 			if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
   533 			if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
   409 				pageInput.val('1');
   534 				pageInput.val('1');
   410 		});
   535 		});
   434 			}).get().join(''));
   559 			}).get().join(''));
   435 		}
   560 		}
   436 		toggleUploadButton();
   561 		toggleUploadButton();
   437 		input.on('change', toggleUploadButton);
   562 		input.on('change', toggleUploadButton);
   438 	})();
   563 	})();
       
   564 
       
   565 	function pinMenu( event ) {
       
   566 		var windowPos = $window.scrollTop(),
       
   567 			resizing = ! event || event.type !== 'scroll';
       
   568 
       
   569 		if ( isIOS || isIE8 || $adminmenu.data( 'wp-responsive' ) ) {
       
   570 			return;
       
   571 		}
       
   572 
       
   573 		if ( height.menu + height.adminbar < height.window ||
       
   574 			height.menu + height.adminbar + 20 > height.wpwrap ) {
       
   575 			unpinMenu();
       
   576 			return;
       
   577 		}
       
   578 
       
   579 		menuIsPinned = true;
       
   580 
       
   581 		if ( height.menu + height.adminbar > height.window ) {
       
   582 			// Check for overscrolling
       
   583 			if ( windowPos < 0 ) {
       
   584 				if ( ! pinnedMenuTop ) {
       
   585 					pinnedMenuTop = true;
       
   586 					pinnedMenuBottom = false;
       
   587 
       
   588 					$adminMenuWrap.css({
       
   589 						position: 'fixed',
       
   590 						top: '',
       
   591 						bottom: ''
       
   592 					});
       
   593 				}
       
   594 
       
   595 				return;
       
   596 			} else if ( windowPos + height.window > $document.height() - 1 ) {
       
   597 				if ( ! pinnedMenuBottom ) {
       
   598 					pinnedMenuBottom = true;
       
   599 					pinnedMenuTop = false;
       
   600 
       
   601 					$adminMenuWrap.css({
       
   602 						position: 'fixed',
       
   603 						top: '',
       
   604 						bottom: 0
       
   605 					});
       
   606 				}
       
   607 
       
   608 				return;
       
   609 			}
       
   610 
       
   611 			if ( windowPos > lastScrollPosition ) {
       
   612 				// Scrolling down
       
   613 				if ( pinnedMenuTop ) {
       
   614 					// let it scroll
       
   615 					pinnedMenuTop = false;
       
   616 					menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition );
       
   617 
       
   618 					if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) {
       
   619 						menuTop = windowPos + height.window - height.menu - height.adminbar;
       
   620 					}
       
   621 
       
   622 					$adminMenuWrap.css({
       
   623 						position: 'absolute',
       
   624 						top: menuTop,
       
   625 						bottom: ''
       
   626 					});
       
   627 				} else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) {
       
   628 					// pin the bottom
       
   629 					pinnedMenuBottom = true;
       
   630 
       
   631 					$adminMenuWrap.css({
       
   632 						position: 'fixed',
       
   633 						top: '',
       
   634 						bottom: 0
       
   635 					});
       
   636 				}
       
   637 			} else if ( windowPos < lastScrollPosition ) {
       
   638 				// Scrolling up
       
   639 				if ( pinnedMenuBottom ) {
       
   640 					// let it scroll
       
   641 					pinnedMenuBottom = false;
       
   642 					menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos );
       
   643 
       
   644 					if ( menuTop + height.menu > windowPos + height.window ) {
       
   645 						menuTop = windowPos;
       
   646 					}
       
   647 
       
   648 					$adminMenuWrap.css({
       
   649 						position: 'absolute',
       
   650 						top: menuTop,
       
   651 						bottom: ''
       
   652 					});
       
   653 				} else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) {
       
   654 					// pin the top
       
   655 					pinnedMenuTop = true;
       
   656 
       
   657 					$adminMenuWrap.css({
       
   658 						position: 'fixed',
       
   659 						top: '',
       
   660 						bottom: ''
       
   661 					});
       
   662 				}
       
   663 			} else if ( resizing ) {
       
   664 				// Resizing
       
   665 				pinnedMenuTop = pinnedMenuBottom = false;
       
   666 				menuTop = windowPos + height.window - height.menu - height.adminbar - 1;
       
   667 
       
   668 				if ( menuTop > 0 ) {
       
   669 					$adminMenuWrap.css({
       
   670 						position: 'absolute',
       
   671 						top: menuTop,
       
   672 						bottom: ''
       
   673 					});
       
   674 				} else {
       
   675 					unpinMenu();
       
   676 				}
       
   677 			}
       
   678 		}
       
   679 
       
   680 		lastScrollPosition = windowPos;
       
   681 	}
       
   682 
       
   683 	function resetHeights() {
       
   684 		height = {
       
   685 			window: $window.height(),
       
   686 			wpwrap: $wpwrap.height(),
       
   687 			adminbar: $adminbar.height(),
       
   688 			menu: $adminMenuWrap.height()
       
   689 		};
       
   690 	}
       
   691 
       
   692 	function unpinMenu() {
       
   693 		if ( isIOS || ! menuIsPinned ) {
       
   694 			return;
       
   695 		}
       
   696 
       
   697 		pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
       
   698 		$adminMenuWrap.css({
       
   699 			position: '',
       
   700 			top: '',
       
   701 			bottom: ''
       
   702 		});
       
   703 	}
       
   704 
       
   705 	function setPinMenu() {
       
   706 		resetHeights();
       
   707 
       
   708 		if ( $adminmenu.data('wp-responsive') ) {
       
   709 			$body.removeClass( 'sticky-menu' );
       
   710 			unpinMenu();
       
   711 		} else if ( height.menu + height.adminbar > height.window ) {
       
   712 			pinMenu();
       
   713 			$body.removeClass( 'sticky-menu' );
       
   714 		} else {
       
   715 			$body.addClass( 'sticky-menu' );
       
   716 			unpinMenu();
       
   717 		}
       
   718 	}
       
   719 
       
   720 	if ( ! isIOS ) {
       
   721 		$window.on( 'scroll.pin-menu', pinMenu );
       
   722 		$document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) {
       
   723 			editor.on( 'wp-autoresize', resetHeights );
       
   724 		});
       
   725 	}
       
   726 
       
   727 	window.wpResponsive = {
       
   728 		init: function() {
       
   729 			var self = this;
       
   730 
       
   731 			// Modify functionality based on custom activate/deactivate event
       
   732 			$document.on( 'wp-responsive-activate.wp-responsive', function() {
       
   733 				self.activate();
       
   734 			}).on( 'wp-responsive-deactivate.wp-responsive', function() {
       
   735 				self.deactivate();
       
   736 			});
       
   737 
       
   738 			$( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' );
       
   739 
       
   740 			// Toggle sidebar when toggle is clicked
       
   741 			$( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
       
   742 				event.preventDefault();
       
   743 				$wpwrap.toggleClass( 'wp-responsive-open' );
       
   744 				if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
       
   745 					$(this).find('a').attr( 'aria-expanded', 'true' );
       
   746 					$( '#adminmenu a:first' ).focus();
       
   747 				} else {
       
   748 					$(this).find('a').attr( 'aria-expanded', 'false' );
       
   749 				}
       
   750 			} );
       
   751 
       
   752 			// Add menu events
       
   753 			$adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
       
   754 				if ( ! $adminmenu.data('wp-responsive') ) {
       
   755 					return;
       
   756 				}
       
   757 
       
   758 				$( this ).parent( 'li' ).toggleClass( 'selected' );
       
   759 				event.preventDefault();
       
   760 			});
       
   761 
       
   762 			self.trigger();
       
   763 			$document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) );
       
   764 
       
   765 			// This needs to run later as UI Sortable may be initialized later on $(document).ready()
       
   766 			$window.on( 'load.wp-responsive', function() {
       
   767 				var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
       
   768 
       
   769 				if ( width <= 782 ) {
       
   770 					self.disableSortables();
       
   771 				}
       
   772 			});
       
   773 		},
       
   774 
       
   775 		activate: function() {
       
   776 			setPinMenu();
       
   777 
       
   778 			if ( ! $body.hasClass( 'auto-fold' ) ) {
       
   779 				$body.addClass( 'auto-fold' );
       
   780 			}
       
   781 
       
   782 			$adminmenu.data( 'wp-responsive', 1 );
       
   783 			this.disableSortables();
       
   784 		},
       
   785 
       
   786 		deactivate: function() {
       
   787 			setPinMenu();
       
   788 			$adminmenu.removeData('wp-responsive');
       
   789 			this.enableSortables();
       
   790 		},
       
   791 
       
   792 		trigger: function() {
       
   793 			var width;
       
   794 
       
   795 			if ( window.innerWidth ) {
       
   796 				// window.innerWidth is affected by zooming on phones
       
   797 				width = Math.max( window.innerWidth, document.documentElement.clientWidth );
       
   798 			} else {
       
   799 				// Exclude IE < 9, it doesn't support @media CSS rules
       
   800 				return;
       
   801 			}
       
   802 
       
   803 			if ( width <= 782 ) {
       
   804 				if ( ! wpResponsiveActive ) {
       
   805 					$document.trigger( 'wp-responsive-activate' );
       
   806 					wpResponsiveActive = true;
       
   807 				}
       
   808 			} else {
       
   809 				if ( wpResponsiveActive ) {
       
   810 					$document.trigger( 'wp-responsive-deactivate' );
       
   811 					wpResponsiveActive = false;
       
   812 				}
       
   813 			}
       
   814 
       
   815 			if ( width <= 480 ) {
       
   816 				this.enableOverlay();
       
   817 			} else {
       
   818 				this.disableOverlay();
       
   819 			}
       
   820 		},
       
   821 
       
   822 		enableOverlay: function() {
       
   823 			if ( $overlay.length === 0 ) {
       
   824 				$overlay = $( '<div id="wp-responsive-overlay"></div>' )
       
   825 					.insertAfter( '#wpcontent' )
       
   826 					.hide()
       
   827 					.on( 'click.wp-responsive', function() {
       
   828 						$toolbar.find( '.menupop.hover' ).removeClass( 'hover' );
       
   829 						$( this ).hide();
       
   830 					});
       
   831 			}
       
   832 
       
   833 			$toolbarPopups.on( 'click.wp-responsive', function() {
       
   834 				$overlay.show();
       
   835 			});
       
   836 		},
       
   837 
       
   838 		disableOverlay: function() {
       
   839 			$toolbarPopups.off( 'click.wp-responsive' );
       
   840 			$overlay.hide();
       
   841 		},
       
   842 
       
   843 		disableSortables: function() {
       
   844 			if ( $sortables.length ) {
       
   845 				try {
       
   846 					$sortables.sortable('disable');
       
   847 				} catch(e) {}
       
   848 			}
       
   849 		},
       
   850 
       
   851 		enableSortables: function() {
       
   852 			if ( $sortables.length ) {
       
   853 				try {
       
   854 					$sortables.sortable('enable');
       
   855 				} catch(e) {}
       
   856 			}
       
   857 		}
       
   858 	};
       
   859 
       
   860 	window.wpResponsive.init();
       
   861 	setPinMenu();
       
   862 
       
   863 	$document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
   439 });
   864 });
   440 
   865 
   441 // internal use
   866 // Fire a custom jQuery event at the end of window resize
   442 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
   867 ( function() {
   443 	if ( typeof(data.cb) != 'function' )
   868 	var timeout;
   444 		return;
   869 
   445 
   870 	function triggerEvent() {
   446 	if ( typeof(data.condition) != 'function' || data.condition() )
   871 		$(document).trigger( 'wp-window-resized' );
   447 		data.cb();
   872 	}
   448 
   873 
   449 	return true;
   874 	function fireOnce() {
   450 });
   875 		window.clearTimeout( timeout );
   451 
   876 		timeout = window.setTimeout( triggerEvent, 200 );
   452 })(jQuery);
   877 	}
       
   878 
       
   879 	$(window).on( 'resize.wp-fire-once', fireOnce );
       
   880 }());
       
   881 
       
   882 // Make Windows 8 devices play along nicely.
       
   883 (function(){
       
   884 	if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) {
       
   885 		var msViewportStyle = document.createElement( 'style' );
       
   886 		msViewportStyle.appendChild(
       
   887 			document.createTextNode( '@-ms-viewport{width:auto!important}' )
       
   888 		);
       
   889 		document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle );
       
   890 	}
       
   891 })();
       
   892 
       
   893 }( jQuery, window ));