Add sort handle column when adding new tags.

This commit is contained in:
Peter Fabian 2018-04-26 15:11:00 +02:00
parent a04c54a896
commit 9b154b961e
2 changed files with 19 additions and 5 deletions

View File

@ -5,19 +5,33 @@ jQuery( function( $ ) {
var table_selector = 'table.wp-list-table',
item_selector = 'tbody tr:not(.inline-edit-row)',
term_id_selector = '.column-handle input[name="term_id"]';
term_id_selector = '.column-handle input[name="term_id"]',
column_handle = '<td class="column-handle"></td>';
if ( 0 === $( table_selector ).find( '.column-handle' ).length ) {
$( table_selector ).find( 'tr:not(.inline-edit-row)' ).append( '<td class="column-handle"></td>' );
$( table_selector ).find( 'tr:not(.inline-edit-row)' ).append( column_handle );
term_id_selector = '.check-column input';
}
$( table_selector ).find( '.column-handle' ).show();
$( document ).ajaxComplete( function( event, request, options ) {
if ( request && 4 === request.readyState && 200 === request.status && options.data && 0 <= options.data.indexOf( '_inline_edit' ) ) {
$.wc_add_missing_sort_handles = function() {
var all_table_rows = $( table_selector ).find('tbody > tr');
var rows_with_handle = $( table_selector ).find('tbody > tr > td.column-handle').parent();
if ( all_table_rows.length !== rows_with_handle.length ) {
all_table_rows.each(function(index, elem){
if ( ! rows_with_handle.is( elem ) ) {
$( elem ).append( column_handle );
}
});
}
$( table_selector ).find( '.column-handle' ).show();
};
$( document ).ajaxComplete( function( event, request, options ) {
if ( request && 4 === request.readyState && 200 === request.status && options.data && ( 0 <= options.data.indexOf( '_inline_edit' ) || 0 <= options.data.indexOf( 'add-tag' ) ) ) {
$.wc_add_missing_sort_handles();
$( document.body ).trigger( 'init_tooltips' );
}
} );

View File

@ -1 +1 @@
jQuery(function(e){var t="table.wp-list-table",n='.column-handle input[name="term_id"]';0===e(t).find(".column-handle").length&&(e(t).find("tr:not(.inline-edit-row)").append('<td class="column-handle"></td>'),n=".check-column input"),e(t).find(".column-handle").show(),e(document).ajaxComplete(function(n,i,d){i&&4===i.readyState&&200===i.status&&d.data&&0<=d.data.indexOf("_inline_edit")&&(e(t).find(".column-handle").show(),e(document.body).trigger("init_tooltips"))}),e(t).sortable({items:"tbody tr:not(.inline-edit-row)",cursor:"move",handle:".column-handle",axis:"y",forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"product-cat-placeholder",scrollSensitivity:40,start:function(e,t){t.item.hasClass("alternate")||t.item.css("background-color","#ffffff"),t.item.children("td, th").css("border-bottom-width","0"),t.item.css("outline","1px solid #aaa")},stop:function(e,t){t.item.removeAttr("style"),t.item.children("td, th").css("border-bottom-width","1px")},update:function(i,d){var o,a,l=d.item.find(n).val(),r=d.item.find(".parent").html(),c=d.item.prev().find(n).val(),m=d.item.next().find(n).val();c!==undefined&&(o=d.item.prev().find(".parent").html())!==r&&(c=undefined),m!==undefined&&(a=d.item.next().find(".parent").html())!==r&&(m=undefined),c===undefined&&m===undefined||m===undefined&&a===c||m!==undefined&&o===l?e(t).sortable("cancel"):(d.item.find(".check-column input").hide(),d.item.find(".check-column").append('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),e.post(ajaxurl,{action:"woocommerce_term_ordering",id:l,nextid:m,thetaxonomy:woocommerce_term_ordering_params.taxonomy},function(e){"children"===e?window.location.reload():(d.item.find(".check-column input").show(),d.item.find(".check-column").find("img").remove())}),e("table.widefat tbody tr").each(function(){jQuery("table.widefat tbody tr").index(this)%2==0?jQuery(this).addClass("alternate"):jQuery(this).removeClass("alternate")}))}})});
jQuery(function(e){var t="table.wp-list-table",n='.column-handle input[name="term_id"]';0===e(t).find(".column-handle").length&&(e(t).find("tr:not(.inline-edit-row)").append('<td class="column-handle"></td>'),n=".check-column input"),e(t).find(".column-handle").show(),e.wc_add_missing_sort_handles=function(){var n=e(t).find("tbody > tr"),i=e(t).find("tbody > tr > td.column-handle").parent();n.length!==i.length&&n.each(function(t,n){i.is(n)||e(n).append('<td class="column-handle"></td>')}),e(t).find(".column-handle").show()},e(document).ajaxComplete(function(t,n,i){n&&4===n.readyState&&200===n.status&&i.data&&(0<=i.data.indexOf("_inline_edit")||0<=i.data.indexOf("add-tag"))&&(e.wc_add_missing_sort_handles(),e(document.body).trigger("init_tooltips"))}),e(t).sortable({items:"tbody tr:not(.inline-edit-row)",cursor:"move",handle:".column-handle",axis:"y",forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"product-cat-placeholder",scrollSensitivity:40,start:function(e,t){t.item.hasClass("alternate")||t.item.css("background-color","#ffffff"),t.item.children("td, th").css("border-bottom-width","0"),t.item.css("outline","1px solid #aaa")},stop:function(e,t){t.item.removeAttr("style"),t.item.children("td, th").css("border-bottom-width","1px")},update:function(i,d){var a,o,l=d.item.find(n).val(),c=d.item.find(".parent").html(),r=d.item.prev().find(n).val(),m=d.item.next().find(n).val();r!==undefined&&(a=d.item.prev().find(".parent").html())!==c&&(r=undefined),m!==undefined&&(o=d.item.next().find(".parent").html())!==c&&(m=undefined),r===undefined&&m===undefined||m===undefined&&o===r||m!==undefined&&a===l?e(t).sortable("cancel"):(d.item.find(".check-column input").hide(),d.item.find(".check-column").append('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),e.post(ajaxurl,{action:"woocommerce_term_ordering",id:l,nextid:m,thetaxonomy:woocommerce_term_ordering_params.taxonomy},function(e){"children"===e?window.location.reload():(d.item.find(".check-column input").show(),d.item.find(".check-column").find("img").remove())}),e("table.widefat tbody tr").each(function(){jQuery("table.widefat tbody tr").index(this)%2==0?jQuery(this).addClass("alternate"):jQuery(this).removeClass("alternate")}))}})});