Skip to content

Commit 6975104

Browse files
External Libraries: Further fix jQuery deprecations in WordPress core.
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
1 parent 0a2ba7c commit 6975104

32 files changed

+127
-130
lines changed

src/js/_enqueues/admin/auth-app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
rejectUrl: authApp.reject
1616
};
1717

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

@@ -26,7 +26,7 @@
2626
}
2727

2828
if ( 0 === name.length ) {
29-
$appNameField.focus();
29+
$appNameField.trigger( 'focus' );
3030
return;
3131
}
3232

@@ -102,7 +102,7 @@
102102
$( 'input', $notice ).val( response.password );
103103

104104
$form.replaceWith( $notice );
105-
$notice.focus();
105+
$notice.trigger( 'focus' );
106106
}
107107
} ).fail( function( jqXHR, textStatus, errorThrown ) {
108108
var errorMessage = errorThrown,
@@ -140,7 +140,7 @@
140140
} );
141141
} );
142142

143-
$rejectBtn.click( function( e ) {
143+
$rejectBtn.on( 'click', function( e ) {
144144
e.preventDefault();
145145

146146
/**

src/js/_enqueues/admin/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ $document.ready( function() {
840840
* @return {void}
841841
*/
842842
$adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
843-
$(e.target).parent().siblings('a').get(0).click();
843+
$(e.target).parent().siblings('a').get(0).trigger( 'click' );
844844
});
845845

846846
/**

src/js/_enqueues/admin/custom-background.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* @return {void}
4141
*/
42-
$( 'select[name="background-size"]' ).change( function() {
42+
$( 'select[name="background-size"]' ).on( 'change', function() {
4343
bgImage.css( 'background-size', $( this ).val() );
4444
});
4545

@@ -50,7 +50,7 @@
5050
*
5151
* @return {void}
5252
*/
53-
$( 'input[name="background-position"]' ).change( function() {
53+
$( 'input[name="background-position"]' ).on( 'change', function() {
5454
bgImage.css( 'background-position', $( this ).val() );
5555
});
5656

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

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

@@ -83,7 +83,7 @@
8383
*
8484
* @return {void}
8585
*/
86-
$('#choose-from-library-link').click( function( event ) {
86+
$('#choose-from-library-link').on( 'click', function( event ) {
8787
var $el = $(this);
8888

8989
event.preventDefault();

src/js/_enqueues/admin/custom-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @return {void}
3737
*/
38-
$('#choose-from-library-link').click( function( event ) {
38+
$('#choose-from-library-link').on( 'click', function( event ) {
3939
var $el = $(this);
4040
event.preventDefault();
4141

src/js/_enqueues/admin/edit-comments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ window.commentReply = {
850850
*/
851851
toggle : function(el) {
852852
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.' ) ) ) ) {
853-
$( el ).find( 'button.vim-q' ).click();
853+
$( el ).find( 'button.vim-q' ).trigger( 'click' );
854854
}
855855
},
856856

@@ -1298,7 +1298,7 @@ $(document).ready(function(){
12981298
return function() {
12991299
var scope = $('select[name="action"]');
13001300
$('option[value="' + value + '"]', scope).prop('selected', true);
1301-
$('#doaction').click();
1301+
$('#doaction').trigger( 'click' );
13021302
};
13031303
};
13041304

src/js/_enqueues/admin/link.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jQuery(document).ready( function($) {
88

99
var newCat, noSyncChecks = false, syncChecks, catAddAfter;
1010

11-
$('#link_name').focus();
11+
$('#link_name').trigger( 'focus' );
1212
// Postboxes.
1313
postboxes.add_postbox_toggles('link');
1414

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

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

4646
/**
4747
* Synchronize category checkboxes.
@@ -82,7 +82,7 @@ jQuery(document).ready( function($) {
8282
var t = $($(this).text());
8383
t.find( 'label' ).each( function() {
8484
var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o;
85-
$('#' + id).change( syncChecks );
85+
$('#' + id).on( 'change', syncChecks );
8686
o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
8787
} );
8888
} );
@@ -108,13 +108,13 @@ jQuery(document).ready( function($) {
108108
} );
109109

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

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

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

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

135-
$('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
135+
$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' );
136136
});

src/js/_enqueues/admin/media.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
$( '#find-posts' ).show();
4747

4848
// Close the dialog when the escape key is pressed.
49-
$('#find-posts-input').focus().keyup( function( event ){
49+
$('#find-posts-input').trigger( 'focus' ).on( 'keyup', function( event ){
5050
if ( event.which == 27 ) {
5151
findPosts.close();
5252
}

src/js/_enqueues/admin/plugin-install.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jQuery( document ).ready( function( $ ) {
7575
.on( 'thickbox:removed', function() {
7676
// Set focus back to the element that opened the modal dialog.
7777
// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
78-
$focusedBefore.focus();
78+
$focusedBefore.trigger( 'focus' );
7979
});
8080

8181
function iframeLoaded() {
@@ -88,7 +88,7 @@ jQuery( document ).ready( function( $ ) {
8888
handleTabbables();
8989

9090
// Set initial focus on the "Close" button.
91-
$firstTabbable.focus();
91+
$firstTabbable.trigger( 'focus' );
9292

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

142142
if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
143143
event.preventDefault();
144-
$firstTabbable.focus();
144+
$firstTabbable.trigger( 'focus' );
145145
} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
146146
event.preventDefault();
147-
$lastTabbable.focus();
147+
$lastTabbable.trigger( 'focus' );
148148
}
149149
}
150150

src/js/_enqueues/admin/post.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ window.wp = window.wp || {};
6868
$('#the-comment-list').append( r.responses[0].data );
6969

7070
theList = theExtraList = null;
71-
$( 'a[className*=\':\']' ).unbind();
71+
$( 'a[className*=\':\']' ).off();
7272

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

416416
$previewField.val('dopreview');
417-
$form.attr( 'target', target ).submit().attr( 'target', '' );
417+
$form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' );
418418

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

449449
// Auto save new posts after a title is typed.
450450
if ( $( '#auto_draft' ).val() ) {
451-
$( '#title' ).blur( function() {
451+
$( '#title' ).on( 'blur', function() {
452452
var cancel;
453453

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

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

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

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

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

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

@@ -1054,11 +1054,11 @@ jQuery(document).ready( function($) {
10541054
// On [Enter], just save the new slug, don't save the post.
10551055
if ( 13 === key ) {
10561056
e.preventDefault();
1057-
buttons.children( '.save' ).click();
1057+
buttons.children( '.save' ).trigger( 'click' );
10581058
}
10591059
// On [Esc] cancel the editing.
10601060
if ( 27 === key ) {
1061-
buttons.children( '.cancel' ).click();
1061+
buttons.children( '.cancel' ).trigger( 'click' );
10621062
}
10631063
} ).on( 'keyup', function() {
10641064
real_slug.val( this.value );
@@ -1177,7 +1177,7 @@ jQuery(document).ready( function($) {
11771177
} else {
11781178
mce = false;
11791179
offset = $textarea.height() - event.pageY;
1180-
$textarea.blur();
1180+
$textarea.trigger( 'blur' );
11811181
}
11821182

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

12661266
// Show success visual feedback.
12671267
clearTimeout( copyAttachmentURLSuccessTimeout );

src/js/_enqueues/admin/postbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
}
128128

129129
postbox.prevAll( '.postbox:visible' ).eq( 0 ).before( postbox );
130-
button.focus();
130+
button.trigger( 'focus' );
131131
postboxes.updateOrderButtonsProperties();
132132
postboxes.save_order( postboxes.page );
133133
}
@@ -141,7 +141,7 @@
141141
}
142142

143143
postbox.nextAll( '.postbox:visible' ).eq( 0 ).after( postbox );
144-
button.focus();
144+
button.trigger( 'focus' );
145145
postboxes.updateOrderButtonsProperties();
146146
postboxes.save_order( postboxes.page );
147147
}

src/js/_enqueues/admin/privacy-tools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ jQuery( document ).ready( function( $ ) {
328328
// Label handling to focus the create page button on Privacy settings page.
329329
$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
330330
e.preventDefault();
331-
$( 'input#create-page' ).focus();
331+
$( 'input#create-page' ).trigger( 'focus' );
332332
} );
333333

334334
// Accordion handling in various new Privacy settings pages.

0 commit comments

Comments
 (0)