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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / assets / js / admin / woocommerce_admin.js
woocommerce / assets / js / admin Last commit date
api-keys.js 5 years ago api-keys.min.js 3 years ago backbone-modal.js 2 years ago backbone-modal.min.js 2 years ago marketplace-suggestions.js 1 year ago marketplace-suggestions.min.js 1 year ago meta-boxes-coupon.js 1 year ago meta-boxes-coupon.min.js 1 year ago meta-boxes-order.js 2 months ago meta-boxes-order.min.js 2 months ago meta-boxes-product-variation.js 1 month ago meta-boxes-product-variation.min.js 1 month ago meta-boxes-product.js 1 month ago meta-boxes-product.min.js 1 month ago meta-boxes.js 6 months ago meta-boxes.min.js 6 months ago network-orders.js 8 years ago network-orders.min.js 3 years ago order-attribution-admin.js 2 years ago order-attribution-admin.min.js 2 years ago product-editor.js 1 year ago product-editor.min.js 1 year ago product-ordering.js 5 months ago product-ordering.min.js 5 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 month ago settings-views-html-settings-tax.min.js 1 month ago settings.js 1 year ago settings.min.js 1 year ago system-status.js 1 month ago system-status.min.js 1 month ago term-ordering.js 5 months ago term-ordering.min.js 5 months ago users.js 5 years ago users.min.js 3 years ago variation-gallery.js 2 months ago variation-gallery.min.js 2 months 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 1 year ago wc-customer-stock-notifications.min.js 1 year ago wc-enhanced-select.js 1 month ago wc-enhanced-select.min.js 1 month ago wc-orders.js 3 weeks ago wc-orders.min.js 3 weeks 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 3 years ago wc-recent-reviews-widget-async.js 6 months ago wc-recent-reviews-widget-async.min.js 6 months ago wc-setup.js 5 years ago wc-setup.min.js 3 years ago wc-shipping-classes.js 1 year ago wc-shipping-classes.min.js 1 year ago wc-shipping-providers.js 5 months ago wc-shipping-providers.min.js 5 months ago wc-shipping-zone-methods.js 7 months ago wc-shipping-zone-methods.min.js 7 months ago wc-shipping-zones.js 1 year ago wc-shipping-zones.min.js 1 year ago wc-status-widget-async.js 6 months ago wc-status-widget-async.min.js 6 months ago wc-status-widget.js 1 year ago wc-status-widget.min.js 1 year ago woocommerce_admin.js 1 month ago woocommerce_admin.min.js 1 month ago
woocommerce_admin.js
858 lines
1 /* global woocommerce_admin */
2 ( function ( $, woocommerce_admin ) {
3 $( function () {
4 if ( 'undefined' === typeof woocommerce_admin ) {
5 return;
6 }
7
8 // Toggle #wc-lost-connection-notice via WP core's heartbeat events (see WC_Admin_Assets::render_lost_connection_notice()).
9 if ( woocommerce_admin.show_lost_connection_notice ) {
10 $( document )
11 .on( 'heartbeat-connection-lost.wc-lost-connection-notice', function ( event, error, status ) {
12 if ( 'timeout' === error || 603 === status ) {
13 $( '#wc-lost-connection-notice' ).show();
14 }
15 } )
16 .on( 'heartbeat-connection-restored.wc-lost-connection-notice', function () {
17 $( '#wc-lost-connection-notice' ).hide();
18 } );
19 }
20
21 // Add buttons to product screen.
22 var $product_screen = $( '.edit-php.post-type-product' ),
23 $title_action = $product_screen.find( '.page-title-action:first' ),
24 $blankslate = $product_screen.find( '.woocommerce-BlankState' );
25
26 if ( 0 === $blankslate.length ) {
27 if ( woocommerce_admin.urls.add_product ) {
28 $title_action
29 .first()
30 .attr( 'href', woocommerce_admin.urls.add_product );
31 }
32 if ( woocommerce_admin.urls.export_products ) {
33 const exportLink = document.createElement('a');
34 exportLink.href = woocommerce_admin.urls.export_products;
35 exportLink.className = 'page-title-action';
36 exportLink.textContent = woocommerce_admin.strings.export_products;
37
38 $title_action.after(exportLink);
39 }
40 if ( woocommerce_admin.urls.import_products ) {
41 const importLink = document.createElement('a');
42 importLink.href = woocommerce_admin.urls.import_products;
43 importLink.className = 'page-title-action';
44 importLink.textContent = woocommerce_admin.strings.import_products;
45
46 $title_action.after(importLink);
47 }
48 } else {
49 $title_action.hide();
50 }
51
52 // Progress indicators when showing steps.
53 $( '.woocommerce-progress-form-wrapper .button-next' ).on(
54 'click',
55 function () {
56 $( '.wc-progress-form-content' ).block( {
57 message: null,
58 overlayCSS: {
59 background: '#fff',
60 opacity: 0.6,
61 },
62 } );
63 return true;
64 }
65 );
66
67 // Field validation error tips
68 $( document.body )
69 .on( 'wc_add_error_tip', function ( e, element, error_type ) {
70 var offset = element.position();
71
72 if ( element.parent().find( '.wc_error_tip' ).length === 0 ) {
73 element.after(
74 '<div class="wc_error_tip ' +
75 error_type +
76 '">' +
77 woocommerce_admin[ error_type ] +
78 '</div>'
79 );
80 element
81 .parent()
82 .find( '.wc_error_tip' )
83 .css(
84 'left',
85 offset.left +
86 element.width() -
87 element.width() / 2 -
88 $( '.wc_error_tip' ).width() / 2
89 )
90 .css( 'top', offset.top + element.height() )
91 .fadeIn( '100' );
92 }
93 } )
94
95 .on( 'wc_remove_error_tip', function ( e, element, error_type ) {
96 element
97 .parent()
98 .find( '.wc_error_tip.' + error_type )
99 .fadeOut( '100', function () {
100 $( this ).remove();
101 } );
102 } )
103
104 .on( 'click', function () {
105 $( '.wc_error_tip' ).fadeOut( '100', function () {
106 $( this ).remove();
107 } );
108 } )
109
110 .on(
111 'blur',
112 '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]',
113 function () {
114 $( '.wc_error_tip' ).fadeOut( '100', function () {
115 $( this ).remove();
116 } );
117 }
118 )
119
120 .on(
121 'change',
122 '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text], ' +
123 '.wc_input_variations_price[type=text]',
124 function () {
125 var regex,
126 decimalRegex,
127 decimailPoint = woocommerce_admin.decimal_point;
128
129 if (
130 $( this ).is( '.wc_input_price' ) ||
131 $( this ).is( '.wc_input_variations_price' ) ||
132 $( this ).is( '#refund_amount' )
133 ) {
134 decimailPoint = woocommerce_admin.mon_decimal_point;
135 }
136
137 regex = new RegExp(
138 '[^-0-9%\\' + decimailPoint + ']+',
139 'gi'
140 );
141 decimalRegex = new RegExp(
142 '\\' + decimailPoint + '+',
143 'gi'
144 );
145
146 var value = $( this ).val();
147 var newvalue = value
148 .replace( regex, '' )
149 .replace( decimalRegex, decimailPoint );
150
151 if ( value !== newvalue ) {
152 $( this ).val( newvalue );
153 }
154 }
155 )
156
157 .on(
158 'keyup',
159 // eslint-disable-next-line max-len
160 '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text], .wc-order-totals #refund_amount[type=text], .wc_input_variations_price[type=text]',
161 function () {
162 var regex, error, decimalRegex;
163 var checkDecimalNumbers = false;
164 if (
165 $( this ).is( '.wc_input_price' ) ||
166 $( this ).is( '.wc_input_variations_price' ) ||
167 $( this ).is( '#refund_amount' )
168 ) {
169 checkDecimalNumbers = true;
170 regex = new RegExp(
171 '[^-0-9%\\' +
172 woocommerce_admin.mon_decimal_point +
173 ']+',
174 'gi'
175 );
176 decimalRegex = new RegExp(
177 '[^\\' + woocommerce_admin.mon_decimal_point + ']',
178 'gi'
179 );
180 error = 'i18n_mon_decimal_error';
181 } else if ( $( this ).is( '.wc_input_country_iso' ) ) {
182 regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
183 error = 'i18n_country_iso_error';
184 } else {
185 checkDecimalNumbers = true;
186 regex = new RegExp(
187 '[^-0-9%\\' +
188 woocommerce_admin.decimal_point +
189 ']+',
190 'gi'
191 );
192 decimalRegex = new RegExp(
193 '[^\\' + woocommerce_admin.decimal_point + ']',
194 'gi'
195 );
196 error = 'i18n_decimal_error';
197 }
198
199 var value = $( this ).val();
200 var newvalue = value.replace( regex, '' );
201
202 // Check if newvalue have more than one decimal point.
203 if (
204 checkDecimalNumbers &&
205 1 < newvalue.replace( decimalRegex, '' ).length
206 ) {
207 newvalue = newvalue.replace( decimalRegex, '' );
208 }
209
210 if ( value !== newvalue ) {
211 $( document.body ).triggerHandler( 'wc_add_error_tip', [
212 $( this ),
213 error,
214 ] );
215 } else {
216 $(
217 document.body
218 ).triggerHandler( 'wc_remove_error_tip', [
219 $( this ),
220 error,
221 ] );
222 }
223 }
224 )
225
226 .on(
227 'change',
228 '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]',
229 function () {
230 var sale_price_field = $( this ),
231 regular_price_field;
232
233 if (
234 sale_price_field
235 .attr( 'name' )
236 .indexOf( 'variable' ) !== -1
237 ) {
238 regular_price_field = sale_price_field
239 .parents( '.variable_pricing' )
240 .find(
241 '.wc_input_price[name^=variable_regular_price]'
242 );
243 } else {
244 regular_price_field = $( '#_regular_price' );
245 }
246
247 var sale_price = parseFloat(
248 window.accounting.unformat(
249 sale_price_field.val(),
250 woocommerce_admin.mon_decimal_point
251 )
252 );
253 var regular_price = parseFloat(
254 window.accounting.unformat(
255 regular_price_field.val(),
256 woocommerce_admin.mon_decimal_point
257 )
258 );
259
260 if ( sale_price >= regular_price ) {
261 $( this ).val( '' );
262 }
263 }
264 )
265
266 .on(
267 'keyup',
268 '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]',
269 function () {
270 var sale_price_field = $( this ),
271 regular_price_field;
272
273 if (
274 sale_price_field
275 .attr( 'name' )
276 .indexOf( 'variable' ) !== -1
277 ) {
278 regular_price_field = sale_price_field
279 .parents( '.variable_pricing' )
280 .find(
281 '.wc_input_price[name^=variable_regular_price]'
282 );
283 } else {
284 regular_price_field = $( '#_regular_price' );
285 }
286
287 var sale_price = parseFloat(
288 window.accounting.unformat(
289 sale_price_field.val(),
290 woocommerce_admin.mon_decimal_point
291 )
292 );
293 var regular_price = parseFloat(
294 window.accounting.unformat(
295 regular_price_field.val(),
296 woocommerce_admin.mon_decimal_point
297 )
298 );
299
300 if ( sale_price >= regular_price ) {
301 $( document.body ).triggerHandler( 'wc_add_error_tip', [
302 $( this ),
303 'i18n_sale_less_than_regular_error',
304 ] );
305 } else {
306 $( document.body ).triggerHandler(
307 'wc_remove_error_tip',
308 [ $( this ), 'i18n_sale_less_than_regular_error' ]
309 );
310 }
311 }
312 )
313
314 .on(
315 'keyup',
316 'input[type=text][name*=_global_unique_id]',
317 function () {
318 // X/x is only valid as the final ISBN-10 check digit (ISO 2108).
319 if ( ! /^[0-9\-]*[0-9Xx]?$/.test( $( this ).val() ) ) {
320 $( document.body ).triggerHandler( 'wc_add_error_tip', [
321 $( this ),
322 'i18n_global_unique_id_error',
323 ] );
324 } else {
325 $( document.body ).triggerHandler(
326 'wc_remove_error_tip',
327 [ $( this ), 'i18n_global_unique_id_error' ]
328 );
329 }
330 }
331 )
332
333 .on(
334 'change',
335 'input[type=text][name*=_global_unique_id]',
336 function () {
337 var cleaned = $( this )
338 .val()
339 .replace( /[^0-9Xx\-]/g, '' )
340 .replace( /^-+|-+$/g, '' );
341 $( this ).val( cleaned );
342
343 if ( ! /^[0-9\-]*[0-9Xx]?$/.test( cleaned ) ) {
344 $( document.body ).triggerHandler( 'wc_add_error_tip', [
345 $( this ),
346 'i18n_global_unique_id_error',
347 ] );
348 } else {
349 $( document.body ).triggerHandler(
350 'wc_remove_error_tip',
351 [ $( this ), 'i18n_global_unique_id_error' ]
352 );
353 }
354 }
355 )
356
357 .on( 'init_tooltips', function () {
358 $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip( {
359 attribute: 'data-tip',
360 fadeIn: 50,
361 fadeOut: 50,
362 delay: 200,
363 keepAlive: true,
364 } );
365
366 $( '.column-wc_actions .wc-action-button' ).tipTip( {
367 fadeIn: 50,
368 fadeOut: 50,
369 delay: 200,
370 } );
371
372 // Add tiptip to parent element for widefat tables
373 $( '.parent-tips' ).each( function () {
374 $( this )
375 .closest( 'a, th' )
376 .attr( 'data-tip', $( this ).data( 'tip' ) )
377 .tipTip( {
378 attribute: 'data-tip',
379 fadeIn: 50,
380 fadeOut: 50,
381 delay: 200,
382 keepAlive: true,
383 } )
384 .css( 'cursor', 'help' );
385 } );
386 } )
387
388 .on( 'click', '.wc-confirm-delete', function ( event ) {
389 if (
390 ! window.confirm( woocommerce_admin.i18n_confirm_delete )
391 ) {
392 event.stopPropagation();
393 }
394 } );
395
396 // Tooltips
397 $( document.body ).trigger( 'init_tooltips' );
398
399 // wc_input_table tables
400 $( '.wc_input_table.sortable tbody' ).sortable( {
401 items: 'tr',
402 cursor: 'move',
403 axis: 'y',
404 scrollSensitivity: 40,
405 forcePlaceholderSize: true,
406 helper: 'clone',
407 opacity: 0.65,
408 placeholder: 'wc-metabox-sortable-placeholder',
409 start: function ( event, ui ) {
410 ui.item.css( 'background-color', '#f6f6f6' );
411 },
412 stop: function ( event, ui ) {
413 ui.item.removeAttr( 'style' );
414 },
415 } );
416 // Focus on inputs within the table if clicked instead of trying to sort.
417 $( '.wc_input_table.sortable tbody input' ).on( 'click', function () {
418 $( this ).trigger( 'focus' );
419 } );
420
421 $( '.wc_input_table .remove_rows' ).on( 'click', function () {
422 var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' );
423 if ( $tbody.find( 'tr.current' ).length > 0 ) {
424 var $current = $tbody.find( 'tr.current' );
425 $current.each( function () {
426 $( this ).remove();
427 } );
428 }
429 return false;
430 } );
431
432 var controlled = false;
433 var shifted = false;
434 var hasFocus = false;
435
436 $( document.body ).on( 'keyup keydown', function ( e ) {
437 shifted = e.shiftKey;
438 controlled = e.ctrlKey || e.metaKey;
439 } );
440
441 $( '.wc_input_table' )
442 .on( 'focus click', 'input', function ( e ) {
443 var $this_table = $( this ).closest( 'table, tbody' );
444 var $this_row = $( this ).closest( 'tr' );
445
446 if (
447 ( e.type === 'focus' && hasFocus !== $this_row.index() ) ||
448 ( e.type === 'click' && $( this ).is( ':focus' ) )
449 ) {
450 hasFocus = $this_row.index();
451
452 if ( ! shifted && ! controlled ) {
453 $( 'tr', $this_table )
454 .removeClass( 'current' )
455 .removeClass( 'last_selected' );
456 $this_row
457 .addClass( 'current' )
458 .addClass( 'last_selected' );
459 } else if ( shifted ) {
460 $( 'tr', $this_table ).removeClass( 'current' );
461 $this_row
462 .addClass( 'selected_now' )
463 .addClass( 'current' );
464
465 if ( $( 'tr.last_selected', $this_table ).length > 0 ) {
466 if (
467 $this_row.index() >
468 $( 'tr.last_selected', $this_table ).index()
469 ) {
470 $( 'tr', $this_table )
471 .slice(
472 $(
473 'tr.last_selected',
474 $this_table
475 ).index(),
476 $this_row.index()
477 )
478 .addClass( 'current' );
479 } else {
480 $( 'tr', $this_table )
481 .slice(
482 $this_row.index(),
483 $(
484 'tr.last_selected',
485 $this_table
486 ).index() + 1
487 )
488 .addClass( 'current' );
489 }
490 }
491
492 $( 'tr', $this_table ).removeClass( 'last_selected' );
493 $this_row.addClass( 'last_selected' );
494 } else {
495 $( 'tr', $this_table ).removeClass( 'last_selected' );
496 if (
497 controlled &&
498 $( this ).closest( 'tr' ).is( '.current' )
499 ) {
500 $this_row.removeClass( 'current' );
501 } else {
502 $this_row
503 .addClass( 'current' )
504 .addClass( 'last_selected' );
505 }
506 }
507
508 $( 'tr', $this_table ).removeClass( 'selected_now' );
509 }
510 } )
511 .on( 'blur', 'input', function () {
512 hasFocus = false;
513 } );
514
515 // Additional cost and Attribute term tables
516 $(
517 '.woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)'
518 ).addClass( 'alternate' );
519
520 // Show order items on orders page
521 $( document.body ).on( 'click', '.show_order_items', function () {
522 $( this ).closest( 'td' ).find( 'table' ).toggle();
523 return false;
524 } );
525
526 // Select availability
527 $( 'select.availability' )
528 .on( 'change', function () {
529 if ( $( this ).val() === 'all' ) {
530 $( this ).closest( 'tr' ).next( 'tr' ).hide();
531 } else {
532 $( this ).closest( 'tr' ).next( 'tr' ).show();
533 }
534 } )
535 .trigger( 'change' );
536
537 // Hidden options
538 $( '.hide_options_if_checked' ).each( function () {
539 $( this )
540 .find( 'input:eq(0)' )
541 .on( 'change', function () {
542 if ( $( this ).is( ':checked' ) ) {
543 $( this )
544 .closest( 'fieldset, tr' )
545 .nextUntil(
546 '.hide_options_if_checked, .show_options_if_checked',
547 '.hidden_option'
548 )
549 .hide();
550 } else {
551 $( this )
552 .closest( 'fieldset, tr' )
553 .nextUntil(
554 '.hide_options_if_checked, .show_options_if_checked',
555 '.hidden_option'
556 )
557 .show();
558 }
559 } )
560 .trigger( 'change' );
561 } );
562
563 $( '.show_options_if_checked' ).each( function () {
564 $( this )
565 .find( 'input:eq(0)' )
566 .on( 'change', function () {
567 if ( $( this ).is( ':checked' ) ) {
568 $( this )
569 .closest( 'fieldset, tr' )
570 .nextUntil(
571 '.hide_options_if_checked, .show_options_if_checked',
572 '.hidden_option'
573 )
574 .show();
575 } else {
576 $( this )
577 .closest( 'fieldset, tr' )
578 .nextUntil(
579 '.hide_options_if_checked, .show_options_if_checked',
580 '.hidden_option'
581 )
582 .hide();
583 }
584 } )
585 .trigger( 'change' );
586 } );
587
588 // Reviews.
589 $( 'input#woocommerce_enable_reviews' )
590 .on( 'change', function () {
591 if ( $( this ).is( ':checked' ) ) {
592 $( '#woocommerce_enable_review_rating' )
593 .closest( 'tr' )
594 .show();
595 } else {
596 $( '#woocommerce_enable_review_rating' )
597 .closest( 'tr' )
598 .hide();
599 }
600 } )
601 .trigger( 'change' );
602
603 // Attribute term table
604 $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass(
605 'alternate'
606 );
607
608 // Toggle gateway on/off.
609 $( '.wc_gateways' ).on(
610 'click',
611 '.wc-payment-gateway-method-toggle-enabled',
612 function () {
613 var $link = $( this ),
614 $row = $link.closest( 'tr' ),
615 $toggle = $link.find( '.woocommerce-input-toggle' );
616
617 var data = {
618 action: 'woocommerce_toggle_gateway_enabled',
619 security: woocommerce_admin.nonces.gateway_toggle,
620 gateway_id: $row.data( 'gateway_id' ),
621 };
622
623 $toggle.addClass( 'woocommerce-input-toggle--loading' );
624
625 $.ajax( {
626 url: woocommerce_admin.ajax_url,
627 data: data,
628 dataType: 'json',
629 type: 'POST',
630 success: function ( response ) {
631 if ( true === response.data ) {
632 $toggle.removeClass(
633 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled'
634 );
635 $toggle.addClass(
636 'woocommerce-input-toggle--enabled'
637 );
638 $toggle.removeClass(
639 'woocommerce-input-toggle--loading'
640 );
641 } else if ( false === response.data ) {
642 $toggle.removeClass(
643 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled'
644 );
645 $toggle.addClass(
646 'woocommerce-input-toggle--disabled'
647 );
648 $toggle.removeClass(
649 'woocommerce-input-toggle--loading'
650 );
651 } else if ( 'needs_setup' === response.data ) {
652 window.location.href = $link.attr( 'href' );
653 }
654 },
655 } );
656
657 return false;
658 }
659 );
660
661 $( '#wpbody' ).on( 'click', '#doaction, #doaction2', function () {
662 var action = $( this ).is( '#doaction' )
663 ? $( '#bulk-action-selector-top' ).val()
664 : $( '#bulk-action-selector-bottom' ).val();
665
666 if ( 'remove_personal_data' === action ) {
667 return window.confirm(
668 woocommerce_admin.i18n_remove_personal_data_notice
669 );
670 }
671 } );
672
673 var marketplaceSectionDropdown = $(
674 '#marketplace-current-section-dropdown'
675 );
676 var marketplaceSectionName = $( '#marketplace-current-section-name' );
677 var marketplaceMenuIsOpen = false;
678
679 // Add event listener to toggle Marketplace menu on touch devices
680 if ( marketplaceSectionDropdown.length ) {
681 if ( isTouchDevice() ) {
682 marketplaceSectionName.on( 'click', function () {
683 marketplaceMenuIsOpen = ! marketplaceMenuIsOpen;
684 if ( marketplaceMenuIsOpen ) {
685 marketplaceSectionDropdown.addClass( 'is-open' );
686 $( document ).on( 'click', maybeToggleMarketplaceMenu );
687 } else {
688 marketplaceSectionDropdown.removeClass( 'is-open' );
689 $( document ).off(
690 'click',
691 maybeToggleMarketplaceMenu
692 );
693 }
694 } );
695 } else {
696 document.body.classList.add( 'no-touch' );
697 }
698 }
699
700 // Close menu if the user clicks outside it
701 function maybeToggleMarketplaceMenu( e ) {
702 if (
703 ! marketplaceSectionDropdown.is( e.target ) &&
704 marketplaceSectionDropdown.has( e.target ).length === 0
705 ) {
706 marketplaceSectionDropdown.removeClass( 'is-open' );
707 marketplaceMenuIsOpen = false;
708 $( document ).off( 'click', maybeToggleMarketplaceMenu );
709 }
710 }
711
712 function isTouchDevice() {
713 return (
714 'ontouchstart' in window ||
715 navigator.maxTouchPoints > 0 ||
716 navigator.msMaxTouchPoints > 0
717 );
718 }
719 } );
720
721 $( function() {
722 /**
723 * Handles heartbeat integration of order locking when HPOS is enabled.
724 */
725 var wc_order_lock = {
726 init: function() {
727 // Order screen.
728 this.$lock_dialog = $( '#post-lock-dialog.order-lock-dialog' );
729 if ( 0 !== this.$lock_dialog.length && 'undefined' !== typeof woocommerce_admin_meta_boxes ) {
730 // We do not want WP's lock to interfere.
731 $( document ).off( 'heartbeat-send.refresh-lock' );
732 $( document ).off( 'heartbeat-tick.refresh-lock' );
733
734 $( document ).on( 'heartbeat-send', this.refresh_order_lock );
735 $( document ).on( 'heartbeat-tick', this.check_order_lock );
736 }
737
738 // Orders list table.
739 this.$list_table = $( 'table.wc-orders-list-table' );
740 if ( 0 !== this.$list_table.length ) {
741 $( document ).on( 'heartbeat-send', this.send_orders_in_list );
742 $( document ).on( 'heartbeat-tick', this.check_orders_in_list );
743 }
744 },
745
746 refresh_order_lock: function( e, data ) {
747 delete data['wp-refresh-post-lock'];
748 data['wc-refresh-order-lock'] = woocommerce_admin_meta_boxes.post_id;
749 },
750
751 check_order_lock: function( e, data ) {
752 var lock_data = data['wc-refresh-order-lock'];
753
754 if ( ! lock_data || ! lock_data.error ) {
755 // No lock request in heartbeat or lock refreshed ok.
756 return;
757 }
758
759 if ( wc_order_lock.$lock_dialog.is( ':visible' ) ) {
760 return;
761 }
762
763 if ( lock_data.error.user_avatar_src ) {
764 wc_order_lock.$lock_dialog.find( '.post-locked-avatar' ).empty().append(
765 $(
766 '<img />',
767 {
768 'class': 'avatar avatar-64 photo',
769 width: 64,
770 height: 64,
771 alt: '',
772 src: lock_data.error.user_avatar_src,
773 srcset: lock_data.error.user_avatar_src_2x ? lock_data.error.user_avatar_src_2x + ' 2x' : undefined
774 }
775 )
776 );
777 }
778
779 wc_order_lock.$lock_dialog.find( '.currently-editing' ).text( lock_data.error.message );
780 wc_order_lock.$lock_dialog.show();
781 wc_order_lock.$lock_dialog.find( '.wp-tab-first' ).trigger( 'focus' );
782 },
783
784 send_orders_in_list: function( e, data ) {
785 data['wc-check-locked-orders'] = wc_order_lock.$list_table.find( 'tr input[name="id[]"]' ).map(
786 function() { return this.value; }
787 ).get();
788 },
789
790 check_orders_in_list: function( e, data ) {
791 var locked_orders = data['wc-check-locked-orders'] || {};
792
793 wc_order_lock.$list_table.find( 'tr' ).each( function( i, tr ) {
794 var $tr = $( tr );
795 var order_id = $tr.find( 'input[name="id[]"]' ).val();
796
797 if ( locked_orders[ order_id ] ) {
798 if ( ! $tr.hasClass( 'wp-locked' ) ) {
799 $tr.find( '.check-column checkbox' ).prop( 'checked', false );
800 $tr.addClass( 'wp-locked' );
801 }
802 } else {
803 $tr.removeClass( 'wp-locked' ).find( '.locked-info span' ).empty();
804 }
805 } );
806 }
807 };
808
809 wc_order_lock.init();
810 } );
811
812 // Function to handle selected product export
813 $( function () {
814 const $exportButton = $( 'a.page-title-action[href*="page=product_exporter"]');
815 // bail out early.
816 if ( !$exportButton.length ) {
817 return;
818 }
819
820 const originalExportHref = $exportButton.attr( 'href' );
821 const originalExportText = $exportButton.text();
822
823 // Use event delegation on the form containing the list table.
824 $( '#posts-filter' ).on(
825 'change',
826 '#the-list input[type="checkbox"][name="post[]"], #cb-select-all-1, #cb-select-all-2',
827 function () {
828 // Use a minimal timeout to ensure the checked state is updated in the DOM.
829 setTimeout( function () {
830 const selectedProductIds = $(
831 '#the-list input[type="checkbox"][name="post[]"]:checked'
832 )
833 .map( function () {
834 return $( this ).val();
835 } )
836 .get(); // .get() converts the jQuery object to a standard array.
837
838 // Update Export button.
839 if ( selectedProductIds.length > 0 ) {
840 // Construct the new href with product_ids and nonce.
841 const url = new URL( originalExportHref );
842 url.searchParams.set( 'product_ids', selectedProductIds.join(','));
843 url.searchParams.set( '_wpnonce', woocommerce_admin.nonces.export_selected_products_nonce);
844 const newHref = url.toString();
845 // Construct the text with the count of selected products.
846 const count = selectedProductIds.length;
847 const buttonText = woocommerce_admin.strings.export_selected_products.replace( '%d', count );
848 $exportButton.text( buttonText ).attr( 'href', newHref );
849 } else {
850 $exportButton.text( originalExportText ).attr( 'href', originalExportHref );
851 }
852 }, 0 );
853 }
854 );
855 } );
856
857 } )( jQuery, woocommerce_admin );
858