Merge pull request #8290 from shivapoudel/jshint-tweaks

Tweaks product and term ordering
This commit is contained in:
Claudio Sanches 2015-06-05 11:52:16 -03:00
commit f2e6a9e400
2 changed files with 85 additions and 74 deletions

View File

@ -3,67 +3,69 @@
* *
* Modified - products have no children (non hierarchical) * Modified - products have no children (non hierarchical)
*/ */
( function( $ ){ ( function( $ ) {
$( document ).ready(function(){ $( document ).ready( function() {
$('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); $( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$("table.widefat tbody").sortable({ $( 'table.widefat tbody' ).sortable({
items: 'tr:not(.inline-edit-row)', items: 'tr:not(.inline-edit-row)',
cursor: 'move', cursor: 'move',
axis: 'y', axis: 'y',
containment: 'table.widefat', containment: 'table.widefat',
scrollSensitivity: 40, scrollSensitivity: 40,
helper: function(event, ui) { helper: function( event, ui ) {
ui.each(function() { $(this).width($(this).width()); }); ui.each( function() {
$( this ).width( $( this ).width() );
});
return ui; return ui;
}, },
start: function(event, ui) { start: function( event, ui ) {
ui.placeholder.children().each(function(){ ui.placeholder.children().each( function() {
var $original = ui.item.children().eq( ui.placeholder.children().index(this) ), var $original = ui.item.children().eq( ui.placeholder.children().index( this ) ),
$this = $( this ); $this = $( this );
$.each( $original[0].attributes, function( k, attr ){ $.each( $original[0].attributes, function( k, attr ) {
$this.attr( attr.name, attr.value ); $this.attr( attr.name, attr.value );
} );
}); });
if ( ! ui.item.hasClass('alternate') ) { });
if ( ! ui.item.hasClass( 'alternate' ) ) {
ui.item.css( 'background-color', '#ffffff' ); ui.item.css( 'background-color', '#ffffff' );
} }
ui.item.children('td,th').css('border-bottom-width','0'); ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
ui.item.css( 'outline', '1px solid #dfdfdf' ); ui.item.css( 'outline', '1px solid #dfdfdf' );
}, },
stop: function(event, ui) { stop: function( event, ui ) {
ui.item.removeAttr('style'); ui.item.removeAttr( 'style' );
ui.item.children('td,th').css('border-bottom-width','1px'); ui.item.children( 'td,th' ).css( 'border-bottom-width', '1px' );
}, },
update: function(event, ui) { update: function( event, ui ) {
$('table.widefat tbody th, table.widefat tbody td').css('cursor','default'); $( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' );
$("table.widefat tbody").sortable('disable'); $( 'table.widefat tbody' ).sortable( 'disable' );
var postid = ui.item.find('.check-column input').val(); // this post id var postid = ui.item.find( '.check-column input' ).val();
var postparent = ui.item.find('.post_parent').html(); // post parent var prevpostid = ui.item.prev().find( '.check-column input' ).val();
var nextpostid = ui.item.next().find( '.check-column input' ).val();
var prevpostid = ui.item.prev().find('.check-column input').val(); // Show Spinner
var nextpostid = ui.item.next().find('.check-column input').val(); ui.item.find( '.check-column input' ).hide().after( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
// show spinner // Go do the sorting stuff via ajax
ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'); $.post( ajaxurl, { action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function( response ) {
$.each( response, function( key, value ) {
// go do the sorting stuff via ajax $( '#inline_' + key + ' .menu_order' ).html( value );
$.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();
ui.item.find('.check-column input').show().siblings('img').remove(); $( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); $( 'table.widefat tbody' ).sortable( 'enable' );
$("table.widefat tbody").sortable('enable');
}); });
// fix cell colors // fix cell colors
$( 'table.widefat tbody tr' ).each(function(){ $( 'table.widefat tbody tr' ).each( function() {
var i = $('table.widefat tbody tr').index(this); var i = $( 'table.widefat tbody tr' ).index( this );
if ( i%2 === 0 ){ if ( i%2 === 0 ) {
$(this).addClass('alternate'); $( this ).addClass( 'alternate' );
} else { } else {
$(this).removeClass('alternate'); $( this ).removeClass( 'alternate' );
} }
}); });
} }

View File

@ -1,9 +1,9 @@
/* Modifided script from the simple-page-ordering plugin */ /* Modifided script from the simple-page-ordering plugin */
jQuery(function($) { jQuery( function( $ ) {
$('table.widefat.wp-list-table tbody th, table.widefat tbody td').css('cursor','move'); $( 'table.widefat.wp-list-table tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$("table.widefat.wp-list-table").sortable({ $( 'table.widefat.wp-list-table' ).sortable({
items: 'tbody tr:not(.inline-edit-row)', items: 'tbody tr:not(.inline-edit-row)',
cursor: 'move', cursor: 'move',
axis: 'y', axis: 'y',
@ -12,57 +12,66 @@ jQuery(function($) {
opacity: 0.65, opacity: 0.65,
placeholder: 'product-cat-placeholder', placeholder: 'product-cat-placeholder',
scrollSensitivity: 40, scrollSensitivity: 40,
start: function(event, ui) { start: function( event, ui ) {
if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' ); if ( ! ui.item.hasClass( 'alternate' ) ) {
ui.item.children('td,th').css('border-bottom-width','0'); ui.item.css( 'background-color', '#ffffff' );
}
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
ui.item.css( 'outline', '1px solid #aaa' ); ui.item.css( 'outline', '1px solid #aaa' );
}, },
stop: function(event, ui) { stop: function( event, ui ) {
ui.item.removeAttr('style'); ui.item.removeAttr( 'style' );
ui.item.children('td,th').css('border-bottom-width','1px'); ui.item.children( 'td, th' ).css( 'border-bottom-width', '1px' );
}, },
update: function(event, ui) { update: function( event, ui ) {
var termid = ui.item.find('.check-column input').val(); // this post id var termid = ui.item.find( '.check-column input' ).val(); // this post id
var termparent = ui.item.find('.parent').html(); // post parent var termparent = ui.item.find( '.parent' ).html(); // post parent
var prevtermid = ui.item.prev().find('.check-column input').val(); var prevtermid = ui.item.prev().find( '.check-column input' ).val();
var nexttermid = ui.item.next().find('.check-column input').val(); var nexttermid = ui.item.next().find( '.check-column input' ).val();
// can only sort in same tree // Can only sort in same tree
var prevtermparent = undefined; var prevtermparent, nexttermparent;
if ( prevtermid != undefined ) { if ( prevtermid !== undefined ) {
var prevtermparent = ui.item.prev().find('.parent').html(); prevtermparent = ui.item.prev().find( '.parent' ).html();
if ( prevtermparent != termparent) prevtermid = undefined; if ( prevtermparent !== termparent) {
prevtermid = undefined;
}
} }
var nexttermparent = undefined; if ( nexttermid !== undefined ) {
if ( nexttermid != undefined ) { nexttermparent = ui.item.next().find( '.parent' ).html();
nexttermparent = ui.item.next().find('.parent').html(); if ( nexttermparent !== termparent) {
if ( nexttermparent != termparent) nexttermid = undefined; nexttermid = undefined;
}
} }
// if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children // If previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
if ( ( prevtermid == undefined && nexttermid == undefined ) || ( nexttermid == undefined && nexttermparent == prevtermid ) || ( nexttermid != undefined && prevtermparent == termid ) ) { if ( ( prevtermid === undefined && nexttermid === undefined ) || ( nexttermid === undefined && nexttermparent === prevtermid ) || ( nexttermid !== undefined && prevtermparent === termid ) ) {
$("table.widefat.wp-list-table").sortable('cancel'); $( 'table.widefat.wp-list-table' ).sortable( 'cancel' );
return; return;
} }
// show spinner // Show Spinner
ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'); ui.item.find( '.check-column input' ).hide().after( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
// go do the sorting stuff via ajax // Go do the sorting stuff via ajax
$.post( ajaxurl, { action: 'woocommerce_term_ordering', id: termid, nextid: nexttermid, thetaxonomy: woocommerce_term_ordering_params.taxonomy }, function(response){ $.post( ajaxurl, { action: 'woocommerce_term_ordering', id: termid, nextid: nexttermid, thetaxonomy: woocommerce_term_ordering_params.taxonomy }, function(response){
if ( response == 'children' ) window.location.reload(); if ( response === 'children' ) {
else { window.location.reload();
ui.item.find('.check-column input').show().siblings('img').remove(); } else {
ui.item.find( '.check-column input' ).show().siblings( 'img' ).remove();
} }
}); });
// fix cell colors // Fix cell colors
$( 'table.widefat tbody tr' ).each(function(){ $( 'table.widefat tbody tr' ).each( function() {
var i = jQuery('table.widefat tbody tr').index(this); var i = jQuery( 'table.widefat tbody tr' ).index( this );
if ( i%2 == 0 ) jQuery(this).addClass('alternate'); if ( i%2 === 0 ) {
else jQuery(this).removeClass('alternate'); jQuery( this ).addClass( 'alternate' );
} else {
jQuery( this ).removeClass( 'alternate' );
}
}); });
} }
}); });