diff --git src/wp-admin/js/inline-edit-post.js src/wp-admin/js/inline-edit-post.js
index 9582707..e59f0fa 100644
|
|
|
|
| 1 | 1 | /* global inlineEditL10n, ajaxurl, typenow */ |
| | 2 | |
| | 3 | /** |
| | 4 | * This file contains the functions needed for the inline editing of posts. |
| | 5 | * |
| | 6 | * @since 2.7.0 |
| | 7 | */ |
| | 8 | |
| 2 | 9 | window.wp = window.wp || {}; |
| 3 | 10 | |
| | 11 | /** |
| | 12 | * Manages the quick edit and bulk edit windows for editing posts or pages. |
| | 13 | * |
| | 14 | * @namespace |
| | 15 | * |
| | 16 | * @since 2.7.0 |
| | 17 | * @access public |
| | 18 | * |
| | 19 | * @type {Object} |
| | 20 | * |
| | 21 | * @property {string} type The type of inline editor. |
| | 22 | * @property {string} what The prefix before the post id. |
| | 23 | * |
| | 24 | */ |
| 4 | 25 | var inlineEditPost; |
| 5 | 26 | ( function( $, wp ) { |
| 6 | | inlineEditPost = { |
| 7 | 27 | |
| | 28 | inlineEditPost = { |
| | 29 | |
| | 30 | /** |
| | 31 | * @summary Initializes the inline and bulk post editor. |
| | 32 | * |
| | 33 | * Binds event handlers to the escape key to close the inline editor |
| | 34 | * and to the save and close buttons. Changes DOM to be ready for inline |
| | 35 | * editing. Adds event handler to bulk edit. |
| | 36 | * |
| | 37 | * @memberof inlineEditPost |
| | 38 | * @since 2.7.0 |
| | 39 | * |
| | 40 | * @returns {void} |
| | 41 | */ |
| 8 | 42 | init : function(){ |
| 9 | 43 | var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); |
| 10 | 44 | |
| 11 | 45 | t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; |
| | 46 | // Post id prefix. |
| 12 | 47 | t.what = '#post-'; |
| 13 | 48 | |
| 14 | | // prepare the edit rows |
| | 49 | /** |
| | 50 | * @summary Bind escape key to revert the changes and close the quick editor. |
| | 51 | * |
| | 52 | * @returns {boolean} Returns the result of revert. |
| | 53 | */ |
| 15 | 54 | qeRow.keyup(function(e){ |
| | 55 | // Revert changes if escape key is pressed. |
| 16 | 56 | if ( e.which === 27 ) { |
| 17 | 57 | return inlineEditPost.revert(); |
| 18 | 58 | } |
| 19 | 59 | }); |
| | 60 | |
| | 61 | /** |
| | 62 | * @summary Bind escape key to revert the changes and close the bulk editor. |
| | 63 | * |
| | 64 | * @returns {boolean} Returns the result of revert. |
| | 65 | */ |
| 20 | 66 | bulkRow.keyup(function(e){ |
| | 67 | // Revert changes if escape key is pressed. |
| 21 | 68 | if ( e.which === 27 ) { |
| 22 | 69 | return inlineEditPost.revert(); |
| 23 | 70 | } |
| 24 | 71 | }); |
| 25 | 72 | |
| | 73 | /** |
| | 74 | * @summary Revert changes and close the quick editor if the cancel button is clicked. |
| | 75 | * |
| | 76 | * @returns {boolean} Returns the result of revert. |
| | 77 | */ |
| 26 | 78 | $( '.cancel', qeRow ).click( function() { |
| 27 | 79 | return inlineEditPost.revert(); |
| 28 | 80 | }); |
| | 81 | |
| | 82 | /** |
| | 83 | * @summary Save changes in the quick editor if the save(named: update) button is clicked. |
| | 84 | * |
| | 85 | * @returns {boolean} Returns the result of save. |
| | 86 | */ |
| 29 | 87 | $( '.save', qeRow ).click( function() { |
| 30 | 88 | return inlineEditPost.save(this); |
| 31 | 89 | }); |
| | 90 | |
| | 91 | /** |
| | 92 | * @summary If enter is pressed, and the target is not the cancel button, save the post. |
| | 93 | * |
| | 94 | * @returns {boolean} Returns the result of save. |
| | 95 | */ |
| 32 | 96 | $('td', qeRow).keydown(function(e){ |
| 33 | 97 | if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) { |
| 34 | 98 | return inlineEditPost.save(this); |
| 35 | 99 | } |
| 36 | 100 | }); |
| 37 | 101 | |
| | 102 | /** |
| | 103 | * @summary Revert changes and close the bulk editor if the cancel button is clicked. |
| | 104 | * |
| | 105 | * @returns {boolean} Returns the result of revert. |
| | 106 | */ |
| 38 | 107 | $( '.cancel', bulkRow ).click( function() { |
| 39 | 108 | return inlineEditPost.revert(); |
| 40 | 109 | }); |
| 41 | 110 | |
| | 111 | /** |
| | 112 | * @summary Disables the password input field when the private post checkbox is checked. |
| | 113 | * |
| | 114 | * @returns {void} |
| | 115 | */ |
| 42 | 116 | $('#inline-edit .inline-edit-private input[value="private"]').click( function(){ |
| 43 | 117 | var pw = $('input.inline-edit-password-input'); |
| 44 | 118 | if ( $(this).prop('checked') ) { |
| … |
… |
inlineEditPost = { |
| 48 | 122 | } |
| 49 | 123 | }); |
| 50 | 124 | |
| 51 | | // add events |
| | 125 | /** |
| | 126 | * @summary Bind click event to the .editinline link which opens the quick editor. |
| | 127 | * |
| | 128 | * @returns {void} |
| | 129 | */ |
| 52 | 130 | $('#the-list').on( 'click', 'a.editinline', function( e ) { |
| 53 | 131 | e.preventDefault(); |
| 54 | 132 | inlineEditPost.edit(this); |
| … |
… |
inlineEditPost = { |
| 62 | 140 | |
| 63 | 141 | $('select[name="_status"] option[value="future"]', bulkRow).remove(); |
| 64 | 142 | |
| | 143 | /** |
| | 144 | * @summary Adds onclick events to the apply buttons. |
| | 145 | * |
| | 146 | * @returns {void} |
| | 147 | */ |
| 65 | 148 | $('#doaction, #doaction2').click(function(e){ |
| 66 | 149 | var n; |
| 67 | 150 | |
| … |
… |
inlineEditPost = { |
| 77 | 160 | }); |
| 78 | 161 | }, |
| 79 | 162 | |
| | 163 | /** |
| | 164 | * @summary Toggles the quick edit window. |
| | 165 | * |
| | 166 | * Hides the window when it's active and shows the window when inactive. |
| | 167 | * |
| | 168 | * @memberof inlineEditPost |
| | 169 | * @since 2.7.0 |
| | 170 | * |
| | 171 | * @param {Object} el Element within a post table row. |
| | 172 | * |
| | 173 | * @returns {void} |
| | 174 | */ |
| 80 | 175 | toggle : function(el){ |
| 81 | 176 | var t = this; |
| 82 | 177 | $( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el ); |
| 83 | 178 | }, |
| 84 | 179 | |
| | 180 | /** |
| | 181 | * @summary Creates the bulk editor row to edit multiple posts at once. |
| | 182 | * |
| | 183 | * @memberof inlineEditPost |
| | 184 | * @since 2.7.0 |
| | 185 | * |
| | 186 | * @returns {void} |
| | 187 | */ |
| 85 | 188 | setBulk : function(){ |
| 86 | 189 | var te = '', type = this.type, c = true; |
| 87 | 190 | this.revert(); |
| 88 | 191 | |
| 89 | 192 | $( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
| | 193 | |
| 90 | 194 | // Insert the editor at the top of the table with an empty row above to maintain zebra striping. |
| 91 | 195 | $('table.widefat tbody').prepend( $('#bulk-edit') ).prepend('<tr class="hidden"></tr>'); |
| 92 | 196 | $('#bulk-edit').addClass('inline-editor').show(); |
| 93 | 197 | |
| | 198 | /** |
| | 199 | * @summary Create a HTML div with the title and a delete link(cross-icon) for each selected post. |
| | 200 | * |
| | 201 | * Get the selected posts based on the checked checkboxes in the post table. |
| | 202 | * Create a HTML div with the title and a link(delete-icon) for each selected post. |
| | 203 | * |
| | 204 | * @returns {void} |
| | 205 | */ |
| 94 | 206 | $( 'tbody th.check-column input[type="checkbox"]' ).each( function() { |
| | 207 | |
| | 208 | // If the checkbox for a post is selected, add the post to the edit list. |
| 95 | 209 | if ( $(this).prop('checked') ) { |
| 96 | 210 | c = false; |
| 97 | 211 | var id = $(this).val(), theTitle; |
| … |
… |
inlineEditPost = { |
| 100 | 214 | } |
| 101 | 215 | }); |
| 102 | 216 | |
| | 217 | // If no checkboxes where checked, just hide the quick/bulk edit rows. |
| 103 | 218 | if ( c ) { |
| 104 | 219 | return this.revert(); |
| 105 | 220 | } |
| 106 | 221 | |
| | 222 | // Add onclick events to the delete-icons in the bulk editors the post title list. |
| 107 | 223 | $('#bulk-titles').html(te); |
| | 224 | |
| | 225 | /** |
| | 226 | * @summary Binds on click events to the checkboxes before the posts in the table. |
| | 227 | * |
| | 228 | * @listens click |
| | 229 | * |
| | 230 | * @returns {void} |
| | 231 | */ |
| 108 | 232 | $('#bulk-titles a').click(function(){ |
| 109 | 233 | var id = $(this).attr('id').substr(1); |
| 110 | | |
| 111 | 234 | $('table.widefat input[value="' + id + '"]').prop('checked', false); |
| 112 | 235 | $('#ttle'+id).remove(); |
| 113 | 236 | }); |
| 114 | 237 | |
| 115 | | // enable autocomplete for tags |
| | 238 | // Enable auto-complete for tags when editing posts. |
| 116 | 239 | if ( 'post' === type ) { |
| 117 | 240 | $( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) { |
| 118 | 241 | $( element ).wpTagsSuggest(); |
| 119 | 242 | } ); |
| 120 | 243 | } |
| | 244 | |
| | 245 | // Scrolls to the top of the table where the editor is rendered. |
| 121 | 246 | $('html, body').animate( { scrollTop: 0 }, 'fast' ); |
| 122 | 247 | }, |
| 123 | 248 | |
| | 249 | /** |
| | 250 | * @summary Creates a quick edit window for the post that has been clicked. |
| | 251 | * |
| | 252 | * @memberof inlineEditPost |
| | 253 | * @since 2.7.0 |
| | 254 | * |
| | 255 | * @param {number|Object} id The id of the clicked post or an element within a post |
| | 256 | * table row. |
| | 257 | * |
| | 258 | * @returns {boolean} Always returns false at the end of execution. |
| | 259 | */ |
| 124 | 260 | edit : function(id) { |
| 125 | 261 | var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw; |
| 126 | 262 | t.revert(); |
| … |
… |
inlineEditPost = { |
| 134 | 270 | fields.push('post_parent', 'page_template'); |
| 135 | 271 | } |
| 136 | 272 | |
| 137 | | // add the new edit row with an extra blank row underneath to maintain zebra striping. |
| | 273 | // Add the new edit row with an extra blank row underneath to maintain zebra striping. |
| 138 | 274 | editRow = $('#inline-edit').clone(true); |
| 139 | 275 | $( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
| 140 | 276 | |
| 141 | 277 | $(t.what+id).removeClass('is-expanded').hide().after(editRow).after('<tr class="hidden"></tr>'); |
| 142 | 278 | |
| 143 | | // populate the data |
| | 279 | // Populate fields in the quick edit window. |
| 144 | 280 | rowData = $('#inline_'+id); |
| 145 | 281 | if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { |
| 146 | | // author no longer has edit caps, so we need to add them to the list of authors |
| | 282 | // The post author no longer has edit capabilities, so we need to add them to the list of authors. |
| 147 | 283 | $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>'); |
| 148 | 284 | } |
| 149 | 285 | if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) { |
| … |
… |
inlineEditPost = { |
| 152 | 288 | |
| 153 | 289 | for ( f = 0; f < fields.length; f++ ) { |
| 154 | 290 | val = $('.'+fields[f], rowData); |
| 155 | | // Deal with Twemoji |
| | 291 | /** |
| | 292 | * @summary Replaces the image for a Twemoji(Twitter emoji) with it's alternate text. |
| | 293 | * |
| | 294 | * @returns Alternate text from the image. |
| | 295 | */ |
| 156 | 296 | val.find( 'img' ).replaceWith( function() { return this.alt; } ); |
| 157 | 297 | val = val.text(); |
| 158 | 298 | $(':input[name="' + fields[f] + '"]', editRow).val( val ); |
| … |
… |
inlineEditPost = { |
| 168 | 308 | $( 'input[name="sticky"]', editRow ).prop( 'checked', true ); |
| 169 | 309 | } |
| 170 | 310 | |
| 171 | | // hierarchical taxonomies |
| | 311 | /** |
| | 312 | * @summary Creates the select boxes for the categories. |
| | 313 | * |
| | 314 | * @returns {void} |
| | 315 | */ |
| 172 | 316 | $('.post_category', rowData).each(function(){ |
| 173 | 317 | var taxname, |
| 174 | 318 | term_ids = $(this).text(); |
| … |
… |
inlineEditPost = { |
| 179 | 323 | } |
| 180 | 324 | }); |
| 181 | 325 | |
| 182 | | //flat taxonomies |
| | 326 | /** |
| | 327 | * @summary Gets all the taxonomies for live auto-fill suggestions. |
| | 328 | * When typing the name of a tag. |
| | 329 | * |
| | 330 | * @returns {void} |
| | 331 | */ |
| 183 | 332 | $('.tags_input', rowData).each(function(){ |
| 184 | 333 | var terms = $(this), |
| 185 | 334 | taxname = $(this).attr('id').replace('_' + id, ''), |
| … |
… |
inlineEditPost = { |
| 240 | 389 | return false; |
| 241 | 390 | }, |
| 242 | 391 | |
| 243 | | // Ajax saving is only for Quick Edit. |
| | 392 | |
| | 393 | /** |
| | 394 | * @summary Saves the changes made in the quick edit window to the post. |
| | 395 | * AJAX saving is only for Quick Edit and not for bulk edit. |
| | 396 | * |
| | 397 | * @since 2.7.0 |
| | 398 | * |
| | 399 | * @param {int} id The id for the post that has been changed. |
| | 400 | * |
| | 401 | * @returns {boolean} Returns false so the form does not submit |
| | 402 | * when pressing Enter on a focused field. |
| | 403 | */ |
| 244 | 404 | save : function(id) { |
| 245 | 405 | var params, fields, page = $('.post_status_page').val() || ''; |
| 246 | 406 | |
| … |
… |
inlineEditPost = { |
| 293 | 453 | return false; |
| 294 | 454 | }, |
| 295 | 455 | |
| 296 | | // Revert is for both Quick Edit and Bulk Edit. |
| | 456 | /** |
| | 457 | * @summary Hides and empties the Quick Edit and/or Bulk Edit windows. |
| | 458 | * |
| | 459 | * @memberof inlineEditPost |
| | 460 | * @since 2.7.0 |
| | 461 | * |
| | 462 | * @returns {boolean} Always returns false. |
| | 463 | */ |
| 297 | 464 | revert : function(){ |
| 298 | 465 | var $tableWideFat = $( '.widefat' ), |
| 299 | 466 | id = $( '.inline-editor', $tableWideFat ).attr( 'id' ); |
| … |
… |
inlineEditPost = { |
| 303 | 470 | $( '.ac_results' ).hide(); |
| 304 | 471 | |
| 305 | 472 | if ( 'bulk-edit' === id ) { |
| | 473 | // Hide the bulk editor. |
| 306 | 474 | $( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove(); |
| 307 | 475 | $('#bulk-titles').empty(); |
| | 476 | // Store the empty bulk editor in a hidden element. |
| 308 | 477 | $('#inlineedit').append( $('#bulk-edit') ); |
| 309 | 478 | // Move focus back to the Bulk Action button that was activated. |
| 310 | 479 | $( '#' + inlineEditPost.whichBulkButtonId ).focus(); |
| 311 | 480 | } else { |
| | 481 | // Remove both the inline-editor and its hidden tr siblings. |
| 312 | 482 | $('#'+id).siblings('tr.hidden').addBack().remove(); |
| 313 | 483 | id = id.substr( id.lastIndexOf('-') + 1 ); |
| 314 | 484 | // Show the post row and move focus back to the Quick Edit link. |
| … |
… |
inlineEditPost = { |
| 319 | 489 | return false; |
| 320 | 490 | }, |
| 321 | 491 | |
| | 492 | /** |
| | 493 | * @summary Gets the id for a the post that you want to quick edit from the row |
| | 494 | * in the quick edit table. |
| | 495 | * |
| | 496 | * @memberof inlineEditPost |
| | 497 | * @since 2.7.0 |
| | 498 | * |
| | 499 | * @param {Object} o DOM row object to get the id for. |
| | 500 | * |
| | 501 | * @returns {string} The post id extracted from the table row in the object. |
| | 502 | */ |
| 322 | 503 | getId : function(o) { |
| 323 | 504 | var id = $(o).closest('tr').attr('id'), |
| 324 | 505 | parts = id.split('-'); |