| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| window.wp = window.wp || {}; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ( function( $, wp ) { |
|
|
| window.inlineEditPost = { |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| init : function(){ |
| var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); |
|
|
| t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; |
| |
| t.what = '#post-'; |
|
|
| |
| |
| |
| |
| |
| qeRow.on( 'keyup', function(e){ |
| |
| if ( e.which === 27 ) { |
| return inlineEditPost.revert(); |
| } |
| }); |
|
|
| |
| |
| |
| |
| |
| bulkRow.on( 'keyup', function(e){ |
| |
| if ( e.which === 27 ) { |
| return inlineEditPost.revert(); |
| } |
| }); |
|
|
| |
| |
| |
| |
| |
| $( '.cancel', qeRow ).on( 'click', function() { |
| return inlineEditPost.revert(); |
| }); |
|
|
| |
| |
| |
| |
| |
| $( '.save', qeRow ).on( 'click', function() { |
| return inlineEditPost.save(this); |
| }); |
|
|
| |
| |
| |
| |
| |
| $('td', qeRow).on( 'keydown', function(e){ |
| if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) { |
| return inlineEditPost.save(this); |
| } |
| }); |
|
|
| |
| |
| |
| |
| |
| $( '.cancel', bulkRow ).on( 'click', function() { |
| return inlineEditPost.revert(); |
| }); |
|
|
| |
| |
| |
| $('#inline-edit .inline-edit-private input[value="private"]').on( 'click', function(){ |
| var pw = $('input.inline-edit-password-input'); |
| if ( $(this).prop('checked') ) { |
| pw.val('').prop('disabled', true); |
| } else { |
| pw.prop('disabled', false); |
| } |
| }); |
|
|
| |
| |
| |
| $( '#the-list' ).on( 'click', '.editinline', function() { |
| $( this ).attr( 'aria-expanded', 'true' ); |
| inlineEditPost.edit( this ); |
| }); |
|
|
| $('#bulk-edit').find('fieldset:first').after( |
| $('#inline-edit fieldset.inline-edit-categories').clone() |
| ).siblings( 'fieldset:last' ).prepend( |
| $( '#inline-edit .inline-edit-tags-wrap' ).clone() |
| ); |
|
|
| $('select[name="_status"] option[value="future"]', bulkRow).remove(); |
|
|
| |
| |
| |
| $('#doaction').on( 'click', function(e){ |
| var n; |
|
|
| t.whichBulkButtonId = $( this ).attr( 'id' ); |
| n = t.whichBulkButtonId.substr( 2 ); |
|
|
| if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) { |
| e.preventDefault(); |
| t.setBulk(); |
| } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { |
| t.revert(); |
| } |
| }); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| toggle : function(el){ |
| var t = this; |
| $( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el ); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| setBulk : function(){ |
| var te = '', type = this.type, c = true; |
| var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' ); |
| var categories = {}; |
| this.revert(); |
|
|
| $( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
|
|
| |
| $('table.widefat tbody').prepend( $('#bulk-edit') ).prepend('<tr class="hidden"></tr>'); |
| $('#bulk-edit').addClass('inline-editor').show(); |
|
|
| |
| |
| |
| |
| |
| |
| $( 'tbody th.check-column input[type="checkbox"]' ).each( function() { |
|
|
| |
| if ( $(this).prop('checked') ) { |
| c = false; |
| var id = $( this ).val(), |
| theTitle = $( '#inline_' + id + ' .post_title' ).html() || wp.i18n.__( '(no title)' ), |
| buttonVisuallyHiddenText = wp.i18n.sprintf( |
| |
| wp.i18n.__( 'Remove “%s” from Bulk Edit' ), |
| theTitle |
| ); |
|
|
| te += '<li class="ntdelitem"><button type="button" id="_' + id + '" class="button-link ntdelbutton"><span class="screen-reader-text">' + buttonVisuallyHiddenText + '</span></button><span class="ntdeltitle" aria-hidden="true">' + theTitle + '</span></li>'; |
| } |
| }); |
|
|
| |
| if ( c ) { |
| return this.revert(); |
| } |
|
|
| |
| $( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' ); |
|
|
| |
| checkedPosts.each( function() { |
| var id = $( this ).val(); |
| var checked = $( '#category_' + id ).text().split( ',' ); |
|
|
| checked.map( function( cid ) { |
| categories[ cid ] || ( categories[ cid ] = 0 ); |
| |
| categories[ cid ]++; |
| } ); |
| } ); |
|
|
| |
| $( '.inline-edit-categories input[name="post_category[]"]' ).each( function() { |
| if ( categories[ $( this ).val() ] == checkedPosts.length ) { |
| |
| $( this ).prop( 'checked', true ); |
| } else if ( categories[ $( this ).val() ] > 0 ) { |
| |
| $( this ).prop( 'indeterminate', true ); |
| if ( ! $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).length ) { |
| |
| var label = $( this ).parent().text(); |
| |
| $( this ).after( '<input type="hidden" name="indeterminate_post_category[]" value="' + $( this ).val() + '">' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) ); |
| } |
| } |
| } ); |
|
|
| $( '.inline-edit-categories input[name="post_category[]"]:indeterminate' ).on( 'change', function() { |
| |
| $( this ).removeAttr( 'aria-label' ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove(); |
| } ); |
|
|
| $( '.inline-edit-save button' ).on( 'click', function() { |
| $( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false ); |
| } ); |
|
|
| |
| |
| |
| |
| |
| $( '#bulk-titles .ntdelbutton' ).click( function() { |
| var $this = $( this ), |
| id = $this.attr( 'id' ).substr( 1 ), |
| $prev = $this.parent().prev().children( '.ntdelbutton' ), |
| $next = $this.parent().next().children( '.ntdelbutton' ); |
|
|
| $( 'input#cb-select-all-1, input#cb-select-all-2' ).prop( 'checked', false ); |
| $( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false ); |
| $( '#_' + id ).parent().remove(); |
| wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' ); |
|
|
| |
| if ( $next.length ) { |
| $next.focus(); |
| } else if ( $prev.length ) { |
| $prev.focus(); |
| } else { |
| $( '#bulk-titles-list' ).remove(); |
| inlineEditPost.revert(); |
| wp.a11y.speak( wp.i18n.__( 'All selected items have been removed. Select new items to use Bulk Actions.' ) ); |
| } |
| }); |
|
|
| |
| if ( 'post' === type ) { |
| $( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) { |
| |
| |
| |
| |
| if ( $( element ).autocomplete( 'instance' ) ) { |
| |
| return; |
| } |
|
|
| $( element ).wpTagsSuggest(); |
| } ); |
| } |
|
|
| |
| $( '#bulk-edit .inline-edit-wrapper' ).attr( 'tabindex', '-1' ).focus(); |
| |
| $('html, body').animate( { scrollTop: 0 }, 'fast' ); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| edit : function(id) { |
| var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw; |
| t.revert(); |
|
|
| if ( typeof(id) === 'object' ) { |
| id = t.getId(id); |
| } |
|
|
| fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order', 'page_template']; |
| if ( t.type === 'page' ) { |
| fields.push('post_parent'); |
| } |
|
|
| |
| editRow = $('#inline-edit').clone(true); |
| $( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
|
|
| |
| $( 'td', editRow ).find('#quick-edit-legend').removeAttr('id'); |
| $( 'td', editRow ).find('p[id^="quick-edit-"]').removeAttr('id'); |
|
|
| $(t.what+id).removeClass('is-expanded').hide().after(editRow).after('<tr class="hidden"></tr>'); |
|
|
| |
| rowData = $('#inline_'+id); |
| if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { |
|
|
| |
| $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#post-' + id + ' .author').text() + '</option>'); |
| } |
| if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) { |
| $('label.inline-edit-author', editRow).hide(); |
| } |
|
|
| for ( f = 0; f < fields.length; f++ ) { |
| val = $('.'+fields[f], rowData); |
|
|
| |
| |
| |
| |
| |
| val.find( 'img' ).replaceWith( function() { return this.alt; } ); |
| val = val.text(); |
| $(':input[name="' + fields[f] + '"]', editRow).val( val ); |
| } |
|
|
| if ( $( '.comment_status', rowData ).text() === 'open' ) { |
| $( 'input[name="comment_status"]', editRow ).prop( 'checked', true ); |
| } |
| if ( $( '.ping_status', rowData ).text() === 'open' ) { |
| $( 'input[name="ping_status"]', editRow ).prop( 'checked', true ); |
| } |
| if ( $( '.sticky', rowData ).text() === 'sticky' ) { |
| $( 'input[name="sticky"]', editRow ).prop( 'checked', true ); |
| } |
|
|
| |
| |
| |
| $('.post_category', rowData).each(function(){ |
| var taxname, |
| term_ids = $(this).text(); |
|
|
| if ( term_ids ) { |
| taxname = $(this).attr('id').replace('_'+id, ''); |
| $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); |
| } |
| }); |
|
|
| |
| |
| |
| |
| $('.tags_input', rowData).each(function(){ |
| var terms = $(this), |
| taxname = $(this).attr('id').replace('_' + id, ''), |
| textarea = $('textarea.tax_input_' + taxname, editRow), |
| comma = wp.i18n._x( ',', 'tag delimiter' ).trim(); |
|
|
| |
| if ( ! textarea.length ) { |
| return; |
| } |
|
|
| terms.find( 'img' ).replaceWith( function() { return this.alt; } ); |
| terms = terms.text(); |
|
|
| if ( terms ) { |
| if ( ',' !== comma ) { |
| terms = terms.replace(/,/g, comma); |
| } |
| textarea.val(terms); |
| } |
|
|
| textarea.wpTagsSuggest(); |
| }); |
|
|
| |
| var post_date_string = $(':input[name="aa"]').val() + '-' + $(':input[name="mm"]').val() + '-' + $(':input[name="jj"]').val(); |
| post_date_string += ' ' + $(':input[name="hh"]').val() + ':' + $(':input[name="mn"]').val() + ':' + $(':input[name="ss"]').val(); |
| var post_date = new Date( post_date_string ); |
| status = $('._status', rowData).text(); |
| if ( 'future' !== status && Date.now() > post_date ) { |
| $('select[name="_status"] option[value="future"]', editRow).remove(); |
| } else { |
| $('select[name="_status"] option[value="publish"]', editRow).remove(); |
| } |
|
|
| pw = $( '.inline-edit-password-input' ).prop( 'disabled', false ); |
| if ( 'private' === status ) { |
| $('input[name="keep_private"]', editRow).prop('checked', true); |
| pw.val( '' ).prop( 'disabled', true ); |
| } |
|
|
| |
| pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow); |
| if ( pageOpt.length > 0 ) { |
| pageLevel = pageOpt[0].className.split('-')[1]; |
| nextPage = pageOpt; |
| while ( pageLoop ) { |
| nextPage = nextPage.next('option'); |
| if ( nextPage.length === 0 ) { |
| break; |
| } |
|
|
| nextLevel = nextPage[0].className.split('-')[1]; |
|
|
| if ( nextLevel <= pageLevel ) { |
| pageLoop = false; |
| } else { |
| nextPage.remove(); |
| nextPage = pageOpt; |
| } |
| } |
| pageOpt.remove(); |
| } |
|
|
| $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
| $('.ptitle', editRow).trigger( 'focus' ); |
|
|
| return false; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| save : function(id) { |
| var params, fields, page = $('.post_status_page').val() || ''; |
|
|
| if ( typeof(id) === 'object' ) { |
| id = this.getId(id); |
| } |
|
|
| $( 'table.widefat .spinner' ).addClass( 'is-active' ); |
|
|
| params = { |
| action: 'inline-save', |
| post_type: typenow, |
| post_ID: id, |
| edit_date: 'true', |
| post_status: page |
| }; |
|
|
| fields = $('#edit-'+id).find(':input').serialize(); |
| params = fields + '&' + $.param(params); |
|
|
| |
| $.post( ajaxurl, params, |
| function(r) { |
| var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ), |
| $error = $errorNotice.find( '.error' ); |
|
|
| $( 'table.widefat .spinner' ).removeClass( 'is-active' ); |
|
|
| if (r) { |
| if ( -1 !== r.indexOf( '<tr' ) ) { |
| $(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove(); |
| $('#edit-'+id).before(r).remove(); |
| $( inlineEditPost.what + id ).hide().fadeIn( 400, function() { |
| |
| $( this ).find( '.editinline' ) |
| .attr( 'aria-expanded', 'false' ) |
| .trigger( 'focus' ); |
| wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) ); |
| }); |
| } else { |
| r = r.replace( /<.[^<>]*?>/g, '' ); |
| $errorNotice.removeClass( 'hidden' ); |
| $error.html( r ); |
| wp.a11y.speak( $error.text() ); |
| } |
| } else { |
| $errorNotice.removeClass( 'hidden' ); |
| $error.text( wp.i18n.__( 'Error while saving the changes.' ) ); |
| wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) ); |
| } |
| }, |
| 'html'); |
|
|
| |
| return false; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| revert : function(){ |
| var $tableWideFat = $( '.widefat' ), |
| id = $( '.inline-editor', $tableWideFat ).attr( 'id' ); |
|
|
| if ( id ) { |
| $( '.spinner', $tableWideFat ).removeClass( 'is-active' ); |
|
|
| if ( 'bulk-edit' === id ) { |
|
|
| |
| $( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove(); |
| $('#bulk-titles').empty(); |
|
|
| |
| $('#inlineedit').append( $('#bulk-edit') ); |
|
|
| |
| $( '#' + inlineEditPost.whichBulkButtonId ).trigger( 'focus' ); |
| } else { |
|
|
| |
| $('#'+id).siblings('tr.hidden').addBack().remove(); |
| id = id.substr( id.lastIndexOf('-') + 1 ); |
|
|
| |
| $( this.what + id ).show().find( '.editinline' ) |
| .attr( 'aria-expanded', 'false' ) |
| .trigger( 'focus' ); |
| } |
| } |
|
|
| return false; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| getId : function(o) { |
| var id = $(o).closest('tr').attr('id'), |
| parts = id.split('-'); |
| return parts[parts.length - 1]; |
| } |
| }; |
|
|
| $( function() { inlineEditPost.init(); } ); |
|
|
| |
| $( function() { |
|
|
| |
| if ( typeof wp !== 'undefined' && wp.heartbeat ) { |
| wp.heartbeat.interval( 15 ); |
| } |
| }).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { |
| var locked = data['wp-check-locked-posts'] || {}; |
|
|
| $('#the-list tr').each( function(i, el) { |
| var key = el.id, row = $(el), lock_data, avatar; |
|
|
| if ( locked.hasOwnProperty( key ) ) { |
| if ( ! row.hasClass('wp-locked') ) { |
| lock_data = locked[key]; |
| row.find('.column-title .locked-text').text( lock_data.text ); |
| row.find('.check-column checkbox').prop('checked', false); |
|
|
| if ( lock_data.avatar_src ) { |
| avatar = $( '<img />', { |
| 'class': 'avatar avatar-18 photo', |
| width: 18, |
| height: 18, |
| alt: '', |
| src: lock_data.avatar_src, |
| srcset: lock_data.avatar_src_2x ? lock_data.avatar_src_2x + ' 2x' : undefined |
| } ); |
| row.find('.column-title .locked-avatar').empty().append( avatar ); |
| } |
| row.addClass('wp-locked'); |
| } |
| } else if ( row.hasClass('wp-locked') ) { |
| row.removeClass( 'wp-locked' ).find( '.locked-info span' ).empty(); |
| } |
| }); |
| }).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) { |
| var check = []; |
|
|
| $('#the-list tr').each( function(i, el) { |
| if ( el.id ) { |
| check.push( el.id ); |
| } |
| }); |
|
|
| if ( check.length ) { |
| data['wp-check-locked-posts'] = check; |
| } |
| }); |
|
|
| })( jQuery, window.wp ); |
|
|