From 55d7dab62d001516eb6887d7c618e7ef23154694 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 4 Jun 2015 17:51:01 +0545 Subject: [PATCH 1/5] Tweak - JSHint fix and coding standard for product ordering --- assets/js/admin/product-ordering.js | 76 +++++++++++++++-------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/assets/js/admin/product-ordering.js b/assets/js/admin/product-ordering.js index 91d6a9373e3..ccb172fde12 100644 --- a/assets/js/admin/product-ordering.js +++ b/assets/js/admin/product-ordering.js @@ -3,67 +3,71 @@ * * Modified - products have no children (non hierarchical) */ -( function( $ ){ -$( document ).ready(function(){ - $('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' ); - $("table.widefat tbody").sortable({ + $( '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()); }); + 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) ), + start: function( event, ui ) { + ui.placeholder.children().each( function() { + var $original = ui.item.children().eq( ui.placeholder.children().index( this ) ), $this = $( this ); - $.each( $original[0].attributes, function( k, attr ){ + $.each( $original[0].attributes, function( k, attr ) { $this.attr( attr.name, attr.value ); - } ); + }); }); - if ( ! ui.item.hasClass('alternate') ) { + if ( ! ui.item.hasClass( 'alternate' ) ) { 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' ); }, - stop: function(event, ui) { - ui.item.removeAttr('style'); - ui.item.children('td,th').css('border-bottom-width','1px'); + 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'); + update: function( event, ui ) { + $( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' ); + $( 'table.widefat tbody' ).sortable( 'disable' ); - var postid = ui.item.find('.check-column input').val(); // this post id - var postparent = ui.item.find('.post_parent').html(); // post parent + var postid = ui.item.find( '.check-column input' ).val(); // this post id + 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(); + var nextpostid = ui.item.next().find( '.check-column input' ).val(); - // show spinner - ui.item.find('.check-column input').hide().after('processing'); + // Show Spinner + ui.item.find( '.check-column input' ).hide().after( 'processing' ); - // 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'); + // 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'); + $( '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'); + $( this ).removeClass( 'alternate' ); } }); } From 318f6672d90f6a17097eda1c7d6aac127e01a216 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 4 Jun 2015 17:51:58 +0545 Subject: [PATCH 2/5] Remove unused var postparent --- assets/js/admin/product-ordering.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/assets/js/admin/product-ordering.js b/assets/js/admin/product-ordering.js index ccb172fde12..d2eaf269e1b 100644 --- a/assets/js/admin/product-ordering.js +++ b/assets/js/admin/product-ordering.js @@ -42,9 +42,7 @@ $( document ).ready( function() { $( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' ); $( 'table.widefat tbody' ).sortable( 'disable' ); - var postid = ui.item.find( '.check-column input' ).val(); // this post id - var postparent = ui.item.find( '.post_parent' ).html(); // post parent - + var postid = ui.item.find( '.check-column input' ).val(); var prevpostid = ui.item.prev().find( '.check-column input' ).val(); var nextpostid = ui.item.next().find( '.check-column input' ).val(); From f9b822ae21c09832ccbc576cdafa6ea009e6ff14 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 4 Jun 2015 18:06:39 +0545 Subject: [PATCH 3/5] Tweak - JSHint fix and coding standard for term ordering --- assets/js/admin/term-ordering.js | 78 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/assets/js/admin/term-ordering.js b/assets/js/admin/term-ordering.js index 3bed28791ce..47878cac30a 100644 --- a/assets/js/admin/term-ordering.js +++ b/assets/js/admin/term-ordering.js @@ -1,9 +1,9 @@ /* 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)', cursor: 'move', axis: 'y', @@ -12,57 +12,67 @@ jQuery(function($) { opacity: 0.65, placeholder: 'product-cat-placeholder', scrollSensitivity: 40, - 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'); + 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 #aaa' ); }, - stop: function(event, ui) { - ui.item.removeAttr('style'); - ui.item.children('td,th').css('border-bottom-width','1px'); + stop: function( event, ui ) { + ui.item.removeAttr( 'style' ); + ui.item.children( 'td, th' ).css( 'border-bottom-width', '1px' ); }, - update: function(event, ui) { - var termid = ui.item.find('.check-column input').val(); // this post id - var termparent = ui.item.find('.parent').html(); // post parent + update: function( event, ui ) { + var termid = ui.item.find( '.check-column input' ).val(); // this post id + var termparent = ui.item.find( '.parent' ).html(); // post parent - var prevtermid = ui.item.prev().find('.check-column input').val(); - var nexttermid = ui.item.next().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(); - // can only sort in same tree + // Can only sort in same tree var prevtermparent = undefined; - if ( prevtermid != undefined ) { - var prevtermparent = ui.item.prev().find('.parent').html(); - if ( prevtermparent != termparent) prevtermid = undefined; + if ( prevtermid !== undefined ) { + prevtermparent = ui.item.prev().find('.parent').html(); + if ( prevtermparent !== termparent) { + prevtermid = undefined; + } } var nexttermparent = undefined; - if ( nexttermid != undefined ) { - nexttermparent = ui.item.next().find('.parent').html(); - if ( nexttermparent != termparent) nexttermid = undefined; + if ( nexttermid !== undefined ) { + nexttermparent = ui.item.next().find( '.parent' ).html(); + if ( nexttermparent !== termparent) { + 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 ( ( prevtermid == undefined && nexttermid == undefined ) || ( nexttermid == undefined && nexttermparent == prevtermid ) || ( nexttermid != undefined && prevtermparent == termid ) ) { - $("table.widefat.wp-list-table").sortable('cancel'); + // 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 ) ) { + $( 'table.widefat.wp-list-table' ).sortable( 'cancel' ); return; } - // show spinner - ui.item.find('.check-column input').hide().after('processing'); + // Show Spinner + ui.item.find( '.check-column input' ).hide().after( 'processing' ); - // 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){ - if ( response == 'children' ) window.location.reload(); - else { - ui.item.find('.check-column input').show().siblings('img').remove(); + if ( response === 'children' ) { + window.location.reload(); + } else { + ui.item.find( '.check-column input' ).show().siblings( 'img' ).remove(); } }); // fix cell colors - $( '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'); + $( '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' ); + } }); } }); From 2bb8ce3097769c8809ba98b6748f16851c0ac628 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 4 Jun 2015 18:08:07 +0545 Subject: [PATCH 4/5] Fix - undefined is not necessary to initialize --- assets/js/admin/term-ordering.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/admin/term-ordering.js b/assets/js/admin/term-ordering.js index 47878cac30a..0b97c8115d7 100644 --- a/assets/js/admin/term-ordering.js +++ b/assets/js/admin/term-ordering.js @@ -31,7 +31,8 @@ jQuery( function( $ ) { var nexttermid = ui.item.next().find( '.check-column input' ).val(); // Can only sort in same tree - var prevtermparent = undefined; + var prevtermparent, nexttermparent; + if ( prevtermid !== undefined ) { prevtermparent = ui.item.prev().find('.parent').html(); if ( prevtermparent !== termparent) { @@ -39,7 +40,6 @@ jQuery( function( $ ) { } } - var nexttermparent = undefined; if ( nexttermid !== undefined ) { nexttermparent = ui.item.next().find( '.parent' ).html(); if ( nexttermparent !== termparent) { From ce2896ffcb9a3d6491a51aa8c6c9762e374904ab Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 4 Jun 2015 18:18:49 +0545 Subject: [PATCH 5/5] Little tweak ... --- assets/js/admin/term-ordering.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assets/js/admin/term-ordering.js b/assets/js/admin/term-ordering.js index 0b97c8115d7..e952d62a99b 100644 --- a/assets/js/admin/term-ordering.js +++ b/assets/js/admin/term-ordering.js @@ -32,9 +32,8 @@ jQuery( function( $ ) { // Can only sort in same tree var prevtermparent, nexttermparent; - if ( prevtermid !== undefined ) { - prevtermparent = ui.item.prev().find('.parent').html(); + prevtermparent = ui.item.prev().find( '.parent' ).html(); if ( prevtermparent !== termparent) { prevtermid = undefined; } @@ -65,7 +64,7 @@ jQuery( function( $ ) { } }); - // fix cell colors + // Fix cell colors $( 'table.widefat tbody tr' ).each( function() { var i = jQuery( 'table.widefat tbody tr' ).index( this ); if ( i%2 === 0 ) {