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