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
settings.js
266 lines
| 1 | /* global woocommerce_settings_params, wp */ |
| 2 | ( function ( $, params, wp ) { |
| 3 | $( function () { |
| 4 | // Sell Countries |
| 5 | $( 'select#woocommerce_allowed_countries' ) |
| 6 | .on( 'change', function () { |
| 7 | if ( 'specific' === $( this ).val() ) { |
| 8 | $( this ).closest( 'tr' ).next( 'tr' ).hide(); |
| 9 | $( this ).closest( 'tr' ).next().next( 'tr' ).show(); |
| 10 | } else if ( 'all_except' === $( this ).val() ) { |
| 11 | $( this ).closest( 'tr' ).next( 'tr' ).show(); |
| 12 | $( this ).closest( 'tr' ).next().next( 'tr' ).hide(); |
| 13 | } else { |
| 14 | $( this ).closest( 'tr' ).next( 'tr' ).hide(); |
| 15 | $( this ).closest( 'tr' ).next().next( 'tr' ).hide(); |
| 16 | } |
| 17 | } ) |
| 18 | .trigger( 'change' ); |
| 19 | |
| 20 | // Ship Countries |
| 21 | $( 'select#woocommerce_ship_to_countries' ) |
| 22 | .on( 'change', function () { |
| 23 | if ( 'specific' === $( this ).val() ) { |
| 24 | $( this ).closest( 'tr' ).next( 'tr' ).show(); |
| 25 | } else { |
| 26 | $( this ).closest( 'tr' ).next( 'tr' ).hide(); |
| 27 | } |
| 28 | } ) |
| 29 | .trigger( 'change' ); |
| 30 | |
| 31 | // Stock management |
| 32 | $( 'input#woocommerce_manage_stock' ) |
| 33 | .on( 'change', function () { |
| 34 | if ( $( this ).is( ':checked' ) ) { |
| 35 | $( this ) |
| 36 | .closest( 'tbody' ) |
| 37 | .find( '.manage_stock_field' ) |
| 38 | .closest( 'tr' ) |
| 39 | .show(); |
| 40 | } else { |
| 41 | $( this ) |
| 42 | .closest( 'tbody' ) |
| 43 | .find( '.manage_stock_field' ) |
| 44 | .closest( 'tr' ) |
| 45 | .hide(); |
| 46 | } |
| 47 | } ) |
| 48 | .trigger( 'change' ); |
| 49 | |
| 50 | // Color picker |
| 51 | $( '.colorpick' ) |
| 52 | .iris( { |
| 53 | change: function ( event, ui ) { |
| 54 | $( this ) |
| 55 | .parent() |
| 56 | .find( '.colorpickpreview' ) |
| 57 | .css( { backgroundColor: ui.color.toString() } ); |
| 58 | }, |
| 59 | hide: true, |
| 60 | border: true, |
| 61 | } ) |
| 62 | |
| 63 | .on( 'click focus', function ( event ) { |
| 64 | event.stopPropagation(); |
| 65 | $( '.iris-picker' ).hide(); |
| 66 | $( this ).closest( 'td' ).find( '.iris-picker' ).show(); |
| 67 | $( this ).data( 'originalValue', $( this ).val() ); |
| 68 | } ) |
| 69 | |
| 70 | .on( 'change', function () { |
| 71 | if ( $( this ).is( '.iris-error' ) ) { |
| 72 | var original_value = $( this ).data( 'originalValue' ); |
| 73 | |
| 74 | if ( |
| 75 | original_value.match( |
| 76 | /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ |
| 77 | ) |
| 78 | ) { |
| 79 | $( this ) |
| 80 | .val( $( this ).data( 'originalValue' ) ) |
| 81 | .trigger( 'change' ); |
| 82 | } else { |
| 83 | $( this ).val( '' ).trigger( 'change' ); |
| 84 | } |
| 85 | } |
| 86 | } ); |
| 87 | |
| 88 | $( 'body' ).on( 'click', function () { |
| 89 | $( '.iris-picker' ).hide(); |
| 90 | } ); |
| 91 | |
| 92 | // Edit prompt |
| 93 | $( function () { |
| 94 | var changed = false; |
| 95 | let $check_column = $( '.wp-list-table .check-column' ); |
| 96 | |
| 97 | $( 'input, textarea, select, checkbox' ).on( 'change', function ( |
| 98 | event |
| 99 | ) { |
| 100 | // Toggling WP List Table checkboxes should not trigger navigation warnings. |
| 101 | if ( |
| 102 | $check_column.length && |
| 103 | $check_column.has( event.target ) |
| 104 | ) { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if ( ! changed ) { |
| 109 | window.onbeforeunload = function () { |
| 110 | return params.i18n_nav_warning; |
| 111 | }; |
| 112 | changed = true; |
| 113 | } |
| 114 | } ); |
| 115 | |
| 116 | $( '.submit :input, input#search-submit' ).on( |
| 117 | 'click', |
| 118 | function () { |
| 119 | window.onbeforeunload = ''; |
| 120 | } |
| 121 | ); |
| 122 | } ); |
| 123 | |
| 124 | // Sorting |
| 125 | $( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable( { |
| 126 | items: 'tr', |
| 127 | cursor: 'move', |
| 128 | axis: 'y', |
| 129 | handle: 'td.sort', |
| 130 | scrollSensitivity: 40, |
| 131 | helper: function ( event, ui ) { |
| 132 | ui.children().each( function () { |
| 133 | $( this ).width( $( this ).width() ); |
| 134 | } ); |
| 135 | ui.css( 'left', '0' ); |
| 136 | return ui; |
| 137 | }, |
| 138 | start: function ( event, ui ) { |
| 139 | ui.item.css( 'background-color', '#f6f6f6' ); |
| 140 | }, |
| 141 | stop: function ( event, ui ) { |
| 142 | ui.item.removeAttr( 'style' ); |
| 143 | ui.item.trigger( 'updateMoveButtons' ); |
| 144 | }, |
| 145 | } ); |
| 146 | |
| 147 | // Select all/none |
| 148 | $( '.woocommerce' ).on( 'click', '.select_all', function () { |
| 149 | $( this ) |
| 150 | .closest( 'td' ) |
| 151 | .find( 'select option' ) |
| 152 | .prop( 'selected', true ); |
| 153 | $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); |
| 154 | return false; |
| 155 | } ); |
| 156 | |
| 157 | $( '.woocommerce' ).on( 'click', '.select_none', function () { |
| 158 | $( this ) |
| 159 | .closest( 'td' ) |
| 160 | .find( 'select option' ) |
| 161 | .prop( 'selected', false ); |
| 162 | $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); |
| 163 | return false; |
| 164 | } ); |
| 165 | |
| 166 | // Re-order buttons. |
| 167 | $( '.wc-item-reorder-nav' ) |
| 168 | .find( '.wc-move-up, .wc-move-down' ) |
| 169 | .on( 'click', function () { |
| 170 | var moveBtn = $( this ), |
| 171 | $row = moveBtn.closest( 'tr' ); |
| 172 | |
| 173 | moveBtn.trigger( 'focus' ); |
| 174 | |
| 175 | var isMoveUp = moveBtn.is( '.wc-move-up' ), |
| 176 | isMoveDown = moveBtn.is( '.wc-move-down' ); |
| 177 | |
| 178 | if ( isMoveUp ) { |
| 179 | var $previewRow = $row.prev( 'tr' ); |
| 180 | |
| 181 | if ( $previewRow && $previewRow.length ) { |
| 182 | $previewRow.before( $row ); |
| 183 | wp.a11y.speak( params.i18n_moved_up ); |
| 184 | } |
| 185 | } else if ( isMoveDown ) { |
| 186 | var $nextRow = $row.next( 'tr' ); |
| 187 | |
| 188 | if ( $nextRow && $nextRow.length ) { |
| 189 | $nextRow.after( $row ); |
| 190 | wp.a11y.speak( params.i18n_moved_down ); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | moveBtn.trigger( 'focus' ); // Re-focus after the container was moved. |
| 195 | moveBtn.closest( 'table' ).trigger( 'updateMoveButtons' ); |
| 196 | } ); |
| 197 | |
| 198 | $( '.wc-item-reorder-nav' ) |
| 199 | .closest( 'table' ) |
| 200 | .on( 'updateMoveButtons', function () { |
| 201 | var table = $( this ), |
| 202 | lastRow = $( this ).find( 'tbody tr:last' ), |
| 203 | firstRow = $( this ).find( 'tbody tr:first' ); |
| 204 | |
| 205 | table |
| 206 | .find( '.wc-item-reorder-nav .wc-move-disabled' ) |
| 207 | .removeClass( 'wc-move-disabled' ) |
| 208 | .attr( { tabindex: '0', 'aria-hidden': 'false' } ); |
| 209 | firstRow |
| 210 | .find( '.wc-item-reorder-nav .wc-move-up' ) |
| 211 | .addClass( 'wc-move-disabled' ) |
| 212 | .attr( { tabindex: '-1', 'aria-hidden': 'true' } ); |
| 213 | lastRow |
| 214 | .find( '.wc-item-reorder-nav .wc-move-down' ) |
| 215 | .addClass( 'wc-move-disabled' ) |
| 216 | .attr( { tabindex: '-1', 'aria-hidden': 'true' } ); |
| 217 | } ); |
| 218 | |
| 219 | $( '.wc-item-reorder-nav' ) |
| 220 | .closest( 'table' ) |
| 221 | .trigger( 'updateMoveButtons' ); |
| 222 | |
| 223 | $( '.submit button' ).on( 'click', function () { |
| 224 | if ( |
| 225 | $( 'select#woocommerce_allowed_countries' ).val() === |
| 226 | 'specific' && |
| 227 | ! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val() |
| 228 | ) { |
| 229 | if ( |
| 230 | window.confirm( |
| 231 | woocommerce_settings_params.i18n_no_specific_countries_selected |
| 232 | ) |
| 233 | ) { |
| 234 | return true; |
| 235 | } |
| 236 | return false; |
| 237 | } |
| 238 | } ); |
| 239 | |
| 240 | $( '#settings-other-payment-methods' ).on( 'click', function ( e ) { |
| 241 | if ( |
| 242 | typeof window.wcTracks.recordEvent === 'undefined' && |
| 243 | typeof window.wc.tracks.recordEvent === 'undefined' |
| 244 | ) { |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | var recordEvent = |
| 249 | window.wc.tracks.recordEvent || window.wcTracks.recordEvent; |
| 250 | |
| 251 | var payment_methods = $.map( |
| 252 | $( |
| 253 | 'td.wc_payment_gateways_wrapper tbody tr[data-gateway_id] ' |
| 254 | ), |
| 255 | function ( tr ) { |
| 256 | return $( tr ).attr( 'data-gateway_id' ); |
| 257 | } |
| 258 | ); |
| 259 | |
| 260 | recordEvent( 'settings_payments_recommendations_other_options', { |
| 261 | available_payment_methods: payment_methods, |
| 262 | } ); |
| 263 | } ); |
| 264 | } ); |
| 265 | } )( jQuery, woocommerce_settings_params, wp ); |
| 266 |