api-keys.js
5 years ago
api-keys.min.js
2 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
4 years ago
marketplace-suggestions.min.js
2 years ago
meta-boxes-coupon.js
5 years ago
meta-boxes-coupon.min.js
2 years ago
meta-boxes-order.js
2 years ago
meta-boxes-order.min.js
2 years ago
meta-boxes-product-variation.js
2 years ago
meta-boxes-product-variation.min.js
2 years ago
meta-boxes-product.js
2 years ago
meta-boxes-product.min.js
2 years ago
meta-boxes.js
2 years ago
meta-boxes.min.js
2 years ago
network-orders.js
8 years ago
network-orders.min.js
2 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
3 years ago
product-editor.min.js
2 years ago
product-ordering.js
3 years ago
product-ordering.min.js
2 years ago
quick-edit.js
4 years ago
quick-edit.min.js
2 years ago
reports.js
5 years ago
reports.min.js
2 years ago
settings-views-html-settings-tax.js
3 years ago
settings-views-html-settings-tax.min.js
2 years ago
settings.js
4 years ago
settings.min.js
2 years ago
system-status.js
3 years ago
system-status.min.js
2 years ago
term-ordering.js
3 years ago
term-ordering.min.js
2 years ago
users.js
5 years ago
users.min.js
2 years ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-enhanced-select.js
2 years ago
wc-enhanced-select.min.js
2 years ago
wc-orders.js
3 years ago
wc-orders.min.js
2 years ago
wc-product-export.js
5 years ago
wc-product-export.min.js
2 years ago
wc-product-import.js
3 years ago
wc-product-import.min.js
2 years ago
wc-setup.js
5 years ago
wc-setup.min.js
2 years ago
wc-shipping-classes.js
2 years ago
wc-shipping-classes.min.js
2 years ago
wc-shipping-zone-methods.js
2 years ago
wc-shipping-zone-methods.min.js
2 years ago
wc-shipping-zones.js
2 years ago
wc-shipping-zones.min.js
2 years ago
wc-status-widget.js
2 years ago
wc-status-widget.min.js
2 years ago
woocommerce_admin.js
2 years ago
woocommerce_admin.min.js
2 years ago
term-ordering.js
149 lines
| 1 | /*global ajaxurl, woocommerce_term_ordering_params */ |
| 2 | |
| 3 | /* Modifided script from the simple-page-ordering plugin */ |
| 4 | jQuery( function( $ ) { |
| 5 | |
| 6 | var table_selector = 'table.wp-list-table', |
| 7 | item_selector = 'tbody tr:not(.inline-edit-row)', |
| 8 | term_id_selector = '.column-handle input[name="term_id"]', |
| 9 | column_handle = '<td class="column-handle"></td>'; |
| 10 | |
| 11 | if ( 0 === $( table_selector ).find( '.column-handle' ).length ) { |
| 12 | $( table_selector ).find( 'tr:not(.inline-edit-row)' ).append( column_handle ); |
| 13 | |
| 14 | term_id_selector = '.check-column input'; |
| 15 | } |
| 16 | |
| 17 | // Stand-in wcTracks.recordEvent in case tracks is not available (for any reason). |
| 18 | window.wcTracks = window.wcTracks || {}; |
| 19 | window.wcTracks.recordEvent = window.wcTracks.recordEvent || function() { }; |
| 20 | |
| 21 | $( table_selector ).find( '.column-handle' ).show(); |
| 22 | |
| 23 | $.wc_add_missing_sort_handles = function() { |
| 24 | var all_table_rows = $( table_selector ).find('tbody > tr'); |
| 25 | var rows_with_handle = $( table_selector ).find('tbody > tr > td.column-handle').parent(); |
| 26 | if ( all_table_rows.length !== rows_with_handle.length ) { |
| 27 | all_table_rows.each(function(index, elem){ |
| 28 | if ( ! rows_with_handle.is( elem ) ) { |
| 29 | $( elem ).append( column_handle ); |
| 30 | } |
| 31 | }); |
| 32 | } |
| 33 | $( table_selector ).find( '.column-handle' ).show(); |
| 34 | }; |
| 35 | |
| 36 | $( document ).ajaxComplete( function( event, request, options ) { |
| 37 | if ( |
| 38 | request && |
| 39 | 4 === request.readyState && |
| 40 | 200 === request.status && |
| 41 | options.data && |
| 42 | ( 0 <= options.data.indexOf( '_inline_edit' ) || 0 <= options.data.indexOf( 'add-tag' ) ) |
| 43 | ) { |
| 44 | $.wc_add_missing_sort_handles(); |
| 45 | $( document.body ).trigger( 'init_tooltips' ); |
| 46 | } |
| 47 | } ); |
| 48 | |
| 49 | $( table_selector ).sortable({ |
| 50 | items: item_selector, |
| 51 | cursor: 'move', |
| 52 | handle: '.column-handle', |
| 53 | axis: 'y', |
| 54 | forcePlaceholderSize: true, |
| 55 | helper: 'clone', |
| 56 | opacity: 0.65, |
| 57 | placeholder: 'product-cat-placeholder', |
| 58 | scrollSensitivity: 40, |
| 59 | start: function( event, ui ) { |
| 60 | if ( ! ui.item.hasClass( 'alternate' ) ) { |
| 61 | ui.item.css( 'background-color', '#ffffff' ); |
| 62 | } |
| 63 | ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' ); |
| 64 | ui.item.css( 'outline', '1px solid #aaa' ); |
| 65 | }, |
| 66 | stop: function( event, ui ) { |
| 67 | ui.item.removeAttr( 'style' ); |
| 68 | ui.item.children( 'td, th' ).css( 'border-bottom-width', '1px' ); |
| 69 | }, |
| 70 | update: function( event, ui ) { |
| 71 | var termid = ui.item.find( term_id_selector ).val(); // this post id |
| 72 | var termparent = ui.item.find( '.parent' ).html(); // post parent |
| 73 | |
| 74 | var prevtermid = ui.item.prev().find( term_id_selector ).val(); |
| 75 | var nexttermid = ui.item.next().find( term_id_selector ).val(); |
| 76 | |
| 77 | // Can only sort in same tree |
| 78 | var prevtermparent, nexttermparent; |
| 79 | if ( prevtermid !== undefined ) { |
| 80 | prevtermparent = ui.item.prev().find( '.parent' ).html(); |
| 81 | if ( prevtermparent !== termparent) { |
| 82 | prevtermid = undefined; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if ( nexttermid !== undefined ) { |
| 87 | nexttermparent = ui.item.next().find( '.parent' ).html(); |
| 88 | if ( nexttermparent !== termparent) { |
| 89 | nexttermid = undefined; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // If previous and next not at same tree level, or next not at same tree level and |
| 94 | // the previous is the parent of the next, or just moved item beneath its own children. |
| 95 | if ( |
| 96 | ( prevtermid === undefined && nexttermid === undefined ) || |
| 97 | ( nexttermid === undefined && nexttermparent === prevtermid ) || |
| 98 | ( nexttermid !== undefined && prevtermparent === termid ) |
| 99 | ) { |
| 100 | $( table_selector ).sortable( 'cancel' ); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | window.wcTracks.recordEvent( 'product_attributes_ordering_term', { |
| 105 | is_category: |
| 106 | woocommerce_term_ordering_params.taxonomy === 'product_cat' |
| 107 | ? 'yes' |
| 108 | : 'no', |
| 109 | } ); |
| 110 | |
| 111 | // Show Spinner |
| 112 | ui.item.find( '.check-column input' ).hide(); |
| 113 | ui.item |
| 114 | .find( '.check-column' ) |
| 115 | .append( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' ); |
| 116 | |
| 117 | // Go do the sorting stuff via ajax. |
| 118 | $.post( |
| 119 | ajaxurl, |
| 120 | { |
| 121 | action: 'woocommerce_term_ordering', |
| 122 | id: termid, |
| 123 | nextid: nexttermid, |
| 124 | thetaxonomy: woocommerce_term_ordering_params.taxonomy |
| 125 | }, |
| 126 | function(response) { |
| 127 | if ( response === 'children' ) { |
| 128 | window.location.reload(); |
| 129 | } else { |
| 130 | ui.item.find( '.check-column input' ).show(); |
| 131 | ui.item.find( '.check-column' ).find( 'img' ).remove(); |
| 132 | } |
| 133 | } |
| 134 | ); |
| 135 | |
| 136 | // Fix cell colors |
| 137 | $( 'table.widefat tbody tr' ).each( function() { |
| 138 | var i = jQuery( 'table.widefat tbody tr' ).index( this ); |
| 139 | if ( i%2 === 0 ) { |
| 140 | jQuery( this ).addClass( 'alternate' ); |
| 141 | } else { |
| 142 | jQuery( this ).removeClass( 'alternate' ); |
| 143 | } |
| 144 | }); |
| 145 | } |
| 146 | }); |
| 147 | |
| 148 | }); |
| 149 |