woocommerce/assets/js/admin/product-ordering.js

55 lines
2.2 KiB
JavaScript
Raw Normal View History

/**
* Based on Simple Page Ordering by 10up (http://wordpress.org/extend/plugins/simple-page-ordering/)
*
* Modified - products have no children (non hierarchical)
*/
jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
2013-01-22 16:48:28 +00:00
jQuery("table.widefat tbody").sortable({
items: 'tr:not(.inline-edit-row)',
cursor: 'move',
axis: 'y',
containment: 'table.widefat',
scrollSensitivity: 40,
2013-01-22 16:48:28 +00:00
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' );
},
2013-01-22 16:48:28 +00:00
stop: function(event, ui) {
ui.item.removeAttr('style');
ui.item.children('td,th').css('border-bottom-width','1px');
},
2013-01-22 16:48:28 +00:00
update: function(event, ui) {
jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','default');
jQuery("table.widefat tbody").sortable('disable');
2013-01-22 16:48:28 +00:00
var postid = ui.item.find('.check-column input').val(); // this post id
var postparent = ui.item.find('.post_parent').html(); // post parent
2013-01-22 16:48:28 +00:00
var prevpostid = ui.item.prev().find('.check-column input').val();
var nextpostid = ui.item.next().find('.check-column input').val();
2013-01-22 16:48:28 +00:00
// show spinner
ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');
2013-01-22 16:48:28 +00:00
// go do the sorting stuff via ajax
2013-01-22 16:48:28 +00:00
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');
});
2013-01-22 16:48:28 +00:00
// 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');
});
}
});