Changeset 38644
- Timestamp:
- 09/22/2016 06:49:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/inline-edit-tax.js
r37439 r38644 1 1 /* global inlineEditL10n, ajaxurl */ 2 /** 3 * This file is used on the term overview page to power quick-editing terms. 4 */ 5 2 6 window.wp = window.wp || {}; 3 7 8 /** 9 * Consists of functions relevant to the inline taxonomy editor. 10 * 11 * @namespace inlineEditTax 12 * 13 * @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 15 * suffixed. 16 */ 4 17 var inlineEditTax; 18 5 19 ( function( $, wp ) { 20 6 21 inlineEditTax = { 7 22 23 /** 24 * @summary Initializes the inline taxonomy editor. 25 * 26 * Adds event handlers to be able to quick edit. 27 * 28 * @since 2.7.0 29 * 30 * @this inlineEditTax 31 * @memberof inlineEditTax 32 * @returns {void} 33 */ 8 34 init : function() { 9 35 var t = this, row = $('#inline-edit'); … … 17 43 }); 18 44 19 // prepare the edit row 45 /* 46 * @summary Cancels inline editing when pressing escape inside the inline editor. 47 * 48 * @param {Object} e The keyup event that has been triggered. 49 */ 20 50 row.keyup( function( e ) { 51 // 27 = [escape] 21 52 if ( e.which === 27 ) { 22 53 return inlineEditTax.revert(); … … 24 55 }); 25 56 57 /** 58 * @summary Cancels inline editing when clicking the cancel button. 59 */ 26 60 $( '.cancel', row ).click( function() { 27 61 return inlineEditTax.revert(); 28 62 }); 63 64 /** 65 * @summary Saves the inline edits when clicking the save button. 66 */ 29 67 $( '.save', row ).click( function() { 30 68 return inlineEditTax.save(this); 31 69 }); 70 71 /** 72 * @summary Saves the inline edits when pressing enter inside the inline editor. 73 */ 32 74 $( 'input, select', row ).keydown( function( e ) { 75 // 13 = [enter] 33 76 if ( e.which === 13 ) { 34 77 return inlineEditTax.save( this ); … … 36 79 }); 37 80 81 /** 82 * @summary Saves the inline edits on submitting the inline edit form. 83 */ 38 84 $( '#posts-filter input[type="submit"]' ).mousedown( function() { 39 85 t.revert(); … … 41 87 }, 42 88 89 /** 90 * Toggles the quick edit based on if it is currently shown or hidden. 91 * 92 * @since 2.7.0 93 * 94 * @this inlineEditTax 95 * @memberof inlineEditTax 96 * 97 * @param {HTMLElement} el An element within the table row or the table row 98 * itself that we want to quick edit. 99 * @returns {void} 100 */ 43 101 toggle : function(el) { 44 102 var t = this; 103 45 104 $(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el); 46 105 }, 47 106 107 /** 108 * Shows the quick editor 109 * 110 * @since 2.7.0 111 * 112 * @this inlineEditTax 113 * @memberof inlineEditTax 114 * 115 * @param {string|HTMLElement} id The ID of the term we want to quick edit or an 116 * element within the table row or the 117 * table row itself. 118 * @returns {boolean} Always returns false. 119 */ 48 120 edit : function(id) { 49 121 var editRow, rowData, val, … … 51 123 t.revert(); 52 124 125 // Makes sure we can pass an HTMLElement as the ID. 53 126 if ( typeof(id) === 'object' ) { 54 127 id = t.getId(id); … … 76 149 }, 77 150 151 /** 152 * @summary Saves the quick edit data. 153 * 154 * Saves the quick edit data to the server and replaces the table row with the 155 * HTML retrieved from the server. 156 * 157 * @since 2.7.0 158 * 159 * @this inlineEditTax 160 * @memberof inlineEditTax 161 * 162 * @param {string|HTMLElement} id The ID of the term we want to quick edit or an 163 * element within the table row or the 164 * table row itself. 165 * @returns {boolean} Always returns false. 166 */ 78 167 save : function(id) { 79 168 var params, fields, tax = $('input[name="taxonomy"]').val() || ''; 80 169 170 // Makes sure we can pass an HTMLElement as the ID. 81 171 if( typeof(id) === 'object' ) { 82 172 id = this.getId(id); … … 95 185 params = fields + '&' + $.param(params); 96 186 97 // make ajax request187 // Do the ajax request to save the data to the server. 98 188 $.post( ajaxurl, params, 189 /** 190 * @summary Handles the response from the server. 191 * 192 * Handles the response from the server, replaces the table row with the response 193 * from the server. 194 * 195 * @param {string} r The string with which to replace the table row. 196 */ 99 197 function(r) { 100 198 var row, new_id, option_value, … … 129 227 } else { 130 228 $errorSpan.html( r ).show(); 131 // Some error strings may contain HTML entities (e.g. `“`), let's use the HTML element's text. 229 /* 230 * Some error strings may contain HTML entities (e.g. `“`), let's use 231 * the HTML element's text. 232 */ 132 233 wp.a11y.speak( $errorSpan.text() ); 133 234 } … … 138 239 } 139 240 ); 241 140 242 // Prevent submitting the form when pressing Enter on a focused field. 141 243 return false; 142 244 }, 143 245 246 /** 247 * Closes the quick edit form. 248 * 249 * @since 2.7.0 250 * 251 * @this inlineEditTax 252 * @memberof inlineEditTax 253 * @returns {void} 254 */ 144 255 revert : function() { 145 256 var id = $('table.widefat tr.inline-editor').attr('id'); … … 149 260 $('#'+id).siblings('tr.hidden').addBack().remove(); 150 261 id = id.substr( id.lastIndexOf('-') + 1 ); 262 151 263 // Show the taxonomy row and move focus back to the Quick Edit link. 152 264 $( this.what + id ).show().find( '.editinline' ).focus(); … … 154 266 }, 155 267 268 /** 269 * Retrieves the ID of the term of the element inside the table row. 270 * 271 * @since 2.7.0 272 * 273 * @memberof inlineEditTax 274 * 275 * @param {HTMLElement} o An element within the table row or the table row itself. 276 * @returns {string} The ID of the term based on the element. 277 */ 156 278 getId : function(o) { 157 279 var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); 280 158 281 return parts[parts.length - 1]; 159 282 } … … 161 284 162 285 $(document).ready(function(){inlineEditTax.init();}); 286 163 287 })( jQuery, window.wp );
Note: See TracChangeset
for help on using the changeset viewer.