wp/wp-admin/js/inline-edit-tax.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     1 /* global inlineEditL10n, ajaxurl */
       
     2 /**
     1 /**
     3  * This file is used on the term overview page to power quick-editing terms.
     2  * This file is used on the term overview page to power quick-editing terms.
       
     3  *
       
     4  * @output wp-admin/js/inline-edit-tax.js
     4  */
     5  */
       
     6 
       
     7 /* global inlineEditL10n, ajaxurl, inlineEditTax */
     5 
     8 
     6 window.wp = window.wp || {};
     9 window.wp = window.wp || {};
     7 
    10 
     8 /**
    11 /**
     9  * Consists of functions relevant to the inline taxonomy editor.
    12  * Consists of functions relevant to the inline taxonomy editor.
    12  *
    15  *
    13  * @property {string} type The type of inline edit we are currently on.
    16  * @property {string} type The type of inline edit we are currently on.
    14  * @property {string} what The type property with a hash prefixed and a dash
    17  * @property {string} what The type property with a hash prefixed and a dash
    15  *                         suffixed.
    18  *                         suffixed.
    16  */
    19  */
    17 var inlineEditTax;
       
    18 
       
    19 ( function( $, wp ) {
    20 ( function( $, wp ) {
    20 
    21 
    21 inlineEditTax = {
    22 window.inlineEditTax = {
    22 
    23 
    23 	/**
    24 	/**
    24 	 * @summary Initializes the inline taxonomy editor.
    25 	 * Initializes the inline taxonomy editor by adding event handlers to be able to
    25 	 *
    26 	 * quick edit.
    26 	 * Adds event handlers to be able to quick edit.
       
    27 	 *
    27 	 *
    28 	 * @since 2.7.0
    28 	 * @since 2.7.0
    29 	 *
    29 	 *
    30 	 * @this inlineEditTax
    30 	 * @this inlineEditTax
    31 	 * @memberof inlineEditTax
    31 	 * @memberof inlineEditTax
    35 		var t = this, row = $('#inline-edit');
    35 		var t = this, row = $('#inline-edit');
    36 
    36 
    37 		t.type = $('#the-list').attr('data-wp-lists').substr(5);
    37 		t.type = $('#the-list').attr('data-wp-lists').substr(5);
    38 		t.what = '#'+t.type+'-';
    38 		t.what = '#'+t.type+'-';
    39 
    39 
    40 		$('#the-list').on('click', 'a.editinline', function(){
    40 		$( '#the-list' ).on( 'click', '.editinline', function() {
    41 			inlineEditTax.edit(this);
    41 			$( this ).attr( 'aria-expanded', 'true' );
    42 			return false;
    42 			inlineEditTax.edit( this );
    43 		});
    43 		});
    44 
    44 
    45 		/*
    45 		/**
    46 		 * @summary Cancels inline editing when pressing escape inside the inline editor.
    46 		 * Cancels inline editing when pressing escape inside the inline editor.
    47 		 *
    47 		 *
    48 		 * @param {Object} e The keyup event that has been triggered.
    48 		 * @param {Object} e The keyup event that has been triggered.
    49 		 */
    49 		 */
    50 		row.keyup( function( e ) {
    50 		row.keyup( function( e ) {
    51 			// 27 = [escape]
    51 			// 27 = [escape]
    53 				return inlineEditTax.revert();
    53 				return inlineEditTax.revert();
    54 			}
    54 			}
    55 		});
    55 		});
    56 
    56 
    57 		/**
    57 		/**
    58 		 * @summary Cancels inline editing when clicking the cancel button.
    58 		 * Cancels inline editing when clicking the cancel button.
    59 		 */
    59 		 */
    60 		$( '.cancel', row ).click( function() {
    60 		$( '.cancel', row ).click( function() {
    61 			return inlineEditTax.revert();
    61 			return inlineEditTax.revert();
    62 		});
    62 		});
    63 
    63 
    64 		/**
    64 		/**
    65 		 * @summary Saves the inline edits when clicking the save button.
    65 		 * Saves the inline edits when clicking the save button.
    66 		 */
    66 		 */
    67 		$( '.save', row ).click( function() {
    67 		$( '.save', row ).click( function() {
    68 			return inlineEditTax.save(this);
    68 			return inlineEditTax.save(this);
    69 		});
    69 		});
    70 
    70 
    71 		/**
    71 		/**
    72 		 * @summary Saves the inline edits when pressing enter inside the inline editor.
    72 		 * Saves the inline edits when pressing enter inside the inline editor.
    73 		 */
    73 		 */
    74 		$( 'input, select', row ).keydown( function( e ) {
    74 		$( 'input, select', row ).keydown( function( e ) {
    75 			// 13 = [enter]
    75 			// 13 = [enter]
    76 			if ( e.which === 13 ) {
    76 			if ( e.which === 13 ) {
    77 				return inlineEditTax.save( this );
    77 				return inlineEditTax.save( this );
    78 			}
    78 			}
    79 		});
    79 		});
    80 
    80 
    81 		/**
    81 		/**
    82 		 * @summary Saves the inline edits on submitting the inline edit form.
    82 		 * Saves the inline edits on submitting the inline edit form.
    83 		 */
    83 		 */
    84 		$( '#posts-filter input[type="submit"]' ).mousedown( function() {
    84 		$( '#posts-filter input[type="submit"]' ).mousedown( function() {
    85 			t.revert();
    85 			t.revert();
    86 		});
    86 		});
    87 	},
    87 	},
   147 
   147 
   148 		return false;
   148 		return false;
   149 	},
   149 	},
   150 
   150 
   151 	/**
   151 	/**
   152 	 * @summary Saves the quick edit data.
   152 	 * Saves the quick edit data.
   153 	 *
   153 	 *
   154 	 * Saves the quick edit data to the server and replaces the table row with the
   154 	 * Saves the quick edit data to the server and replaces the table row with the
   155 	 * HTML retrieved from the server.
   155 	 * HTML retrieved from the server.
   156 	 *
   156 	 *
   157 	 * @since 2.7.0
   157 	 * @since 2.7.0
   185 		params = fields + '&' + $.param(params);
   185 		params = fields + '&' + $.param(params);
   186 
   186 
   187 		// Do the ajax request to save the data to the server.
   187 		// Do the ajax request to save the data to the server.
   188 		$.post( ajaxurl, params,
   188 		$.post( ajaxurl, params,
   189 			/**
   189 			/**
   190 			 * @summary Handles the response from the server.
   190 			 * Handles the response from the server
   191 			 *
   191 			 *
   192 			 * Handles the response from the server, replaces the table row with the response
   192 			 * Handles the response from the server, replaces the table row with the response
   193 			 * from the server.
   193 			 * from the server.
   194 			 *
   194 			 *
   195 			 * @param {string} r The string with which to replace the table row.
   195 			 * @param {string} r The string with which to replace the table row.
   218 
   218 
   219 						// Update the value in the Parent dropdown.
   219 						// Update the value in the Parent dropdown.
   220 						$( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
   220 						$( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
   221 
   221 
   222 						row.hide().fadeIn( 400, function() {
   222 						row.hide().fadeIn( 400, function() {
   223 							// Move focus back to the Quick Edit link.
   223 							// Move focus back to the Quick Edit button.
   224 							row.find( '.editinline' ).focus();
   224 							row.find( '.editinline' )
       
   225 								.attr( 'aria-expanded', 'false' )
       
   226 								.focus();
   225 							wp.a11y.speak( inlineEditL10n.saved );
   227 							wp.a11y.speak( inlineEditL10n.saved );
   226 						});
   228 						});
   227 
   229 
   228 					} else {
   230 					} else {
   229 						$errorNotice.removeClass( 'hidden' );
   231 						$errorNotice.removeClass( 'hidden' );
   261 		if ( id ) {
   263 		if ( id ) {
   262 			$( 'table.widefat .spinner' ).removeClass( 'is-active' );
   264 			$( 'table.widefat .spinner' ).removeClass( 'is-active' );
   263 			$('#'+id).siblings('tr.hidden').addBack().remove();
   265 			$('#'+id).siblings('tr.hidden').addBack().remove();
   264 			id = id.substr( id.lastIndexOf('-') + 1 );
   266 			id = id.substr( id.lastIndexOf('-') + 1 );
   265 
   267 
   266 			// Show the taxonomy row and move focus back to the Quick Edit link.
   268 			// Show the taxonomy row and move focus back to the Quick Edit button.
   267 			$( this.what + id ).show().find( '.editinline' ).focus();
   269 			$( this.what + id ).show().find( '.editinline' )
       
   270 				.attr( 'aria-expanded', 'false' )
       
   271 				.focus();
   268 		}
   272 		}
   269 	},
   273 	},
   270 
   274 
   271 	/**
   275 	/**
   272 	 * Retrieves the ID of the term of the element inside the table row.
   276 	 * Retrieves the ID of the term of the element inside the table row.