2015-07-10 04:32:30 +00:00
|
|
|
/*global ajaxurl */
|
|
|
|
|
2012-05-08 19:30:18 +00:00
|
|
|
/**
|
2016-10-11 23:37:15 +00:00
|
|
|
* Based on Simple Page Ordering by 10up (https://wordpress.org/plugins/simple-page-ordering/)
|
2012-05-08 19:30:18 +00:00
|
|
|
*
|
|
|
|
* Modified - products have no children (non hierarchical)
|
|
|
|
*/
|
2015-07-10 04:32:30 +00:00
|
|
|
jQuery( function( $ ) {
|
2015-06-04 12:06:01 +00:00
|
|
|
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
|
2013-01-22 16:48:28 +00:00
|
|
|
|
2015-06-04 12:06:01 +00:00
|
|
|
$( 'table.widefat tbody' ).sortable({
|
2014-08-03 00:05:44 +00:00
|
|
|
items: 'tr:not(.inline-edit-row)',
|
|
|
|
cursor: 'move',
|
|
|
|
axis: 'y',
|
|
|
|
containment: 'table.widefat',
|
|
|
|
scrollSensitivity: 40,
|
2015-06-04 12:06:01 +00:00
|
|
|
helper: function( event, ui ) {
|
|
|
|
ui.each( function() {
|
|
|
|
$( this ).width( $( this ).width() );
|
|
|
|
});
|
2014-08-03 00:05:44 +00:00
|
|
|
return ui;
|
|
|
|
},
|
2015-06-04 12:06:01 +00:00
|
|
|
start: function( event, ui ) {
|
2017-03-06 14:33:48 +00:00
|
|
|
ui.item.css( 'background-color', '#ffffff' );
|
2015-06-04 12:06:01 +00:00
|
|
|
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
|
2014-08-03 00:05:44 +00:00
|
|
|
ui.item.css( 'outline', '1px solid #dfdfdf' );
|
|
|
|
},
|
2015-06-04 12:06:01 +00:00
|
|
|
stop: function( event, ui ) {
|
|
|
|
ui.item.removeAttr( 'style' );
|
|
|
|
ui.item.children( 'td,th' ).css( 'border-bottom-width', '1px' );
|
2014-08-03 00:05:44 +00:00
|
|
|
},
|
2015-06-04 12:06:01 +00:00
|
|
|
update: function( event, ui ) {
|
|
|
|
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' );
|
|
|
|
$( 'table.widefat tbody' ).sortable( 'disable' );
|
2013-01-22 16:48:28 +00:00
|
|
|
|
2015-06-04 12:06:58 +00:00
|
|
|
var postid = ui.item.find( '.check-column input' ).val();
|
2015-06-04 12:06:01 +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
|
|
|
|
2015-06-04 12:06:01 +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
|
|
|
|
2015-06-04 12:06:01 +00:00
|
|
|
// 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' );
|
2014-08-03 00:05:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// fix cell colors
|
2015-06-04 12:06:01 +00:00
|
|
|
$( 'table.widefat tbody tr' ).each( function() {
|
|
|
|
var i = $( 'table.widefat tbody tr' ).index( this );
|
|
|
|
if ( i%2 === 0 ) {
|
|
|
|
$( this ).addClass( 'alternate' );
|
2014-08-03 00:05:44 +00:00
|
|
|
} else {
|
2015-06-04 12:06:01 +00:00
|
|
|
$( this ).removeClass( 'alternate' );
|
2014-08-03 00:05:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|