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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / assets / js / admin / settings.js
woocommerce / assets / js / admin Last commit date
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 10 months ago marketplace-suggestions.min.js 10 months ago meta-boxes-coupon.js 1 year ago meta-boxes-coupon.min.js 1 year ago meta-boxes-order.js 4 weeks ago meta-boxes-order.min.js 4 weeks ago meta-boxes-product-variation.js 1 year ago meta-boxes-product-variation.min.js 1 year ago meta-boxes-product.js 4 weeks ago meta-boxes-product.min.js 4 weeks ago meta-boxes.js 4 months ago meta-boxes.min.js 4 months 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 11 months ago product-editor.min.js 11 months ago product-ordering.js 3 months ago product-ordering.min.js 3 months ago quick-edit.js 1 year ago quick-edit.min.js 1 year ago reports.js 1 year ago reports.min.js 1 year ago settings-views-html-settings-tax.js 1 year ago settings-views-html-settings-tax.min.js 1 year ago settings.js 1 year ago settings.min.js 1 year ago system-status.js 3 months ago system-status.min.js 3 months ago term-ordering.js 3 months ago term-ordering.min.js 3 months ago users.js 5 years ago users.min.js 2 years ago variation-gallery.js 4 weeks ago variation-gallery.min.js 4 weeks ago wc-brands-enhanced-select.js 1 year ago wc-brands-enhanced-select.min.js 1 year ago wc-clipboard.js 5 years ago wc-clipboard.min.js 5 years ago wc-customer-stock-notifications.js 10 months ago wc-customer-stock-notifications.min.js 10 months 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 1 year ago wc-product-export.min.js 1 year ago wc-product-import.js 3 years ago wc-product-import.min.js 2 years ago wc-recent-reviews-widget-async.js 4 months ago wc-recent-reviews-widget-async.min.js 4 months ago wc-setup.js 5 years ago wc-setup.min.js 2 years ago wc-shipping-classes.js 1 year ago wc-shipping-classes.min.js 1 year ago wc-shipping-providers.js 3 months ago wc-shipping-providers.min.js 3 months ago wc-shipping-zone-methods.js 5 months ago wc-shipping-zone-methods.min.js 5 months ago wc-shipping-zones.js 1 year ago wc-shipping-zones.min.js 1 year ago wc-status-widget-async.js 4 months ago wc-status-widget-async.min.js 4 months ago wc-status-widget.js 1 year ago wc-status-widget.min.js 1 year ago woocommerce_admin.js 4 weeks ago woocommerce_admin.min.js 4 weeks ago
settings.js
423 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 const $this = $( this );
55 $this
56 .parent()
57 .find( '.colorpickpreview' )
58 .css( { backgroundColor: ui.color.toString() } );
59 setTimeout( function () {
60 $this.trigger( 'change' );
61 } );
62 },
63 hide: true,
64 border: true,
65 } )
66
67 .on( 'click focus', function ( event ) {
68 event.stopPropagation();
69 $( '.iris-picker' ).hide();
70 $( this ).closest( 'td' ).find( '.iris-picker' ).show();
71 $( this ).data( 'originalValue', $( this ).val() );
72 } )
73
74 .on( 'change', function () {
75 if ( $( this ).is( '.iris-error' ) ) {
76 var original_value = $( this ).data( 'originalValue' );
77
78 if (
79 original_value.match(
80 /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
81 )
82 ) {
83 $( this )
84 .val( $( this ).data( 'originalValue' ) )
85 .trigger( 'change' );
86 } else {
87 $( this ).val( '' ).trigger( 'change' );
88 }
89 }
90 } );
91
92 $( '.iris-square-value' ).on( 'click', function ( event ) {
93 event.preventDefault();
94 } );
95
96 $( '.colorpickpreview' ).on( 'click', function ( event ) {
97 event.stopPropagation();
98 $( this ).next( '.colorpick' ).click();
99 } );
100
101 $( 'body' ).on( 'click', function () {
102 $( '.iris-picker' ).hide();
103 } );
104
105 // Edit prompt
106 function editPrompt () {
107 var changed = false;
108 let $prevent_change_elements = $( '.wp-list-table .check-column, .wc-settings-prevent-change-event' );
109
110 $( 'input, textarea, select, checkbox' ).on( 'change input', function (
111 event
112 ) {
113 // Prevent change event on specific elements, that don't change the form. E.g.:
114 // - WP List Table checkboxes that only (un)select rows
115 // - Changing email type in email preview
116 if (
117 $prevent_change_elements.length &&
118 $prevent_change_elements.has( event.target ).length
119 ) {
120 return;
121 }
122
123 if ( ! changed ) {
124 window.onbeforeunload = function () {
125 return params.i18n_nav_warning;
126 };
127 changed = true;
128 $( '.woocommerce-save-button' ).removeAttr( 'disabled' );
129 }
130 } );
131
132 $( '.iris-picker' ).on( 'click', function () {
133 if ( ! changed ) {
134 changed = true;
135 $( '.woocommerce-save-button' ).removeAttr( 'disabled' );
136 }
137 } );
138
139 $( '.submit :input, input#search-submit' ).on(
140 'click',
141 function () {
142 window.onbeforeunload = '';
143 }
144 );
145 }
146
147 $( editPrompt );
148
149 const nodeListContainsFormElements = ( nodes ) => {
150 if ( ! nodes.length ) {
151 return false;
152 }
153 return Array.from( nodes ).some( ( element ) => {
154 return $( element ).find( 'input, textarea, select, checkbox' ).length;
155 } );
156 }
157
158 const form = document.querySelector( '#mainform' );
159 const observer = new MutationObserver( ( mutationsList ) => {
160 for ( const mutation of mutationsList ) {
161 if ( mutation.type === 'childList' ) {
162 if ( nodeListContainsFormElements( mutation.addedNodes ) ) {
163 editPrompt();
164 $( '.woocommerce-save-button' ).removeAttr( 'disabled' );
165 } else if ( nodeListContainsFormElements( mutation.removedNodes ) ) {
166 $( '.woocommerce-save-button' ).removeAttr( 'disabled' );
167 }
168 }
169 }
170 } );
171
172 observer.observe( form, { childList: true, subtree: true } );
173
174 // Sorting
175 $( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable( {
176 items: 'tr',
177 cursor: 'move',
178 axis: 'y',
179 handle: 'td.sort',
180 scrollSensitivity: 40,
181 helper: function ( event, ui ) {
182 ui.children().each( function () {
183 $( this ).width( $( this ).width() );
184 } );
185 ui.css( 'left', '0' );
186 return ui;
187 },
188 start: function ( event, ui ) {
189 ui.item.css( 'background-color', '#f6f6f6' );
190 },
191 stop: function ( event, ui ) {
192 ui.item.removeAttr( 'style' );
193 ui.item.trigger( 'updateMoveButtons', { isInitialLoad: false } );
194 },
195 } );
196
197 // Select all/none
198 $( '.woocommerce' ).on( 'click', '.select_all', function () {
199 $( this )
200 .closest( 'td' )
201 .find( 'select option' )
202 .prop( 'selected', true );
203 $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
204 return false;
205 } );
206
207 $( '.woocommerce' ).on( 'click', '.select_none', function () {
208 $( this )
209 .closest( 'td' )
210 .find( 'select option' )
211 .prop( 'selected', false );
212 $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
213 return false;
214 } );
215
216 // Re-order buttons.
217 $( '.wc-item-reorder-nav' )
218 .find( '.wc-move-up, .wc-move-down' )
219 .on( 'click', function () {
220 var moveBtn = $( this ),
221 $row = moveBtn.closest( 'tr' );
222
223 moveBtn.trigger( 'focus' );
224
225 var isMoveUp = moveBtn.is( '.wc-move-up' ),
226 isMoveDown = moveBtn.is( '.wc-move-down' );
227
228 if ( isMoveUp ) {
229 var $previewRow = $row.prev( 'tr' );
230
231 if ( $previewRow && $previewRow.length ) {
232 $previewRow.before( $row );
233 wp.a11y.speak( params.i18n_moved_up );
234 }
235 } else if ( isMoveDown ) {
236 var $nextRow = $row.next( 'tr' );
237
238 if ( $nextRow && $nextRow.length ) {
239 $nextRow.after( $row );
240 wp.a11y.speak( params.i18n_moved_down );
241 }
242 }
243
244 moveBtn.trigger( 'focus' ); // Re-focus after the container was moved.
245 moveBtn.closest( 'table' ).trigger( 'updateMoveButtons', { isInitialLoad: false } );
246 } );
247
248 $( '.wc-item-reorder-nav' )
249 .closest( 'table' )
250 .on( 'updateMoveButtons', function ( event, data ) {
251 var table = $( this ),
252 lastRow = $( this ).find( 'tbody tr:last' ),
253 firstRow = $( this ).find( 'tbody tr:first' );
254
255 table
256 .find( '.wc-item-reorder-nav .wc-move-disabled' )
257 .removeClass( 'wc-move-disabled' )
258 .attr( { tabindex: '0', 'aria-hidden': 'false' } );
259 firstRow
260 .find( '.wc-item-reorder-nav .wc-move-up' )
261 .addClass( 'wc-move-disabled' )
262 .attr( { tabindex: '-1', 'aria-hidden': 'true' } );
263 lastRow
264 .find( '.wc-item-reorder-nav .wc-move-down' )
265 .addClass( 'wc-move-disabled' )
266 .attr( { tabindex: '-1', 'aria-hidden': 'true' } );
267 if ( ! data.isInitialLoad ) {
268 $( '.woocommerce-save-button' ).removeAttr( 'disabled' );
269 }
270 } );
271
272 $( '.wc-item-reorder-nav' )
273 .closest( 'table' )
274 .trigger( 'updateMoveButtons', { isInitialLoad: true } );
275
276 $( '.submit button' ).on( 'click', function () {
277 if (
278 $( 'select#woocommerce_allowed_countries' ).val() ===
279 'specific' &&
280 ! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val()
281 ) {
282 if (
283 window.confirm(
284 woocommerce_settings_params.i18n_no_specific_countries_selected
285 )
286 ) {
287 return true;
288 }
289 return false;
290 }
291 } );
292
293 $( '#settings-other-payment-methods' ).on( 'click', function ( e ) {
294 if (
295 typeof window.wcTracks.recordEvent === 'undefined' &&
296 typeof window.wc.tracks.recordEvent === 'undefined'
297 ) {
298 return;
299 }
300
301 var recordEvent =
302 window.wc.tracks.recordEvent || window.wcTracks.recordEvent;
303
304 var payment_methods = $.map(
305 $(
306 'td.wc_payment_gateways_wrapper tbody tr[data-gateway_id] '
307 ),
308 function ( tr ) {
309 return $( tr ).attr( 'data-gateway_id' );
310 }
311 );
312
313 recordEvent( 'settings_payments_recommendations_other_options', {
314 available_payment_methods: payment_methods,
315 } );
316 } );
317
318 $( '.woocommerce-save-button.components-button' ).on( 'click', function ( e ) {
319 if ( ! $( this ).attr( 'disabled' ) ) {
320 $( this ).addClass( 'is-busy' );
321 }
322 } );
323
324 /**
325 * Support conditionally displaying a settings field description when another element
326 * is set to a specific value.
327 *
328 * This logic is subject to change, and is not intended for use by other plugins.
329 * Note that we can't avoid jQuery here, because of our current dependence on Select2
330 * for various controls.
331 */
332 document.querySelectorAll( 'body.woocommerce_page_wc-settings #mainform .conditional.description' ).forEach( description => {
333 const $underObservation = $( description.dataset.dependsOn );
334 const showIfEquals = description.dataset.showIfEquals;
335
336 if ( undefined === showIfEquals || $underObservation.length === 0 ) {
337 return;
338 }
339
340 /**
341 * Set visibility of the description element according to whether its value
342 * matches that of showIfEquals.
343 */
344 const changeAgent = () => {
345 description.style.visibility = $underObservation.val() === showIfEquals ? 'visible' : 'hidden';
346 };
347
348 // Monitor future changes, and take action based on the current state.
349 $underObservation.on( 'change', changeAgent );
350 changeAgent();
351 } );
352
353 // Ensures the active tab is visible and centered on small screens if it's out of view in a scrollable tab list.
354 function settings_scroll_to_active_tab() {
355 const body = document.body;
356 if (
357 ! body.classList.contains('mobile') ||
358 ! body.classList.contains('woocommerce_page_wc-settings')
359 ) {
360 return;
361 }
362 // Select the currently active tab
363 const activeTab = document.querySelector( '.nav-tab-active' );
364
365 // Exit if there's no active tab or screen is wider than 500px (desktop)
366 if ( ! activeTab || window.innerWidth >= 500 ) {
367 return;
368 }
369
370 // Get the parent element, assumed to be the scrollable container
371 const parent = activeTab.parentElement;
372
373 // Exit if no parent or if scrolling isn't needed (content fits)
374 if ( ! parent || parent.scrollWidth <= parent.clientWidth ) {
375 return;
376 }
377
378 // Get the position of the active tab relative to its parent
379 const tabLeft = activeTab.offsetLeft;
380 const tabRight = tabLeft + activeTab.offsetWidth;
381 const scrollLeft = parent.scrollLeft;
382 const visibleLeft = scrollLeft;
383 const visibleRight = scrollLeft + parent.clientWidth;
384 const isOutOfView = tabLeft < visibleLeft || tabRight > visibleRight;
385
386 // If it’s out of view, scroll the parent so the tab is centered
387 if ( isOutOfView ) {
388 const offset = tabLeft - parent.clientWidth / 2 + activeTab.offsetWidth / 2;
389 parent.scrollTo( {
390 left: offset,
391 behavior: 'auto' // Instant scroll (no animation)
392 } );
393 }
394 }
395
396 // Some legacy setting pages have tables that span beyond the set width of its parents
397 // causing layout issues.
398 // Fixe the width of the nav tab wrapper to match the window width on mobile.
399 function settings_fix_nav_width() {
400 const body = document.body;
401 if (
402 ! body.classList.contains('mobile') ||
403 ! body.classList.contains('woocommerce_page_wc-settings')
404 ) {
405 return;
406 }
407 const navWrapper = document.getElementsByClassName('nav-tab-wrapper');
408 if ( ! navWrapper.length ) {
409 return;
410 }
411
412 const navWrapperWidth = navWrapper[0].offsetWidth;
413 if ( navWrapperWidth !== window.innerWidth) {
414 navWrapper[0].style.width = window.innerWidth + 'px';
415 }
416 }
417
418 settings_scroll_to_active_tab();
419 settings_fix_nav_width();
420
421 } );
422 } )( jQuery, woocommerce_settings_params, wp );
423