From cc0714f612d0ce07432a8466b2220da60c8cf346 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 14:59:17 -0700 Subject: [PATCH 01/15] Replace Jquery.isFunction() except in 3rd party assets --- assets/js/frontend/single-product.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/frontend/single-product.js b/assets/js/frontend/single-product.js index ad1e5407a46..b93faefc3cb 100644 --- a/assets/js/frontend/single-product.js +++ b/assets/js/frontend/single-product.js @@ -101,8 +101,8 @@ jQuery( function( $ ) { $target.data( 'product_gallery', this ); // Pick functionality to initialize... - this.flexslider_enabled = $.isFunction( $.fn.flexslider ) && wc_single_product_params.flexslider_enabled; - this.zoom_enabled = $.isFunction( $.fn.zoom ) && wc_single_product_params.zoom_enabled; + this.flexslider_enabled = 'function' === typeof $.fn.flexslider && wc_single_product_params.flexslider_enabled; + this.zoom_enabled = 'function' === typeof $.fn.zoom && wc_single_product_params.zoom_enabled; this.photoswipe_enabled = typeof PhotoSwipe !== 'undefined' && wc_single_product_params.photoswipe_enabled; // ...also taking args into account. From 80a8d66106941fb567dd64a63a86bc18366f3223 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 15:00:14 -0700 Subject: [PATCH 02/15] Replace jQuery.submit() --- assets/js/admin/meta-boxes-product-variation.js | 4 ++-- assets/js/admin/wc-setup.js | 6 +++--- assets/js/frontend/woocommerce.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index dc45f7a2012..1dfc880e598 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -547,9 +547,9 @@ jQuery( function( $ ) { callerid = postForm.data( 'callerid' ); if ( 'publish' === callerid ) { - postForm.append('').submit(); + postForm.append('').trigger( 'submit' ); } else { - postForm.append('').submit(); + postForm.append('').trigger( 'submit' ); } }, diff --git a/assets/js/admin/wc-setup.js b/assets/js/admin/wc-setup.js index 1484fda1f7b..2f846e60e37 100644 --- a/assets/js/admin/wc-setup.js +++ b/assets/js/admin/wc-setup.js @@ -37,7 +37,7 @@ jQuery( function( $ ) { } ); $( document.body ).on( 'wc_backbone_modal_response', function() { - form.unbind( 'submit' ).submit(); + form.unbind( 'submit' ).trigger( 'submit' ); } ); $( '#wc_tracker_checkbox_dialog' ).on( 'change', function( e ) { @@ -46,7 +46,7 @@ jQuery( function( $ ) { } ); $( '#wc_tracker_submit' ).on( 'click', function () { - form.unbind( 'submit' ).submit(); + form.unbind( 'submit' ).trigger( 'submit' ); } ); return true; @@ -182,7 +182,7 @@ jQuery( function( $ ) { } ); function submitActivateForm() { - $( 'form.activate-jetpack' ).submit(); + $( 'form.activate-jetpack' ).trigger( 'submit' ); } function waitForJetpackInstall() { diff --git a/assets/js/frontend/woocommerce.js b/assets/js/frontend/woocommerce.js index f09329fe6a4..169ac858226 100644 --- a/assets/js/frontend/woocommerce.js +++ b/assets/js/frontend/woocommerce.js @@ -2,7 +2,7 @@ jQuery( function( $ ) { // Orderby $( '.woocommerce-ordering' ).on( 'change', 'select.orderby', function() { - $( this ).closest( 'form' ).submit(); + $( this ).closest( 'form' ).trigger( 'submit' ); }); // Target quantity inputs on product pages From a67def78de3eb2aef694043f4f5fdb144270ae6a Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 15:00:55 -0700 Subject: [PATCH 03/15] Replace jQuery.click() --- assets/js/admin/meta-boxes-order.js | 4 ++-- assets/js/admin/meta-boxes-product-variation.js | 2 +- assets/js/admin/meta-boxes-product.js | 4 ++-- assets/js/admin/meta-boxes.js | 2 +- assets/js/admin/wc-setup.js | 2 +- assets/js/frontend/add-payment-method.js | 2 +- assets/js/frontend/single-product.js | 10 +++++----- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index dc5ccf52890..5973cc6a87f 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -158,7 +158,7 @@ jQuery( function ( $ ) { change_customer_user: function() { if ( ! $( '#_billing_country' ).val() ) { - $( 'a.edit_address' ).click(); + $( 'a.edit_address' ).trigger( 'click' ); wc_meta_boxes_order.load_billing( true ); wc_meta_boxes_order.load_shipping( true ); } @@ -643,7 +643,7 @@ jQuery( function ( $ ) { $( this ).closest( 'tr' ).find( '.view' ).hide(); $( this ).closest( 'tr' ).find( '.edit' ).show(); $( this ).hide(); - $( 'button.add-line-item' ).click(); + $( 'button.add-line-item' ).trigger( 'click' ); $( 'button.cancel-action' ).attr( 'data-reload', true ); window.wcTracks.recordEvent( 'order_edit_edit_item_click', { order_id: woocommerce_admin_meta_boxes.post_id, diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 1dfc880e598..9329e1fb41e 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -104,7 +104,7 @@ jQuery( function( $ ) { date_to = $( '.sale_price_dates_to', $el ).val(); if ( '' !== date_from || '' !== date_to ) { - $( 'a.sale_schedule', $el ).click(); + $( 'a.sale_schedule', $el ).trigger( 'click' ); } }); diff --git a/assets/js/admin/meta-boxes-product.js b/assets/js/admin/meta-boxes-product.js index f124a581224..3c48ef6770e 100644 --- a/assets/js/admin/meta-boxes-product.js +++ b/assets/js/admin/meta-boxes-product.js @@ -113,7 +113,7 @@ jQuery( function( $ ) { show_and_hide_panels(); - $( 'ul.wc-tabs li:visible' ).eq( 0 ).find( 'a' ).click(); + $( 'ul.wc-tabs li:visible' ).eq( 0 ).find( 'a' ).trigger( 'click' ); $( document.body ).trigger( 'woocommerce-product-type-change', select_val, $( this ) ); @@ -335,7 +335,7 @@ jQuery( function( $ ) { attribute_row_indexes(); - $attributes.find( '.woocommerce_attribute' ).last().find( 'h3' ).click(); + $attributes.find( '.woocommerce_attribute' ).last().find( 'h3' ).trigger( 'click' ); $wrapper.unblock(); diff --git a/assets/js/admin/meta-boxes.js b/assets/js/admin/meta-boxes.js index ccc9d87648c..1f82968994f 100644 --- a/assets/js/admin/meta-boxes.js +++ b/assets/js/admin/meta-boxes.js @@ -32,7 +32,7 @@ jQuery( function ( $ ) { $( $( this ).attr( 'href' ) ).show(); }); $( 'div.panel-wrap' ).each( function() { - $( this ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' ).click(); + $( this ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' ).trigger( 'click' ); }); }).trigger( 'wc-init-tabbed-panels' ); diff --git a/assets/js/admin/wc-setup.js b/assets/js/admin/wc-setup.js index 2f846e60e37..1a0f9b0b3e4 100644 --- a/assets/js/admin/wc-setup.js +++ b/assets/js/admin/wc-setup.js @@ -121,7 +121,7 @@ jQuery( function( $ ) { $focused = $( document.activeElement ); if ( $focused.is( '.wc-wizard-service-toggle, .wc-wizard-service-enable' ) && ( 13 === code || 32 === code ) ) { - $focused.find( ':input' ).click(); + $focused.find( ':input' ).trigger( 'click' ); } } ); diff --git a/assets/js/frontend/add-payment-method.js b/assets/js/frontend/add-payment-method.js index 1642155a77a..d824ce86a39 100644 --- a/assets/js/frontend/add-payment-method.js +++ b/assets/js/frontend/add-payment-method.js @@ -24,7 +24,7 @@ jQuery( function( $ ) { }) // Trigger initial click - .find( 'input[name=payment_method]:checked' ).click(); + .find( 'input[name=payment_method]:checked' ).trigger( 'click' ); $( '#add_payment_method' ).submit( function() { $( '#add_payment_method' ).block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); diff --git a/assets/js/frontend/single-product.js b/assets/js/frontend/single-product.js index b93faefc3cb..fee12d826d8 100644 --- a/assets/js/frontend/single-product.js +++ b/assets/js/frontend/single-product.js @@ -16,13 +16,13 @@ jQuery( function( $ ) { var $tabs = $( this ).find( '.wc-tabs, ul.tabs' ).first(); if ( hash.toLowerCase().indexOf( 'comment-' ) >= 0 || hash === '#reviews' || hash === '#tab-reviews' ) { - $tabs.find( 'li.reviews_tab a' ).click(); + $tabs.find( 'li.reviews_tab a' ).trigger( 'click' ); } else if ( url.indexOf( 'comment-page-' ) > 0 || url.indexOf( 'cpage=' ) > 0 ) { - $tabs.find( 'li.reviews_tab a' ).click(); + $tabs.find( 'li.reviews_tab a' ).trigger( 'click' ); } else if ( hash === '#tab-additional_information' ) { - $tabs.find( 'li.additional_information_tab a' ).click(); + $tabs.find( 'li.additional_information_tab a' ).trigger( 'click' ); } else { - $tabs.find( 'li:first a' ).click(); + $tabs.find( 'li:first a' ).trigger( 'click' ); } } ) .on( 'click', '.wc-tabs li a, ul.tabs li a', function( e ) { @@ -39,7 +39,7 @@ jQuery( function( $ ) { } ) // Review link .on( 'click', 'a.woocommerce-review-link', function() { - $( '.reviews_tab a' ).click(); + $( '.reviews_tab a' ).trigger( 'click' ); return true; } ) // Star ratings for comments From 61c4e20863ec1dfce21b1c8d0596314a36708371 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 15:04:26 -0700 Subject: [PATCH 04/15] replace jQuery..bind except in 3rd party assets --- .../js/admin/meta-boxes-product-variation.js | 2 +- assets/js/admin/meta-boxes-product.js | 2 +- assets/js/admin/reports.js | 2 +- assets/js/admin/wc-product-export.js | 2 +- assets/js/admin/wc-product-import.js | 2 +- assets/js/admin/wc-setup.js | 2 +- assets/js/admin/woocommerce_admin.js | 2 +- assets/js/frontend/add-to-cart-variation.js | 8 +++--- assets/js/frontend/add-to-cart.js | 4 +-- assets/js/frontend/address-i18n.js | 2 +- assets/js/frontend/cart-fragments.js | 2 +- assets/js/frontend/cart.js | 26 +++++++++---------- assets/js/frontend/checkout.js | 4 +-- assets/js/frontend/country-select.js | 2 +- assets/js/frontend/single-product.js | 14 +++++----- assets/js/frontend/tokenization-form.js | 10 +++---- 16 files changed, 43 insertions(+), 43 deletions(-) diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 9329e1fb41e..66966d3c629 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -346,7 +346,7 @@ jQuery( function( $ ) { postForm.on( 'submit', this.save_on_submit ); - $( 'input:submit', postForm ).bind( 'click keypress', function() { + $( 'input:submit', postForm ).on( 'click keypress', function() { postForm.data( 'callerid', this.id ); }); diff --git a/assets/js/admin/meta-boxes-product.js b/assets/js/admin/meta-boxes-product.js index 3c48ef6770e..ee696e527cd 100644 --- a/assets/js/admin/meta-boxes-product.js +++ b/assets/js/admin/meta-boxes-product.js @@ -20,7 +20,7 @@ jQuery( function( $ ) { }); // Prevent enter submitting post form. - $( '#upsell_product_data' ).bind( 'keypress', function( e ) { + $( '#upsell_product_data' ).on( 'keypress', function( e ) { if ( e.keyCode === 13 ) { return false; } diff --git a/assets/js/admin/reports.js b/assets/js/admin/reports.js index 34ec4ff2be6..8f3857aef01 100644 --- a/assets/js/admin/reports.js +++ b/assets/js/admin/reports.js @@ -10,7 +10,7 @@ jQuery(function( $ ) { var prev_data_index = null; var prev_series_index = null; - $( '.chart-placeholder' ).bind( 'plothover', function ( event, pos, item ) { + $( '.chart-placeholder' ).on( 'plothover', function ( event, pos, item ) { if ( item ) { if ( prev_data_index !== item.dataIndex || prev_series_index !== item.seriesIndex ) { prev_data_index = item.dataIndex; diff --git a/assets/js/admin/wc-product-export.js b/assets/js/admin/wc-product-export.js index 8e2dc3546e5..b33ad76d56a 100644 --- a/assets/js/admin/wc-product-export.js +++ b/assets/js/admin/wc-product-export.js @@ -11,7 +11,7 @@ this.$form.find('.woocommerce-exporter-progress').val( 0 ); // Methods. - this.processStep = this.processStep.bind( this ); + this.processStep = this.processStep.on( this ); // Events. $form.on( 'submit', { productExportForm: this }, this.onSubmit ); diff --git a/assets/js/admin/wc-product-import.js b/assets/js/admin/wc-product-import.js index 645f11b5912..5222ac4c13f 100644 --- a/assets/js/admin/wc-product-import.js +++ b/assets/js/admin/wc-product-import.js @@ -23,7 +23,7 @@ // Initial state. this.$form.find('.woocommerce-importer-progress').val( 0 ); - this.run_import = this.run_import.bind( this ); + this.run_import = this.run_import.on( this ); // Start importing. this.run_import(); diff --git a/assets/js/admin/wc-setup.js b/assets/js/admin/wc-setup.js index 1a0f9b0b3e4..fffe5168a0f 100644 --- a/assets/js/admin/wc-setup.js +++ b/assets/js/admin/wc-setup.js @@ -252,7 +252,7 @@ jQuery( function( $ ) { bySlug[ slug ].find( 'a' ) .on( 'mouseenter mouseleave', ( function( $hover, event ) { $hover.toggleClass( 'plugin-install-source', 'mouseenter' === event.type ); - } ).bind( null, hover ? $el.closest( hover ) : $el ) ); + } ).on( null, hover ? $el.closest( hover ) : $el ) ); } } diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index e023ab8ef08..7932d1ea430 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -250,7 +250,7 @@ var shifted = false; var hasFocus = false; - $( document.body ).bind( 'keyup keydown', function( e ) { + $( document.body ).on( 'keyup keydown', function( e ) { shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey; }); diff --git a/assets/js/frontend/add-to-cart-variation.js b/assets/js/frontend/add-to-cart-variation.js index 2dd3c209945..dacd3185a85 100644 --- a/assets/js/frontend/add-to-cart-variation.js +++ b/assets/js/frontend/add-to-cart-variation.js @@ -22,10 +22,10 @@ self.$form.off( '.wc-variation-form' ); // Methods. - self.getChosenAttributes = self.getChosenAttributes.bind( self ); - self.findMatchingVariations = self.findMatchingVariations.bind( self ); - self.isMatch = self.isMatch.bind( self ); - self.toggleResetLink = self.toggleResetLink.bind( self ); + self.getChosenAttributes = self.getChosenAttributes.on( self ); + self.findMatchingVariations = self.findMatchingVariations.on( self ); + self.isMatch = self.isMatch.on( self ); + self.toggleResetLink = self.toggleResetLink.on( self ); // Events. $form.on( 'click.wc-variation-form', '.reset_variations', { variationForm: self }, self.onReset ); diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index e27baf072a4..d97cb7746e4 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -10,8 +10,8 @@ jQuery( function( $ ) { */ var AddToCartHandler = function() { this.requests = []; - this.addRequest = this.addRequest.bind( this ); - this.run = this.run.bind( this ); + this.addRequest = this.addRequest.on( this ); + this.run = this.run.on( this ); $( document.body ) .on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart ) diff --git a/assets/js/frontend/address-i18n.js b/assets/js/frontend/address-i18n.js index b66c0adae30..f71dd266e3b 100644 --- a/assets/js/frontend/address-i18n.js +++ b/assets/js/frontend/address-i18n.js @@ -32,7 +32,7 @@ jQuery( function( $ ) { // Handle locale $( document.body ) - .bind( 'country_to_state_changing', function( event, country, wrapper ) { + .on( 'country_to_state_changing', function( event, country, wrapper ) { var thisform = wrapper, thislocale; if ( typeof locale[ country ] !== 'undefined' ) { diff --git a/assets/js/frontend/cart-fragments.js b/assets/js/frontend/cart-fragments.js index c5eef7b4c72..e70ad4ad36c 100644 --- a/assets/js/frontend/cart-fragments.js +++ b/assets/js/frontend/cart-fragments.js @@ -180,7 +180,7 @@ jQuery( function( $ ) { wp.customize.widgetsPreview.WidgetPartial ); if ( hasSelectiveRefresh ) { - wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() { + wp.customize.selectiveRefresh.on( 'partial-content-rendered', function() { refresh_cart_fragment(); } ); } diff --git a/assets/js/frontend/cart.js b/assets/js/frontend/cart.js index 622c8eb1437..d2a8b55f0b8 100644 --- a/assets/js/frontend/cart.js +++ b/assets/js/frontend/cart.js @@ -152,9 +152,9 @@ jQuery( function( $ ) { */ init: function( cart ) { this.cart = cart; - this.toggle_shipping = this.toggle_shipping.bind( this ); - this.shipping_method_selected = this.shipping_method_selected.bind( this ); - this.shipping_calculator_submit = this.shipping_calculator_submit.bind( this ); + this.toggle_shipping = this.toggle_shipping.on( this ); + this.shipping_method_selected = this.shipping_method_selected.on( this ); + this.shipping_calculator_submit = this.shipping_calculator_submit.on( this ); $( document ).on( 'click', @@ -261,16 +261,16 @@ jQuery( function( $ ) { * Initialize cart UI events. */ init: function() { - this.update_cart_totals = this.update_cart_totals.bind( this ); - this.input_keypress = this.input_keypress.bind( this ); - this.cart_submit = this.cart_submit.bind( this ); - this.submit_click = this.submit_click.bind( this ); - this.apply_coupon = this.apply_coupon.bind( this ); - this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this ); - this.quantity_update = this.quantity_update.bind( this ); - this.item_remove_clicked = this.item_remove_clicked.bind( this ); - this.item_restore_clicked = this.item_restore_clicked.bind( this ); - this.update_cart = this.update_cart.bind( this ); + this.update_cart_totals = this.update_cart_totals.on( this ); + this.input_keypress = this.input_keypress.on( this ); + this.cart_submit = this.cart_submit.on( this ); + this.submit_click = this.submit_click.on( this ); + this.apply_coupon = this.apply_coupon.on( this ); + this.remove_coupon_clicked = this.remove_coupon_clicked.on( this ); + this.quantity_update = this.quantity_update.on( this ); + this.item_remove_clicked = this.item_remove_clicked.on( this ); + this.item_restore_clicked = this.item_restore_clicked.on( this ); + this.update_cart = this.update_cart.on( this ); $( document ).on( 'wc_update_cart added_to_cart', diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index 56ebd18a917..1918eb37dad 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -16,8 +16,8 @@ jQuery( function( $ ) { $order_review: $( '#order_review' ), $checkout_form: $( 'form.checkout' ), init: function() { - $( document.body ).bind( 'update_checkout', this.update_checkout ); - $( document.body ).bind( 'init_checkout', this.init_checkout ); + $( document.body ).on( 'update_checkout', this.update_checkout ); + $( document.body ).on( 'init_checkout', this.init_checkout ); // Payment methods this.$checkout_form.on( 'click', 'input[name="payment_method"]', this.payment_method_selected ); diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index eec0c962da3..e44a55947b2 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -70,7 +70,7 @@ jQuery( function( $ ) { wc_country_select_select2(); - $( document.body ).bind( 'country_to_state_changed', function() { + $( document.body ).on( 'country_to_state_changed', function() { wc_country_select_select2(); }); } diff --git a/assets/js/frontend/single-product.js b/assets/js/frontend/single-product.js index fee12d826d8..852f68c84fe 100644 --- a/assets/js/frontend/single-product.js +++ b/assets/js/frontend/single-product.js @@ -118,13 +118,13 @@ jQuery( function( $ ) { } // Bind functions to this. - this.initFlexslider = this.initFlexslider.bind( this ); - this.initZoom = this.initZoom.bind( this ); - this.initZoomForTarget = this.initZoomForTarget.bind( this ); - this.initPhotoswipe = this.initPhotoswipe.bind( this ); - this.onResetSlidePosition = this.onResetSlidePosition.bind( this ); - this.getGalleryItems = this.getGalleryItems.bind( this ); - this.openPhotoswipe = this.openPhotoswipe.bind( this ); + this.initFlexslider = this.initFlexslider.on( this ); + this.initZoom = this.initZoom.on( this ); + this.initZoomForTarget = this.initZoomForTarget.on( this ); + this.initPhotoswipe = this.initPhotoswipe.on( this ); + this.onResetSlidePosition = this.onResetSlidePosition.on( this ); + this.getGalleryItems = this.getGalleryItems.on( this ); + this.openPhotoswipe = this.openPhotoswipe.on( this ); if ( this.flexslider_enabled ) { this.initFlexslider( args.flexslider ); diff --git a/assets/js/frontend/tokenization-form.js b/assets/js/frontend/tokenization-form.js index 3a5a8bffbad..9fde864d1c1 100644 --- a/assets/js/frontend/tokenization-form.js +++ b/assets/js/frontend/tokenization-form.js @@ -15,11 +15,11 @@ jQuery( function( $ ) { }, wc_tokenization_form_params ); // Bind functions to this. - this.onDisplay = this.onDisplay.bind( this ); - this.hideForm = this.hideForm.bind( this ); - this.showForm = this.showForm.bind( this ); - this.showSaveNewCheckbox = this.showSaveNewCheckbox.bind( this ); - this.hideSaveNewCheckbox = this.hideSaveNewCheckbox.bind( this ); + this.onDisplay = this.onDisplay.on( this ); + this.hideForm = this.hideForm.on( this ); + this.showForm = this.showForm.on( this ); + this.showSaveNewCheckbox = this.showSaveNewCheckbox.on( this ); + this.hideSaveNewCheckbox = this.hideSaveNewCheckbox.on( this ); // When a radio button is changed, make sure to show/hide our new CC info area. this.$target.on( From 0ccff4dda56397af993b4932990dc72e9b28171c Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 15:06:18 -0700 Subject: [PATCH 05/15] Repalce jQuery.focus() except in 3rd party assets --- assets/js/admin/api-keys.js | 6 +++--- assets/js/admin/backbone-modal.js | 2 +- assets/js/admin/meta-boxes-coupon.js | 2 +- assets/js/admin/meta-boxes-order.js | 4 ++-- assets/js/admin/settings.js | 4 ++-- assets/js/admin/system-status.js | 6 +++--- assets/js/admin/woocommerce_admin.js | 2 +- assets/js/frontend/checkout.js | 2 +- assets/js/frontend/country-select.js | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/assets/js/admin/api-keys.js b/assets/js/admin/api-keys.js index 4a5c0dd7ceb..035cd7e5675 100644 --- a/assets/js/admin/api-keys.js +++ b/assets/js/admin/api-keys.js @@ -53,7 +53,7 @@ .on( 'click', css_class, function( evt ) { evt.preventDefault(); if ( ! document.queryCommandSupported( 'copy' ) ) { - $( css_class ).parent().find( 'input' ).focus().select(); + $( css_class ).parent().find( 'input' ).trigger( 'focus' ).select(); $( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed ); } else { $( '#copy-error' ).text( '' ); @@ -69,10 +69,10 @@ 'fadeIn': 50, 'fadeOut': 50, 'delay': 0 - } ).focus(); + } ).trigger( 'focus' ); } ) .on( 'aftercopyerror', css_class, function() { - $( css_class ).parent().find( 'input' ).focus().select(); + $( css_class ).parent().find( 'input' ).trigger( 'focus' ).select(); $( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed ); } ); }, diff --git a/assets/js/admin/backbone-modal.js b/assets/js/admin/backbone-modal.js index 63cca56422a..c1d92c4dab9 100644 --- a/assets/js/admin/backbone-modal.js +++ b/assets/js/admin/backbone-modal.js @@ -88,7 +88,7 @@ }).append( this.$el ); this.resizeContent(); - this.$( '.wc-backbone-modal-content' ).attr( 'tabindex' , '0' ).focus(); + this.$( '.wc-backbone-modal-content' ).attr( 'tabindex' , '0' ).trigger( 'focus' ); $( document.body ).trigger( 'init_tooltips' ); diff --git a/assets/js/admin/meta-boxes-coupon.js b/assets/js/admin/meta-boxes-coupon.js index 9fc82fd8bef..be7263a1d07 100644 --- a/assets/js/admin/meta-boxes-coupon.js +++ b/assets/js/admin/meta-boxes-coupon.js @@ -61,7 +61,7 @@ jQuery(function( $ ) { ); } $result = woocommerce_admin_meta_boxes_coupon.prefix + $result + woocommerce_admin_meta_boxes_coupon.suffix; - $coupon_code_field.focus().val( $result ); + $coupon_code_field.trigger( 'focus' ).val( $result ); $coupon_code_label.addClass( 'screen-reader-text' ); } }; diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 5973cc6a87f..3e11bcb1476 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -1470,7 +1470,7 @@ jQuery( function ( $ ) { 'fadeIn': 50, 'fadeOut': 50, 'delay': 0 - }).focus(); + }).trigger( 'focus' ); }, /** @@ -1483,7 +1483,7 @@ jQuery( function ( $ ) { 'fadeIn': 50, 'fadeOut': 50, 'delay': 0 - }).focus(); + }).trigger( 'focus' ); } }; diff --git a/assets/js/admin/settings.js b/assets/js/admin/settings.js index 88a924b8384..8665d52e20f 100644 --- a/assets/js/admin/settings.js +++ b/assets/js/admin/settings.js @@ -126,7 +126,7 @@ var moveBtn = $( this ), $row = moveBtn.closest( 'tr' ); - moveBtn.focus(); + moveBtn.trigger( 'focus' ); var isMoveUp = moveBtn.is( '.wc-move-up' ), isMoveDown = moveBtn.is( '.wc-move-down' ); @@ -147,7 +147,7 @@ } } - moveBtn.focus(); // Re-focus after the container was moved. + moveBtn.trigger( 'focus' ); // Re-focus after the container was moved. moveBtn.closest( 'table' ).trigger( 'updateMoveButtons' ); } ); diff --git a/assets/js/admin/system-status.js b/assets/js/admin/system-status.js index 9f066410b17..e3873958f33 100644 --- a/assets/js/admin/system-status.js +++ b/assets/js/admin/system-status.js @@ -68,7 +68,7 @@ jQuery( function ( $ ) { try { $( '#debug-report' ).slideDown(); - $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).focus().select(); + $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).select(); $( this ).fadeOut(); return false; } catch ( e ) { @@ -100,7 +100,7 @@ jQuery( function ( $ ) { 'fadeIn': 50, 'fadeOut': 50, 'delay': 0 - }).focus(); + }).trigger( 'focus' ); }, /** @@ -108,7 +108,7 @@ jQuery( function ( $ ) { */ copyFail: function() { $( '.copy-error' ).removeClass( 'hidden' ); - $( '#debug-report' ).find( 'textarea' ).focus().select(); + $( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).select(); } }; diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index 7932d1ea430..67df55711a9 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -232,7 +232,7 @@ }); // Focus on inputs within the table if clicked instead of trying to sort. $( '.wc_input_table.sortable tbody input' ).on( 'click', function() { - $( this ).focus(); + $( this ).trigger( 'focus' ); } ); $( '.wc_input_table .remove_rows' ).on( 'click', function() { diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index 1918eb37dad..90e05c913fc 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -582,7 +582,7 @@ jQuery( function( $ ) { }, show_coupon_form: function() { $( '.checkout_coupon' ).slideToggle( 400, function() { - $( '.checkout_coupon' ).find( ':input:eq(0)' ).focus(); + $( '.checkout_coupon' ).find( ':input:eq(0)' ).trigger( 'focus' ); }); return false; }, diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index e44a55947b2..20ab4a64c66 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -62,7 +62,7 @@ jQuery( function( $ ) { $( this ) .on( 'select2:select', function() { - $( this ).focus(); // Maintain focus after select https://github.com/select2/select2/issues/4384 + $( this ).trigger( 'focus' ); // Maintain focus after select https://github.com/select2/select2/issues/4384 } ) .selectWoo( select2_args ); }); From adb2c6b86e3bc87c2f518b8cfd207f8f7ec4beb7 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Thu, 7 Jan 2021 15:07:02 -0700 Subject: [PATCH 06/15] Replace jQuery.select() --- assets/js/admin/api-keys.js | 4 ++-- assets/js/admin/system-status.js | 4 ++-- assets/js/admin/wc-clipboard.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/js/admin/api-keys.js b/assets/js/admin/api-keys.js index 035cd7e5675..6ac852ff214 100644 --- a/assets/js/admin/api-keys.js +++ b/assets/js/admin/api-keys.js @@ -53,7 +53,7 @@ .on( 'click', css_class, function( evt ) { evt.preventDefault(); if ( ! document.queryCommandSupported( 'copy' ) ) { - $( css_class ).parent().find( 'input' ).trigger( 'focus' ).select(); + $( css_class ).parent().find( 'input' ).trigger( 'focus' ).trigger( 'select' ); $( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed ); } else { $( '#copy-error' ).text( '' ); @@ -72,7 +72,7 @@ } ).trigger( 'focus' ); } ) .on( 'aftercopyerror', css_class, function() { - $( css_class ).parent().find( 'input' ).trigger( 'focus' ).select(); + $( css_class ).parent().find( 'input' ).trigger( 'focus' ).trigger( 'select' ); $( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed ); } ); }, diff --git a/assets/js/admin/system-status.js b/assets/js/admin/system-status.js index e3873958f33..317625898c1 100644 --- a/assets/js/admin/system-status.js +++ b/assets/js/admin/system-status.js @@ -68,7 +68,7 @@ jQuery( function ( $ ) { try { $( '#debug-report' ).slideDown(); - $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).select(); + $( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).trigger( 'select' ); $( this ).fadeOut(); return false; } catch ( e ) { @@ -108,7 +108,7 @@ jQuery( function ( $ ) { */ copyFail: function() { $( '.copy-error' ).removeClass( 'hidden' ); - $( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).select(); + $( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' ); } }; diff --git a/assets/js/admin/wc-clipboard.js b/assets/js/admin/wc-clipboard.js index fc009d02041..8a2391213ae 100644 --- a/assets/js/admin/wc-clipboard.js +++ b/assets/js/admin/wc-clipboard.js @@ -17,7 +17,7 @@ function wcSetClipboard( data, $el ) { } var $temp_input = jQuery( '