Skip to content

Commit

Permalink
External Libraries: Further fix jQuery deprecations in WordPress core.
Browse files Browse the repository at this point in the history
This includes many minor adjustments to a wide array of core files to replace shorthands with full declarations.

Follow-up to [50001], [50270], [50367].

Props Clorith, hellofromTonya, peterwilsoncc, adamsilverstein, aristath.
See #51812.

git-svn-id: https://develop.svn.wordpress.org/trunk@50420 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Feb 23, 2021
1 parent 0a2ba7c commit 6975104
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 130 deletions.
8 changes: 4 additions & 4 deletions src/js/_enqueues/admin/auth-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
rejectUrl: authApp.reject
};

$approveBtn.click( function( e ) {
$approveBtn.on( 'click', function( e ) {
var name = $appNameField.val(),
appId = $( 'input[name="app_id"]', $form ).val();

Expand All @@ -26,7 +26,7 @@
}

if ( 0 === name.length ) {
$appNameField.focus();
$appNameField.trigger( 'focus' );
return;
}

Expand Down Expand Up @@ -102,7 +102,7 @@
$( 'input', $notice ).val( response.password );

$form.replaceWith( $notice );
$notice.focus();
$notice.trigger( 'focus' );
}
} ).fail( function( jqXHR, textStatus, errorThrown ) {
var errorMessage = errorThrown,
Expand Down Expand Up @@ -140,7 +140,7 @@
} );
} );

