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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 / woocommerce_admin.js
woocommerce / assets / js / admin Last commit date
api-keys.js 5 years ago api-keys.min.js 5 years ago backbone-modal.js 5 years ago backbone-modal.min.js 5 years ago marketplace-suggestions.js 4 years ago marketplace-suggestions.min.js 3 years ago meta-boxes-coupon.js 5 years ago meta-boxes-coupon.min.js 3 years ago meta-boxes-order.js 3 years ago meta-boxes-order.min.js 3 years ago meta-boxes-product-variation.js 3 years ago meta-boxes-product-variation.min.js 3 years ago meta-boxes-product.js 3 years ago meta-boxes-product.min.js 3 years ago meta-boxes.js 3 years ago meta-boxes.min.js 3 years ago network-orders.js 8 years ago network-orders.min.js 3 years ago product-editor.js 3 years ago product-editor.min.js 3 years ago product-ordering.js 3 years ago product-ordering.min.js 3 years ago quick-edit.js 4 years ago quick-edit.min.js 3 years ago reports.js 5 years ago reports.min.js 3 years ago settings-views-html-settings-tax.js 5 years ago settings-views-html-settings-tax.min.js 3 years ago settings.js 4 years ago settings.min.js 3 years ago system-status.js 3 years ago system-status.min.js 3 years ago term-ordering.js 3 years ago term-ordering.min.js 3 years ago users.js 5 years ago users.min.js 3 years ago wc-clipboard.js 5 years ago wc-clipboard.min.js 5 years ago wc-enhanced-select.js 3 years ago wc-enhanced-select.min.js 3 years ago wc-orders.js 3 years ago wc-orders.min.js 3 years ago wc-product-export.js 5 years ago wc-product-export.min.js 5 years ago wc-product-import.js 3 years ago wc-product-import.min.js 3 years ago wc-setup.js 5 years ago wc-setup.min.js 3 years ago wc-shipping-classes.js 5 years ago wc-shipping-classes.min.js 3 years ago wc-shipping-zone-methods.js 4 years ago wc-shipping-zone-methods.min.js 3 years ago wc-shipping-zones.js 4 years ago wc-shipping-zones.min.js 3 years ago wc-status-widget.js 4 years ago wc-status-widget.min.js 4 years ago woocommerce_admin.js 3 years ago woocommerce_admin.min.js 3 years ago
woocommerce_admin.js
669 lines
1 /* global woocommerce_admin */
2 ( function ( $, woocommerce_admin ) {
3 $( function () {
4 if ( 'undefined' === typeof woocommerce_admin ) {
5 return;
6 }
7
8 // Add buttons to product screen.
9 var $product_screen = $( '.edit-php.post-type-product' ),
10 $title_action = $product_screen.find( '.page-title-action:first' ),
11 $blankslate = $product_screen.find( '.woocommerce-BlankState' );
12
13 if ( 0 === $blankslate.length ) {
14 if ( woocommerce_admin.urls.add_product ) {
15 $title_action
16 .first()
17 .attr( 'href', woocommerce_admin.urls.add_product );
18 }
19 if ( woocommerce_admin.urls.export_products ) {
20 $title_action.after(
21 '<a href="' +
22 woocommerce_admin.urls.export_products +
23 '" class="page-title-action">' +
24 woocommerce_admin.strings.export_products +
25 '</a>'
26 );
27 }
28 if ( woocommerce_admin.urls.import_products ) {
29 $title_action.after(
30 '<a href="' +
31 woocommerce_admin.urls.import_products +
32 '" class="page-title-action">' +
33 woocommerce_admin.strings.import_products +
34 '</a>'
35 );
36 }
37 } else {
38 $title_action.hide();
39 }
40
41 // Progress indicators when showing steps.
42 $( '.woocommerce-progress-form-wrapper .button-next' ).on(
43 'click',
44 function () {
45 $( '.wc-progress-form-content' ).block( {
46 message: null,
47 overlayCSS: {
48 background: '#fff',
49 opacity: 0.6,
50 },
51 } );
52 return true;
53 }
54 );
55
56 // Field validation error tips
57 $( document.body )
58 .on( 'wc_add_error_tip', function ( e, element, error_type ) {
59 var offset = element.position();
60
61 if ( element.parent().find( '.wc_error_tip' ).length === 0 ) {
62 element.after(
63 '<div class="wc_error_tip ' +
64 error_type +
65 '">' +
66 woocommerce_admin[ error_type ] +
67 '</div>'
68 );
69 element
70 .parent()
71 .find( '.wc_error_tip' )
72 .css(
73 'left',
74 offset.left +
75 element.width() -
76 element.width() / 2 -
77 $( '.wc_error_tip' ).width() / 2
78 )
79 .css( 'top', offset.top + element.height() )
80 .fadeIn( '100' );
81 }
82 } )
83
84 .on( 'wc_remove_error_tip', function ( e, element, error_type ) {
85 element
86 .parent()
87 .find( '.wc_error_tip.' + error_type )
88 .fadeOut( '100', function () {
89 $( this ).remove();
90 } );
91 } )
92
93 .on( 'click', function () {
94 $( '.wc_error_tip' ).fadeOut( '100', function () {
95 $( this ).remove();
96 } );
97 } )
98
99 .on(
100 'blur',
101 '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]',
102 function () {
103 $( '.wc_error_tip' ).fadeOut( '100', function () {
104 $( this ).remove();
105 } );
106 }
107 )
108
109 .on(
110 'change',
111 '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text], ' +
112 '.wc_input_variations_price[type=text]',
113 function () {
114 var regex,
115 decimalRegex,
116 decimailPoint = woocommerce_admin.decimal_point;
117
118 if (
119 $( this ).is( '.wc_input_price' ) ||
120 $( this ).is( '.wc_input_variations_price' ) ||
121 $( this ).is( '#refund_amount' )
122 ) {
123 decimailPoint = woocommerce_admin.mon_decimal_point;
124 }
125
126 regex = new RegExp(
127 '[^-0-9%\\' + decimailPoint + ']+',
128 'gi'
129 );
130 decimalRegex = new RegExp(
131 '\\' + decimailPoint + '+',
132 'gi'
133 );
134
135 var value = $( this ).val();
136 var newvalue = value
137 .replace( regex, '' )
138 .replace( decimalRegex, decimailPoint );
139
140 if ( value !== newvalue ) {
141 $( this ).val( newvalue );
142 }
143 }
144 )
145
146 .on(
147 'keyup',
148 // eslint-disable-next-line max-len
149 '.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]',
150 function () {
151 var regex, error, decimalRegex;
152 var checkDecimalNumbers = false;
153 if (
154 $( this ).is( '.wc_input_price' ) ||
155 $( this ).is( '.wc_input_variations_price' ) ||
156 $( this ).is( '#refund_amount' )
157 ) {
158 checkDecimalNumbers = true;
159 regex = new RegExp(
160 '[^-0-9%\\' +
161 woocommerce_admin.mon_decimal_point +
162 ']+',
163 'gi'
164 );
165 decimalRegex = new RegExp(
166 '[^\\' + woocommerce_admin.mon_decimal_point + ']',
167 'gi'
168 );
169 error = 'i18n_mon_decimal_error';
170 } else if ( $( this ).is( '.wc_input_country_iso' ) ) {
171 regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
172 error = 'i18n_country_iso_error';
173 } else {
174 checkDecimalNumbers = true;
175 regex = new RegExp(
176 '[^-0-9%\\' +
177 woocommerce_admin.decimal_point +
178 ']+',
179 'gi'
180 );
181 decimalRegex = new RegExp(
182 '[^\\' + woocommerce_admin.decimal_point + ']',
183 'gi'
184 );
185 error = 'i18n_decimal_error';
186 }
187
188 var value = $( this ).val();
189 var newvalue = value.replace( regex, '' );
190
191 // Check if newvalue have more than one decimal point.
192 if (
193 checkDecimalNumbers &&
194 1 < newvalue.replace( decimalRegex, '' ).length
195 ) {
196 newvalue = newvalue.replace( decimalRegex, '' );
197 }
198
199 if ( value !== newvalue ) {
200 $( document.body ).triggerHandler( 'wc_add_error_tip', [
201 $( this ),
202 error,
203 ] );
204 } else {
205 $(
206 document.body
207 ).triggerHandler( 'wc_remove_error_tip', [
208 $( this ),
209 error,
210 ] );
211 }
212 }
213 )
214
215 .on(
216 'change',
217 '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]',
218 function () {
219 var sale_price_field = $( this ),
220 regular_price_field;
221
222 if (
223 sale_price_field
224 .attr( 'name' )
225 .indexOf( 'variable' ) !== -1
226 ) {
227 regular_price_field = sale_price_field
228 .parents( '.variable_pricing' )
229 .find(
230 '.wc_input_price[name^=variable_regular_price]'
231 );
232 } else {
233 regular_price_field = $( '#_regular_price' );
234 }
235
236 var sale_price = parseFloat(
237 window.accounting.unformat(
238 sale_price_field.val(),
239 woocommerce_admin.mon_decimal_point
240 )
241 );
242 var regular_price = parseFloat(
243 window.accounting.unformat(
244 regular_price_field.val(),
245 woocommerce_admin.mon_decimal_point
246 )
247 );
248
249 if ( sale_price >= regular_price ) {
250 $( this ).val( '' );
251 }
252 }
253 )
254
255 .on(
256 'keyup',
257 '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]',
258 function () {
259 var sale_price_field = $( this ),
260 regular_price_field;
261
262 if (
263 sale_price_field
264 .attr( 'name' )
265 .indexOf( 'variable' ) !== -1
266 ) {
267 regular_price_field = sale_price_field
268 .parents( '.variable_pricing' )
269 .find(
270 '.wc_input_price[name^=variable_regular_price]'
271 );
272 } else {
273 regular_price_field = $( '#_regular_price' );
274 }
275
276 var sale_price = parseFloat(
277 window.accounting.unformat(
278 sale_price_field.val(),
279 woocommerce_admin.mon_decimal_point
280 )
281 );
282 var regular_price = parseFloat(
283 window.accounting.unformat(
284 regular_price_field.val(),
285 woocommerce_admin.mon_decimal_point
286 )
287 );
288
289 if ( sale_price >= regular_price ) {
290 $( document.body ).triggerHandler( 'wc_add_error_tip', [
291 $( this ),
292 'i18n_sale_less_than_regular_error',
293 ] );
294 } else {
295 $(
296 document.body
297 ).triggerHandler( 'wc_remove_error_tip', [
298 $( this ),
299 'i18n_sale_less_than_regular_error',
300 ] );
301 }
302 }
303 )
304
305 .on( 'init_tooltips', function () {
306 $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip( {
307 attribute: 'data-tip',
308 fadeIn: 50,
309 fadeOut: 50,
310 delay: 200,
311 keepAlive: true,
312 } );
313
314 $( '.column-wc_actions .wc-action-button' ).tipTip( {
315 fadeIn: 50,
316 fadeOut: 50,
317 delay: 200,
318 } );
319
320 // Add tiptip to parent element for widefat tables
321 $( '.parent-tips' ).each( function () {
322 $( this )
323 .closest( 'a, th' )
324 .attr( 'data-tip', $( this ).data( 'tip' ) )
325 .tipTip( {
326 attribute: 'data-tip',
327 fadeIn: 50,
328 fadeOut: 50,
329 delay: 200,
330 keepAlive: true,
331 } )
332 .css( 'cursor', 'help' );
333 } );
334 } )
335
336 .on( 'click', '.wc-confirm-delete', function ( event ) {
337 if (
338 ! window.confirm( woocommerce_admin.i18n_confirm_delete )
339 ) {
340 event.stopPropagation();
341 }
342 } );
343
344 // Tooltips
345 $( document.body ).trigger( 'init_tooltips' );
346
347 // wc_input_table tables
348 $( '.wc_input_table.sortable tbody' ).sortable( {
349 items: 'tr',
350 cursor: 'move',
351 axis: 'y',
352 scrollSensitivity: 40,
353 forcePlaceholderSize: true,
354 helper: 'clone',
355 opacity: 0.65,
356 placeholder: 'wc-metabox-sortable-placeholder',
357 start: function ( event, ui ) {
358 ui.item.css( 'background-color', '#f6f6f6' );
359 },
360 stop: function ( event, ui ) {
361 ui.item.removeAttr( 'style' );
362 },
363 } );
364 // Focus on inputs within the table if clicked instead of trying to sort.
365 $( '.wc_input_table.sortable tbody input' ).on( 'click', function () {
366 $( this ).trigger( 'focus' );
367 } );
368
369 $( '.wc_input_table .remove_rows' ).on( 'click', function () {
370 var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' );
371 if ( $tbody.find( 'tr.current' ).length > 0 ) {
372 var $current = $tbody.find( 'tr.current' );
373 $current.each( function () {
374 $( this ).remove();
375 } );
376 }
377 return false;
378 } );
379
380 var controlled = false;
381 var shifted = false;
382 var hasFocus = false;
383
384 $( document.body ).on( 'keyup keydown', function ( e ) {
385 shifted = e.shiftKey;
386 controlled = e.ctrlKey || e.metaKey;
387 } );
388
389 $( '.wc_input_table' )
390 .on( 'focus click', 'input', function ( e ) {
391 var $this_table = $( this ).closest( 'table, tbody' );
392 var $this_row = $( this ).closest( 'tr' );
393
394 if (
395 ( e.type === 'focus' && hasFocus !== $this_row.index() ) ||
396 ( e.type === 'click' && $( this ).is( ':focus' ) )
397 ) {
398 hasFocus = $this_row.index();
399
400 if ( ! shifted && ! controlled ) {
401 $( 'tr', $this_table )
402 .removeClass( 'current' )
403 .removeClass( 'last_selected' );
404 $this_row
405 .addClass( 'current' )
406 .addClass( 'last_selected' );
407 } else if ( shifted ) {
408 $( 'tr', $this_table ).removeClass( 'current' );
409 $this_row
410 .addClass( 'selected_now' )
411 .addClass( 'current' );
412
413 if ( $( 'tr.last_selected', $this_table ).length > 0 ) {
414 if (
415 $this_row.index() >
416 $( 'tr.last_selected', $this_table ).index()
417 ) {
418 $( 'tr', $this_table )
419 .slice(
420 $(
421 'tr.last_selected',
422 $this_table
423 ).index(),
424 $this_row.index()
425 )
426 .addClass( 'current' );
427 } else {
428 $( 'tr', $this_table )
429 .slice(
430 $this_row.index(),
431 $(
432 'tr.last_selected',
433 $this_table
434 ).index() + 1
435 )
436 .addClass( 'current' );
437 }
438 }
439
440 $( 'tr', $this_table ).removeClass( 'last_selected' );
441 $this_row.addClass( 'last_selected' );
442 } else {
443 $( 'tr', $this_table ).removeClass( 'last_selected' );
444 if (
445 controlled &&
446 $( this ).closest( 'tr' ).is( '.current' )
447 ) {
448 $this_row.removeClass( 'current' );
449 } else {
450 $this_row
451 .addClass( 'current' )
452 .addClass( 'last_selected' );
453 }
454 }
455
456 $( 'tr', $this_table ).removeClass( 'selected_now' );
457 }
458 } )
459 .on( 'blur', 'input', function () {
460 hasFocus = false;
461 } );
462
463 // Additional cost and Attribute term tables
464 $(
465 '.woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)'
466 ).addClass( 'alternate' );
467
468 // Show order items on orders page
469 $( document.body ).on( 'click', '.show_order_items', function () {
470 $( this ).closest( 'td' ).find( 'table' ).toggle();
471 return false;
472 } );
473
474 // Select availability
475 $( 'select.availability' )
476 .on( 'change', function () {
477 if ( $( this ).val() === 'all' ) {
478 $( this ).closest( 'tr' ).next( 'tr' ).hide();
479 } else {
480 $( this ).closest( 'tr' ).next( 'tr' ).show();
481 }
482 } )
483 .trigger( 'change' );
484
485 // Hidden options
486 $( '.hide_options_if_checked' ).each( function () {
487 $( this )
488 .find( 'input:eq(0)' )
489 .on( 'change', function () {
490 if ( $( this ).is( ':checked' ) ) {
491 $( this )
492 .closest( 'fieldset, tr' )
493 .nextUntil(
494 '.hide_options_if_checked, .show_options_if_checked',
495 '.hidden_option'
496 )
497 .hide();
498 } else {
499 $( this )
500 .closest( 'fieldset, tr' )
501 .nextUntil(
502 '.hide_options_if_checked, .show_options_if_checked',
503 '.hidden_option'
504 )
505 .show();
506 }
507 } )
508 .trigger( 'change' );
509 } );
510
511 $( '.show_options_if_checked' ).each( function () {
512 $( this )
513 .find( 'input:eq(0)' )
514 .on( 'change', function () {
515 if ( $( this ).is( ':checked' ) ) {
516 $( this )
517 .closest( 'fieldset, tr' )
518 .nextUntil(
519 '.hide_options_if_checked, .show_options_if_checked',
520 '.hidden_option'
521 )
522 .show();
523 } else {
524 $( this )
525 .closest( 'fieldset, tr' )
526 .nextUntil(
527 '.hide_options_if_checked, .show_options_if_checked',
528 '.hidden_option'
529 )
530 .hide();
531 }
532 } )
533 .trigger( 'change' );
534 } );
535
536 // Reviews.
537 $( 'input#woocommerce_enable_reviews' )
538 .on( 'change', function () {
539 if ( $( this ).is( ':checked' ) ) {
540 $( '#woocommerce_enable_review_rating' )
541 .closest( 'tr' )
542 .show();
543 } else {
544 $( '#woocommerce_enable_review_rating' )
545 .closest( 'tr' )
546 .hide();
547 }
548 } )
549 .trigger( 'change' );
550
551 // Attribute term table
552 $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass(
553 'alternate'
554 );
555
556 // Toggle gateway on/off.
557 $( '.wc_gateways' ).on(
558 'click',
559 '.wc-payment-gateway-method-toggle-enabled',
560 function () {
561 var $link = $( this ),
562 $row = $link.closest( 'tr' ),
563 $toggle = $link.find( '.woocommerce-input-toggle' );
564
565 var data = {
566 action: 'woocommerce_toggle_gateway_enabled',
567 security: woocommerce_admin.nonces.gateway_toggle,
568 gateway_id: $row.data( 'gateway_id' ),
569 };
570
571 $toggle.addClass( 'woocommerce-input-toggle--loading' );
572
573 $.ajax( {
574 url: woocommerce_admin.ajax_url,
575 data: data,
576 dataType: 'json',
577 type: 'POST',
578 success: function ( response ) {
579 if ( true === response.data ) {
580 $toggle.removeClass(
581 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled'
582 );
583 $toggle.addClass(
584 'woocommerce-input-toggle--enabled'
585 );
586 $toggle.removeClass(
587 'woocommerce-input-toggle--loading'
588 );
589 } else if ( false === response.data ) {
590 $toggle.removeClass(
591 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled'
592 );
593 $toggle.addClass(
594 'woocommerce-input-toggle--disabled'
595 );
596 $toggle.removeClass(
597 'woocommerce-input-toggle--loading'
598 );
599 } else if ( 'needs_setup' === response.data ) {
600 window.location.href = $link.attr( 'href' );
601 }
602 },
603 } );
604
605 return false;
606 }
607 );
608
609 $( '#wpbody' ).on( 'click', '#doaction, #doaction2', function () {
610 var action = $( this ).is( '#doaction' )
611 ? $( '#bulk-action-selector-top' ).val()
612 : $( '#bulk-action-selector-bottom' ).val();
613
614 if ( 'remove_personal_data' === action ) {
615 return window.confirm(
616 woocommerce_admin.i18n_remove_personal_data_notice
617 );
618 }
619 } );
620
621 var marketplaceSectionDropdown = $(
622 '#marketplace-current-section-dropdown'
623 );
624 var marketplaceSectionName = $( '#marketplace-current-section-name' );
625 var marketplaceMenuIsOpen = false;
626
627 // Add event listener to toggle Marketplace menu on touch devices
628 if ( marketplaceSectionDropdown.length ) {
629 if ( isTouchDevice() ) {
630 marketplaceSectionName.on( 'click', function () {
631 marketplaceMenuIsOpen = ! marketplaceMenuIsOpen;
632 if ( marketplaceMenuIsOpen ) {
633 marketplaceSectionDropdown.addClass( 'is-open' );
634 $( document ).on( 'click', maybeToggleMarketplaceMenu );
635 } else {
636 marketplaceSectionDropdown.removeClass( 'is-open' );
637 $( document ).off(
638 'click',
639 maybeToggleMarketplaceMenu
640 );
641 }
642 } );
643 } else {
644 document.body.classList.add( 'no-touch' );
645 }
646 }
647
648 // Close menu if the user clicks outside it
649 function maybeToggleMarketplaceMenu( e ) {
650 if (
651 ! marketplaceSectionDropdown.is( e.target ) &&
652 marketplaceSectionDropdown.has( e.target ).length === 0
653 ) {
654 marketplaceSectionDropdown.removeClass( 'is-open' );
655 marketplaceMenuIsOpen = false;
656 $( document ).off( 'click', maybeToggleMarketplaceMenu );
657 }
658 }
659
660 function isTouchDevice() {
661 return (
662 'ontouchstart' in window ||
663 navigator.maxTouchPoints > 0 ||
664 navigator.msMaxTouchPoints > 0
665 );
666 }
667 } );
668 } )( jQuery, woocommerce_admin );
669