From c4082c6867f0ca4c8354ff4f4983a6fb75f68ca4 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 2 Aug 2014 21:05:44 -0300 Subject: [PATCH] On reordering products the cells of the placeholder need to match the attributes of the original row cells, otherwise the width gets messed up --- assets/js/admin/product-ordering.js | 105 ++++++++++++++++------------ 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/assets/js/admin/product-ordering.js b/assets/js/admin/product-ordering.js index f8142026601..91d6a9373e3 100644 --- a/assets/js/admin/product-ordering.js +++ b/assets/js/admin/product-ordering.js @@ -3,53 +3,70 @@ * * Modified - products have no children (non hierarchical) */ -jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); +( function( $ ){ +$( document ).ready(function(){ + $('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); -jQuery("table.widefat tbody").sortable({ - items: 'tr:not(.inline-edit-row)', - cursor: 'move', - axis: 'y', - containment: 'table.widefat', - scrollSensitivity: 40, - helper: function(e, ui) { - ui.children().each(function() { jQuery(this).width(jQuery(this).width()); }); - return ui; - }, - start: function(event, ui) { - if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' ); - ui.item.children('td,th').css('border-bottom-width','0'); - ui.item.css( 'outline', '1px solid #dfdfdf' ); - }, - stop: function(event, ui) { - ui.item.removeAttr('style'); - ui.item.children('td,th').css('border-bottom-width','1px'); - }, - update: function(event, ui) { - jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','default'); - jQuery("table.widefat tbody").sortable('disable'); + $("table.widefat tbody").sortable({ + items: 'tr:not(.inline-edit-row)', + cursor: 'move', + axis: 'y', + containment: 'table.widefat', + scrollSensitivity: 40, + helper: function(event, ui) { + ui.each(function() { $(this).width($(this).width()); }); + return ui; + }, + start: function(event, ui) { + ui.placeholder.children().each(function(){ + var $original = ui.item.children().eq( ui.placeholder.children().index(this) ), + $this = $( this ); - var postid = ui.item.find('.check-column input').val(); // this post id - var postparent = ui.item.find('.post_parent').html(); // post parent + $.each( $original[0].attributes, function( k, attr ){ + $this.attr( attr.name, attr.value ); + } ); + }); + if ( ! ui.item.hasClass('alternate') ) { + ui.item.css( 'background-color', '#ffffff' ); + } + ui.item.children('td,th').css('border-bottom-width','0'); + ui.item.css( 'outline', '1px solid #dfdfdf' ); + }, + stop: function(event, ui) { + ui.item.removeAttr('style'); + ui.item.children('td,th').css('border-bottom-width','1px'); + }, + update: function(event, ui) { + $('table.widefat tbody th, table.widefat tbody td').css('cursor','default'); + $("table.widefat tbody").sortable('disable'); - var prevpostid = ui.item.prev().find('.check-column input').val(); - var nextpostid = ui.item.next().find('.check-column input').val(); + var postid = ui.item.find('.check-column input').val(); // this post id + var postparent = ui.item.find('.post_parent').html(); // post parent - // show spinner - ui.item.find('.check-column input').hide().after('processing'); + var prevpostid = ui.item.prev().find('.check-column input').val(); + var nextpostid = ui.item.next().find('.check-column input').val(); - // go do the sorting stuff via ajax - jQuery.post( ajaxurl, { action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){ - jQuery.each(response, function(key,value) { jQuery('#inline_'+key+' .menu_order').html(value); }); - ui.item.find('.check-column input').show().siblings('img').remove(); - jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); - jQuery("table.widefat tbody").sortable('enable'); - }); + // show spinner + ui.item.find('.check-column input').hide().after('processing'); - // fix cell colors - jQuery( 'table.widefat tbody tr' ).each(function(){ - var i = jQuery('table.widefat tbody tr').index(this); - if ( i%2 == 0 ) jQuery(this).addClass('alternate'); - else jQuery(this).removeClass('alternate'); - }); - } -}); \ No newline at end of file + // go do the sorting stuff via ajax + $.post( ajaxurl, { action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){ + $.each(response, function(key,value) { $('#inline_'+key+' .menu_order').html(value); }); + ui.item.find('.check-column input').show().siblings('img').remove(); + $('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); + $("table.widefat tbody").sortable('enable'); + }); + + // fix cell colors + $( 'table.widefat tbody tr' ).each(function(){ + var i = $('table.widefat tbody tr').index(this); + if ( i%2 === 0 ){ + $(this).addClass('alternate'); + } else { + $(this).removeClass('alternate'); + } + }); + } + }); +}); +}( jQuery ) );