$rejectBtn.click( function( e ) {
$rejectBtn.on( 'click', function( e ) {
e.preventDefault();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/_enqueues/admin/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ $document.ready( function() {
* @return {void}
*/
$adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
$(e.target).parent().siblings('a').get(0).click();
$(e.target).parent().siblings('a').get(0).trigger( 'click' );
});

/**
Expand Down
10 changes: 5 additions & 5 deletions src/js/_enqueues/admin/custom-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @return {void}
*/
$( 'select[name="background-size"]' ).change( function() {
$( 'select[name="background-size"]' ).on( 'change', function() {
bgImage.css( 'background-size', $( this ).val() );
});

Expand All @@ -50,7 +50,7 @@
*
* @return {void}
*/
$( 'input[name="background-position"]' ).change( function() {
$( 'input[name="background-position"]' ).on( 'change', function() {
bgImage.css( 'background-position', $( this ).val() );
});

Expand All @@ -61,7 +61,7 @@
*
* @return {void}
*/
$( 'input[name="background-repeat"]' ).change( function() {
$( 'input[name="background-repeat"]' ).on( 'change', function() {
bgImage.css( 'background-repeat', $( this ).is( ':checked' ) ? 'repeat' : 'no-repeat' );
});

Expand All @@ -72,7 +72,7 @@
*
* @return {void}
*/
$( 'input[name="background-attachment"]' ).change( function() {
$( 'input[name="background-attachment"]' ).on( 'change', function() {
bgImage.css( 'background-attachment', $( this ).is( ':checked' ) ? 'scroll' : 'fixed' );
});

Expand All @@ -83,7 +83,7 @@
*
* @return {void}
*/
$('#choose-from-library-link').click( function( event ) {
$('#choose-from-library-link').on( 'click', function( event ) {
var $el = $(this);

event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/js/_enqueues/admin/custom-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @return {void}
*/
$('#choose-from-library-link').click( function( event ) {
$('#choose-from-library-link').on( 'click', function( event ) {
var $el = $(this);
event.preventDefault();

Expand Down
4 changes: 2 additions & 2 deletions src/js/_enqueues/admin/edit-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ window.commentReply = {
*/
toggle : function(el) {
if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( __( 'Are you sure you want to edit this comment?\nThe changes you made will be lost.' ) ) ) ) {
$( el ).find( 'button.vim-q' ).click();
$( el ).find( 'button.vim-q' ).trigger( 'click' );
}
},

Expand Down Expand Up @@ -1298,7 +1298,7 @@ $(document).ready(function(){
return function() {
var scope = $('select[name="action"]');
$('option[value="' + value + '"]', scope).prop('selected', true);
$('#doaction').click();
$('#doaction').trigger( 'click' );
};
};

Expand Down
24 changes: 12 additions & 12 deletions src/js/_enqueues/admin/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jQuery(document).ready( function($) {

var newCat, noSyncChecks = false, syncChecks, catAddAfter;

$('#link_name').focus();
$('#link_name').trigger( 'focus' );
// Postboxes.
postboxes.add_postbox_toggles('link');

Expand All @@ -19,7 +19,7 @@ jQuery(document).ready( function($) {
*
* @return {boolean} Always returns false to prevent the default behavior.
*/
$('#category-tabs a').click(function(){
$('#category-tabs a').on( 'click', function(){
var t = $(this).attr('href');
$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
$('.tabs-panel').hide();
Expand All @@ -31,7 +31,7 @@ jQuery(document).ready( function($) {
return false;
});
if ( getUserSetting('cats') )
$('#category-tabs a[href="#categories-pop"]').click();
$('#category-tabs a[href="#categories-pop"]').trigger( 'click' );

// Ajax Cat.
newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
Expand All @@ -41,7 +41,7 @@ jQuery(document).ready( function($) {
*
* @return {void}
*/
$('#link-category-add-submit').click( function() { newCat.focus(); } );
$('#link-category-add-submit').on( 'click', function() { newCat.focus(); } );

/**
* Synchronize category checkboxes.
Expand Down Expand Up @@ -82,7 +82,7 @@ jQuery(document).ready( function($) {
var t = $($(this).text());
t.find( 'label' ).each( function() {
var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o;
$('#' + id).change( syncChecks );
$('#' + id).on( 'change', syncChecks );
o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
} );
} );
Expand All @@ -108,13 +108,13 @@ jQuery(document).ready( function($) {
} );

// All categories is the default tab, so we delete the user setting.
$('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
$('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');});

// Set a preference for the popular categories to cookies.
$('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
$('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');});

if ( 'pop' == getUserSetting('cats') )
$('a[href="#categories-pop"]').click();
$('a[href="#categories-pop"]').trigger( 'click' );

/**
* Adds event handler that shows the interface controls to add a new category.
Expand All @@ -125,12 +125,12 @@ jQuery(document).ready( function($) {
* @return {boolean} Always returns false to prevent regular link
* functionality.
*/
$('#category-add-toggle').click( function() {
$('#category-add-toggle').on( 'click', function() {
$(this).parents('div:first').toggleClass( 'wp-hidden-children' );
$('#category-tabs a[href="#categories-all"]').click();
$('#newcategory').focus();
$('#category-tabs a[href="#categories-all"]').trigger( 'click' );
$('#newcategory').trigger( 'focus' );
return false;
} );

$('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' );
});
2 changes: 1 addition & 1 deletion src/js/_enqueues/admin/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
$( '#find-posts' ).show();

// Close the dialog when the escape key is pressed.
$('#find-posts-input').focus().keyup( function( event ){
$('#find-posts-input').trigger( 'focus' ).on( 'keyup', function( event ){
if ( event.which == 27 ) {
findPosts.close();
}
Expand Down
8 changes: 4 additions & 4 deletions src/js/_enqueues/admin/plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jQuery( document ).ready( function( $ ) {
.on( 'thickbox:removed', function() {
// Set focus back to the element that opened the modal dialog.
// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
$focusedBefore.focus();
$focusedBefore.trigger( 'focus' );
});

function iframeLoaded() {
Expand All @@ -88,7 +88,7 @@ jQuery( document ).ready( function( $ ) {
handleTabbables();

// Set initial focus on the "Close" button.
$firstTabbable.focus();
$firstTabbable.trigger( 'focus' );

/*
* When the "Install" button is disabled (e.g. the Plugin is already installed)
Expand Down Expand Up @@ -141,10 +141,10 @@ jQuery( document ).ready( function( $ ) {

if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
event.preventDefault();
$firstTabbable.focus();
$firstTabbable.trigger( 'focus' );
} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
event.preventDefault();
$lastTabbable.focus();
$lastTabbable.trigger( 'focus' );
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/js/_enqueues/admin/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ window.wp = window.wp || {};
$('#the-comment-list').append( r.responses[0].data );

theList = theExtraList = null;
$( 'a[className*=\':\']' ).unbind();
$( 'a[className*=\':\']' ).off();

// If the offset is over the total number of comments we cannot fetch any more, so hide the button.
if ( commentsBox.st > commentsBox.total )
Expand Down Expand Up @@ -414,7 +414,7 @@ jQuery(document).ready( function($) {
}

$previewField.val('dopreview');
$form.attr( 'target', target ).submit().attr( 'target', '' );
$form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' );

// Workaround for WebKit bug preventing a form submitting twice to the same action.
// https://bugs.webkit.org/show_bug.cgi?id=28633
Expand Down Expand Up @@ -448,7 +448,7 @@ jQuery(document).ready( function($) {

// Auto save new posts after a title is typed.
if ( $( '#auto_draft' ).val() ) {
$( '#title' ).blur( function() {
$( '#title' ).on( 'blur', function() {
var cancel;

if ( ! this.value || $('#edit-slug-box > *').length ) {
Expand Down Expand Up @@ -592,18 +592,18 @@ jQuery(document).ready( function($) {
});

if ( getUserSetting( settingName ) )
$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' );

// Add category button controls.
$('#new' + taxonomy).one( 'focus', function() {
$( this ).val( '' ).removeClass( 'form-input-tip' );
});

// On [Enter] submit the taxonomy.
$('#new' + taxonomy).keypress( function(event){
$('#new' + taxonomy).on( 'keypress', function(event){
if( 13 === event.keyCode ) {
event.preventDefault();
$('#' + taxonomy + '-add-submit').click();
$('#' + taxonomy + '-add-submit').trigger( 'click' );
}
});

Expand Down Expand Up @@ -1001,7 +1001,7 @@ jQuery(document).ready( function($) {
var new_slug = $el.children( 'input' ).val();

if ( new_slug == $('#editable-post-name-full').text() ) {
buttons.children('.cancel').click();
buttons.children('.cancel').trigger( 'click' );
return;
}

Expand Down Expand Up @@ -1054,11 +1054,11 @@ jQuery(document).ready( function($) {
// On [Enter], just save the new slug, don't save the post.
if ( 13 === key ) {
e.preventDefault();
buttons.children( '.save' ).click();
buttons.children( '.save' ).trigger( 'click' );
}
// On [Esc] cancel the editing.
if ( 27 === key ) {
buttons.children( '.cancel' ).click();
buttons.children( '.cancel' ).trigger( 'click' );
}
} ).on( 'keyup', function() {
real_slug.val( this.value );
Expand Down Expand Up @@ -1177,7 +1177,7 @@ jQuery(document).ready( function($) {
} else {
mce = false;
offset = $textarea.height() - event.pageY;
$textarea.blur();
$textarea.trigger( 'blur' );
}

$document.on( 'mousemove.wp-editor-resize', dragging )
Expand Down Expand Up @@ -1261,7 +1261,7 @@ jQuery(document).ready( function($) {
// Clear the selection and move focus back to the trigger.
event.clearSelection();
// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
triggerElement.focus();
triggerElement.trigger( 'focus' );

// Show success visual feedback.
clearTimeout( copyAttachmentURLSuccessTimeout );
Expand Down
4 changes: 2 additions & 2 deletions src/js/_enqueues/admin/postbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
}

postbox.prevAll( '.postbox:visible' ).eq( 0 ).before( postbox );
button.focus();
button.trigger( 'focus' );
postboxes.updateOrderButtonsProperties();
postboxes.save_order( postboxes.page );
}
Expand All @@ -141,7 +141,7 @@
}

postbox.nextAll( '.postbox:visible' ).eq( 0 ).after( postbox );
button.focus();
button.trigger( 'focus' );
postboxes.updateOrderButtonsProperties();
postboxes.save_order( postboxes.page );
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/_enqueues/admin/privacy-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ jQuery( document ).ready( function( $ ) {
// Label handling to focus the create page button on Privacy settings page.
$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
e.preventDefault();
$( 'input#create-page' ).focus();
$( 'input#create-page' ).trigger( 'focus' );
} );

// Accordion handling in various new Privacy settings pages.
Expand Down
Loading

0 comments on commit 6975104

Please sign in to comment.