wp/wp-admin/js/inline-edit-post.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    49 		/**
    49 		/**
    50 		 * Binds the Escape key to revert the changes and close the quick editor.
    50 		 * Binds the Escape key to revert the changes and close the quick editor.
    51 		 *
    51 		 *
    52 		 * @return {boolean} The result of revert.
    52 		 * @return {boolean} The result of revert.
    53 		 */
    53 		 */
    54 		qeRow.keyup(function(e){
    54 		qeRow.on( 'keyup', function(e){
    55 			// Revert changes if Escape key is pressed.
    55 			// Revert changes if Escape key is pressed.
    56 			if ( e.which === 27 ) {
    56 			if ( e.which === 27 ) {
    57 				return inlineEditPost.revert();
    57 				return inlineEditPost.revert();
    58 			}
    58 			}
    59 		});
    59 		});
    61 		/**
    61 		/**
    62 		 * Binds the Escape key to revert the changes and close the bulk editor.
    62 		 * Binds the Escape key to revert the changes and close the bulk editor.
    63 		 *
    63 		 *
    64 		 * @return {boolean} The result of revert.
    64 		 * @return {boolean} The result of revert.
    65 		 */
    65 		 */
    66 		bulkRow.keyup(function(e){
    66 		bulkRow.on( 'keyup', function(e){
    67 			// Revert changes if Escape key is pressed.
    67 			// Revert changes if Escape key is pressed.
    68 			if ( e.which === 27 ) {
    68 			if ( e.which === 27 ) {
    69 				return inlineEditPost.revert();
    69 				return inlineEditPost.revert();
    70 			}
    70 			}
    71 		});
    71 		});
    73 		/**
    73 		/**
    74 		 * Reverts changes and close the quick editor if the cancel button is clicked.
    74 		 * Reverts changes and close the quick editor if the cancel button is clicked.
    75 		 *
    75 		 *
    76 		 * @return {boolean} The result of revert.
    76 		 * @return {boolean} The result of revert.
    77 		 */
    77 		 */
    78 		$( '.cancel', qeRow ).click( function() {
    78 		$( '.cancel', qeRow ).on( 'click', function() {
    79 			return inlineEditPost.revert();
    79 			return inlineEditPost.revert();
    80 		});
    80 		});
    81 
    81 
    82 		/**
    82 		/**
    83 		 * Saves changes in the quick editor if the save(named: update) button is clicked.
    83 		 * Saves changes in the quick editor if the save(named: update) button is clicked.
    84 		 *
    84 		 *
    85 		 * @return {boolean} The result of save.
    85 		 * @return {boolean} The result of save.
    86 		 */
    86 		 */
    87 		$( '.save', qeRow ).click( function() {
    87 		$( '.save', qeRow ).on( 'click', function() {
    88 			return inlineEditPost.save(this);
    88 			return inlineEditPost.save(this);
    89 		});
    89 		});
    90 
    90 
    91 		/**
    91 		/**
    92 		 * If Enter is pressed, and the target is not the cancel button, save the post.
    92 		 * If Enter is pressed, and the target is not the cancel button, save the post.
    93 		 *
    93 		 *
    94 		 * @return {boolean} The result of save.
    94 		 * @return {boolean} The result of save.
    95 		 */
    95 		 */
    96 		$('td', qeRow).keydown(function(e){
    96 		$('td', qeRow).on( 'keydown', function(e){
    97 			if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) {
    97 			if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) {
    98 				return inlineEditPost.save(this);
    98 				return inlineEditPost.save(this);
    99 			}
    99 			}
   100 		});
   100 		});
   101 
   101 
   102 		/**
   102 		/**
   103 		 * Reverts changes and close the bulk editor if the cancel button is clicked.
   103 		 * Reverts changes and close the bulk editor if the cancel button is clicked.
   104 		 *
   104 		 *
   105 		 * @return {boolean} The result of revert.
   105 		 * @return {boolean} The result of revert.
   106 		 */
   106 		 */
   107 		$( '.cancel', bulkRow ).click( function() {
   107 		$( '.cancel', bulkRow ).on( 'click', function() {
   108 			return inlineEditPost.revert();
   108 			return inlineEditPost.revert();
   109 		});
   109 		});
   110 
   110 
   111 		/**
   111 		/**
   112 		 * Disables the password input field when the private post checkbox is checked.
   112 		 * Disables the password input field when the private post checkbox is checked.
   113 		 */
   113 		 */
   114 		$('#inline-edit .inline-edit-private input[value="private"]').click( function(){
   114 		$('#inline-edit .inline-edit-private input[value="private"]').on( 'click', function(){
   115 			var pw = $('input.inline-edit-password-input');
   115 			var pw = $('input.inline-edit-password-input');
   116 			if ( $(this).prop('checked') ) {
   116 			if ( $(this).prop('checked') ) {
   117 				pw.val('').prop('disabled', true);
   117 				pw.val('').prop('disabled', true);
   118 			} else {
   118 			} else {
   119 				pw.prop('disabled', false);
   119 				pw.prop('disabled', false);
   137 		$('select[name="_status"] option[value="future"]', bulkRow).remove();
   137 		$('select[name="_status"] option[value="future"]', bulkRow).remove();
   138 
   138 
   139 		/**
   139 		/**
   140 		 * Adds onclick events to the apply buttons.
   140 		 * Adds onclick events to the apply buttons.
   141 		 */
   141 		 */
   142 		$('#doaction, #doaction2').click(function(e){
   142 		$('#doaction').on( 'click', function(e){
   143 			var n;
   143 			var n;
   144 
   144 
   145 			t.whichBulkButtonId = $( this ).attr( 'id' );
   145 			t.whichBulkButtonId = $( this ).attr( 'id' );
   146 			n = t.whichBulkButtonId.substr( 2 );
   146 			n = t.whichBulkButtonId.substr( 2 );
   147 
   147 
   213 		/**
   213 		/**
   214 		 * Binds on click events to the checkboxes before the posts in the table.
   214 		 * Binds on click events to the checkboxes before the posts in the table.
   215 		 *
   215 		 *
   216 		 * @listens click
   216 		 * @listens click
   217 		 */
   217 		 */
   218 		$('#bulk-titles a').click(function(){
   218 		$('#bulk-titles a').on( 'click', function(){
   219 			var id = $(this).attr('id').substr(1);
   219 			var id = $(this).attr('id').substr(1);
   220 
   220 
   221 			$('table.widefat input[value="' + id + '"]').prop('checked', false);
   221 			$('table.widefat input[value="' + id + '"]').prop('checked', false);
   222 			$('#ttle'+id).remove();
   222 			$('#ttle'+id).remove();
   223 		});
   223 		});
   327 			var terms = $(this),
   327 			var terms = $(this),
   328 				taxname = $(this).attr('id').replace('_' + id, ''),
   328 				taxname = $(this).attr('id').replace('_' + id, ''),
   329 				textarea = $('textarea.tax_input_' + taxname, editRow),
   329 				textarea = $('textarea.tax_input_' + taxname, editRow),
   330 				comma = wp.i18n._x( ',', 'tag delimiter' ).trim();
   330 				comma = wp.i18n._x( ',', 'tag delimiter' ).trim();
   331 
   331 
       
   332 			// Ensure the textarea exists.
       
   333 			if ( ! textarea.length ) {
       
   334 				return;
       
   335 			}
       
   336 
   332 			terms.find( 'img' ).replaceWith( function() { return this.alt; } );
   337 			terms.find( 'img' ).replaceWith( function() { return this.alt; } );
   333 			terms = terms.text();
   338 			terms = terms.text();
   334 
   339 
   335 			if ( terms ) {
   340 			if ( terms ) {
   336 				if ( ',' !== comma ) {
   341 				if ( ',' !== comma ) {
   376 			}
   381 			}
   377 			pageOpt.remove();
   382 			pageOpt.remove();
   378 		}
   383 		}
   379 
   384 
   380 		$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
   385 		$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
   381 		$('.ptitle', editRow).focus();
   386 		$('.ptitle', editRow).trigger( 'focus' );
   382 
   387 
   383 		return false;
   388 		return false;
   384 	},
   389 	},
   385 
   390 
   386 	/**
   391 	/**
   418 			function(r) {
   423 			function(r) {
   419 				var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ),
   424 				var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ),
   420 					$error = $errorNotice.find( '.error' );
   425 					$error = $errorNotice.find( '.error' );
   421 
   426 
   422 				$( 'table.widefat .spinner' ).removeClass( 'is-active' );
   427 				$( 'table.widefat .spinner' ).removeClass( 'is-active' );
   423 				$( '.ac_results' ).hide();
       
   424 
   428 
   425 				if (r) {
   429 				if (r) {
   426 					if ( -1 !== r.indexOf( '<tr' ) ) {
   430 					if ( -1 !== r.indexOf( '<tr' ) ) {
   427 						$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
   431 						$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
   428 						$('#edit-'+id).before(r).remove();
   432 						$('#edit-'+id).before(r).remove();
   429 						$( inlineEditPost.what + id ).hide().fadeIn( 400, function() {
   433 						$( inlineEditPost.what + id ).hide().fadeIn( 400, function() {
   430 							// Move focus back to the Quick Edit button. $( this ) is the row being animated.
   434 							// Move focus back to the Quick Edit button. $( this ) is the row being animated.
   431 							$( this ).find( '.editinline' )
   435 							$( this ).find( '.editinline' )
   432 								.attr( 'aria-expanded', 'false' )
   436 								.attr( 'aria-expanded', 'false' )
   433 								.focus();
   437 								.trigger( 'focus' );
   434 							wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) );
   438 							wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) );
   435 						});
   439 						});
   436 					} else {
   440 					} else {
   437 						r = r.replace( /<.[^<>]*?>/g, '' );
   441 						r = r.replace( /<.[^<>]*?>/g, '' );
   438 						$errorNotice.removeClass( 'hidden' );
   442 						$errorNotice.removeClass( 'hidden' );
   464 		var $tableWideFat = $( '.widefat' ),
   468 		var $tableWideFat = $( '.widefat' ),
   465 			id = $( '.inline-editor', $tableWideFat ).attr( 'id' );
   469 			id = $( '.inline-editor', $tableWideFat ).attr( 'id' );
   466 
   470 
   467 		if ( id ) {
   471 		if ( id ) {
   468 			$( '.spinner', $tableWideFat ).removeClass( 'is-active' );
   472 			$( '.spinner', $tableWideFat ).removeClass( 'is-active' );
   469 			$( '.ac_results' ).hide();
       
   470 
   473 
   471 			if ( 'bulk-edit' === id ) {
   474 			if ( 'bulk-edit' === id ) {
   472 
   475 
   473 				// Hide the bulk editor.
   476 				// Hide the bulk editor.
   474 				$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove();
   477 				$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove();
   476 
   479 
   477 				// Store the empty bulk editor in a hidden element.
   480 				// Store the empty bulk editor in a hidden element.
   478 				$('#inlineedit').append( $('#bulk-edit') );
   481 				$('#inlineedit').append( $('#bulk-edit') );
   479 
   482 
   480 				// Move focus back to the Bulk Action button that was activated.
   483 				// Move focus back to the Bulk Action button that was activated.
   481 				$( '#' + inlineEditPost.whichBulkButtonId ).focus();
   484 				$( '#' + inlineEditPost.whichBulkButtonId ).trigger( 'focus' );
   482 			} else {
   485 			} else {
   483 
   486 
   484 				// Remove both the inline-editor and its hidden tr siblings.
   487 				// Remove both the inline-editor and its hidden tr siblings.
   485 				$('#'+id).siblings('tr.hidden').addBack().remove();
   488 				$('#'+id).siblings('tr.hidden').addBack().remove();
   486 				id = id.substr( id.lastIndexOf('-') + 1 );
   489 				id = id.substr( id.lastIndexOf('-') + 1 );
   487 
   490 
   488 				// Show the post row and move focus back to the Quick Edit button.
   491 				// Show the post row and move focus back to the Quick Edit button.
   489 				$( this.what + id ).show().find( '.editinline' )
   492 				$( this.what + id ).show().find( '.editinline' )
   490 					.attr( 'aria-expanded', 'false' )
   493 					.attr( 'aria-expanded', 'false' )
   491 					.focus();
   494 					.trigger( 'focus' );
   492 			}
   495 			}
   493 		}
   496 		}
   494 
   497 
   495 		return false;
   498 		return false;
   496 	},
   499 	},
   511 			parts = id.split('-');
   514 			parts = id.split('-');
   512 		return parts[parts.length - 1];
   515 		return parts[parts.length - 1];
   513 	}
   516 	}
   514 };
   517 };
   515 
   518 
   516 $( document ).ready( function(){ inlineEditPost.init(); } );
   519 $( function() { inlineEditPost.init(); } );
   517 
   520 
   518 // Show/hide locks on posts.
   521 // Show/hide locks on posts.
   519 $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
   522 $( function() {
       
   523 
       
   524 	// Set the heartbeat interval to 15 seconds.
       
   525 	if ( typeof wp !== 'undefined' && wp.heartbeat ) {
       
   526 		wp.heartbeat.interval( 15 );
       
   527 	}
       
   528 }).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
   520 	var locked = data['wp-check-locked-posts'] || {};
   529 	var locked = data['wp-check-locked-posts'] || {};
   521 
   530 
   522 	$('#the-list tr').each( function(i, el) {
   531 	$('#the-list tr').each( function(i, el) {
   523 		var key = el.id, row = $(el), lock_data, avatar;
   532 		var key = el.id, row = $(el), lock_data, avatar;
   524 
   533 
   555 	});
   564 	});
   556 
   565 
   557 	if ( check.length ) {
   566 	if ( check.length ) {
   558 		data['wp-check-locked-posts'] = check;
   567 		data['wp-check-locked-posts'] = check;
   559 	}
   568 	}
   560 }).ready( function() {
       
   561 
       
   562 	// Set the heartbeat interval to 15 seconds.
       
   563 	if ( typeof wp !== 'undefined' && wp.heartbeat ) {
       
   564 		wp.heartbeat.interval( 15 );
       
   565 	}
       
   566 });
   569 });
   567 
   570 
   568 })( jQuery, window.wp );
   571 })( jQuery, window.wp );