diff --git a/src/js/_enqueues/admin/comment.js b/src/js/_enqueues/admin/comment.js index d815eee184..4e4f3c5ed9 100644 --- a/src/js/_enqueues/admin/comment.js +++ b/src/js/_enqueues/admin/comment.js @@ -11,7 +11,7 @@ * * @param {jQuery} $ The jQuery object. */ -jQuery(document).ready( function($) { +jQuery( function($) { postboxes.add_postbox_toggles('comment'); diff --git a/src/js/_enqueues/admin/common.js b/src/js/_enqueues/admin/common.js index f0807f989e..636237f0b4 100644 --- a/src/js/_enqueues/admin/common.js +++ b/src/js/_enqueues/admin/common.js @@ -483,7 +483,7 @@ window.columns = { } }; -$document.ready(function(){columns.init();}); +$( function() { columns.init(); } ); /** * Validates that the required form fields are not empty. @@ -802,7 +802,7 @@ $availableStructureTags.on( 'click', function() { } } ); -$document.ready( function() { +$( function() { var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, lastClicked = false, pageInput = $('input.current-page'), @@ -1706,7 +1706,7 @@ $document.ready( function() { }); self.trigger(); - $document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) ); + $document.on( 'wp-window-resized.wp-responsive', this.trigger.bind( this ) ); // This needs to run later as UI Sortable may be initialized later on $(document).ready(). $window.on( 'load.wp-responsive', this.maybeDisableSortables ); @@ -1889,7 +1889,7 @@ $document.ready( function() { $( '.aria-button-if-js' ).attr( 'role', 'button' ); } - $( document ).ajaxComplete( function() { + $( document ).on( 'ajaxComplete', function() { aria_button_if_js(); }); @@ -2008,7 +2008,7 @@ $document.ready( function() { * * @since 5.5.0 */ -$document.ready( function( $ ) { +$( function( $ ) { var $overwrite, $warning; if ( ! $body.hasClass( 'update-php' ) ) { diff --git a/src/js/_enqueues/admin/custom-background.js b/src/js/_enqueues/admin/custom-background.js index 8204fdfeca..f83db00af0 100644 --- a/src/js/_enqueues/admin/custom-background.js +++ b/src/js/_enqueues/admin/custom-background.js @@ -12,7 +12,7 @@ * @requires jQuery */ (function($) { - $(document).ready(function() { + $( function() { var frame, bgImage = $( '#custom-background-image' ); diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 31d0c551a7..96ca1f9f48 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -1225,7 +1225,7 @@ window.commentReply = { } }; -$(document).ready(function(){ +$( function(){ var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; setCommentsList(); diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index 70c5996496..4d297e0c1a 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -516,10 +516,16 @@ window.wp = window.wp || {}; } }; -$( document ).ready( function(){ inlineEditPost.init(); } ); +$( function() { inlineEditPost.init(); } ); // Show/hide locks on posts. -$( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { +$( function() { + + // Set the heartbeat interval to 15 seconds. + if ( typeof wp !== 'undefined' && wp.heartbeat ) { + wp.heartbeat.interval( 15 ); + } +}).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { var locked = data['wp-check-locked-posts'] || {}; $('#the-list tr').each( function(i, el) { @@ -560,12 +566,6 @@ $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { if ( check.length ) { data['wp-check-locked-posts'] = check; } -}).ready( function() { - - // Set the heartbeat interval to 15 seconds. - if ( typeof wp !== 'undefined' && wp.heartbeat ) { - wp.heartbeat.interval( 15 ); - } }); })( jQuery, window.wp ); diff --git a/src/js/_enqueues/admin/inline-edit-tax.js b/src/js/_enqueues/admin/inline-edit-tax.js index f8b52d63e7..86e3498cd1 100644 --- a/src/js/_enqueues/admin/inline-edit-tax.js +++ b/src/js/_enqueues/admin/inline-edit-tax.js @@ -289,6 +289,6 @@ window.inlineEditTax = { } }; -$(document).ready(function(){inlineEditTax.init();}); +$( function() { inlineEditTax.init(); } ); })( jQuery, window.wp ); diff --git a/src/js/_enqueues/admin/link.js b/src/js/_enqueues/admin/link.js index 3bb7378ba8..1456ba9530 100644 --- a/src/js/_enqueues/admin/link.js +++ b/src/js/_enqueues/admin/link.js @@ -4,7 +4,7 @@ /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */ -jQuery(document).ready( function($) { +jQuery( function($) { var newCat, noSyncChecks = false, syncChecks, catAddAfter; @@ -81,7 +81,11 @@ jQuery(document).ready( function($) { $(s.what + ' response_data', r).each( 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; + var th = $(this), + val = th.find('input').val(), + id = th.find('input')[0].id, + name = th.text().trim(), + o; $('#' + id).on( 'change', syncChecks ); o = $( '' ).text( name ); } ); diff --git a/src/js/_enqueues/admin/media.js b/src/js/_enqueues/admin/media.js index fa11305117..13d46e485b 100644 --- a/src/js/_enqueues/admin/media.js +++ b/src/js/_enqueues/admin/media.js @@ -140,7 +140,7 @@ * * @return {void} */ - $( document ).ready( function() { + $( function() { var settings, $mediaGridWrap = $( '#wp-media-grid' ); // Opens a manage media frame into the grid. diff --git a/src/js/_enqueues/admin/plugin-install.js b/src/js/_enqueues/admin/plugin-install.js index 7cd6fd5bad..9b43b53e13 100644 --- a/src/js/_enqueues/admin/plugin-install.js +++ b/src/js/_enqueues/admin/plugin-install.js @@ -6,7 +6,7 @@ /* global tb_click, tb_remove, tb_position */ -jQuery( document ).ready( function( $ ) { +jQuery( function( $ ) { var tbWindow, $iframeBody, diff --git a/src/js/_enqueues/admin/post.js b/src/js/_enqueues/admin/post.js index a83f834d78..b0fca99135 100644 --- a/src/js/_enqueues/admin/post.js +++ b/src/js/_enqueues/admin/post.js @@ -260,7 +260,9 @@ window.wp = window.wp || {}; timeout = window.setTimeout( function(){ check = true; }, 300000 ); } - $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { + $( function() { + schedule(); + }).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { var post_id, $authCheck = $('#wp-auth-check-wrap'); @@ -286,15 +288,13 @@ window.wp = window.wp || {}; if ( nonces.heartbeatNonce ) window.heartbeatSettings.nonce = nonces.heartbeatNonce; } - }).ready( function() { - schedule(); }); }(jQuery)); /** * All post and postbox controls and functionality. */ -jQuery(document).ready( function($) { +jQuery( function($) { var stamp, visibility, $submitButtons, updateVisibility, updateText, $textarea = $('#content'), $document = $(document), @@ -661,7 +661,7 @@ jQuery(document).ready( function($) { $('#' + taxonomy + '-add-toggle').on( 'click', function( e ) { e.preventDefault(); $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); - $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click(); + $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' ); $('#new'+taxonomy).trigger( 'focus' ); }); diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js index 331af439c9..e5fceb86d7 100644 --- a/src/js/_enqueues/admin/privacy-tools.js +++ b/src/js/_enqueues/admin/privacy-tools.js @@ -5,7 +5,7 @@ */ // Privacy request action handling. -jQuery( document ).ready( function( $ ) { +jQuery( function( $ ) { var __ = wp.i18n.__, copiedNoticeTimeout; diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js index aabc91d6a1..c0e2454224 100644 --- a/src/js/_enqueues/admin/site-health.js +++ b/src/js/_enqueues/admin/site-health.js @@ -6,7 +6,7 @@ /* global ajaxurl, ClipboardJS, SiteHealth, wp */ -jQuery( document ).ready( function( $ ) { +jQuery( function( $ ) { var __ = wp.i18n.__, _n = wp.i18n._n, diff --git a/src/js/_enqueues/admin/tags-box.js b/src/js/_enqueues/admin/tags-box.js index fbbb355861..99d664691c 100644 --- a/src/js/_enqueues/admin/tags-box.js +++ b/src/js/_enqueues/admin/tags-box.js @@ -27,7 +27,8 @@ // Trim the values and ensure they are unique. $.each( array, function( key, val ) { - val = $.trim( val ); + val = val || ''; + val = val.trim(); if ( val && $.inArray( val, out ) === -1 ) { out.push( val ); @@ -96,7 +97,8 @@ // Sanitize the current tags and push them as if they're new tags. $.each( current_tags, function( key, val ) { - val = $.trim( val ); + val = val || ''; + val = val.trim(); if ( val ) { new_tags.push( val ); } @@ -148,7 +150,8 @@ $.each( current_tags, function( key, val ) { var listItem, xbutton; - val = $.trim( val ); + val = val || ''; + val = val.trim(); if ( ! val ) return; diff --git a/src/js/_enqueues/admin/tags.js b/src/js/_enqueues/admin/tags.js index 6c4b8b7a2e..6c25e55537 100644 --- a/src/js/_enqueues/admin/tags.js +++ b/src/js/_enqueues/admin/tags.js @@ -9,7 +9,7 @@ /* global ajaxurl, wpAjax, showNotice, validateForm */ -jQuery(document).ready(function($) { +jQuery( function($) { var addingTerm = false; diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js index 06cfba2e12..3b5e26f977 100644 --- a/src/js/_enqueues/admin/user-profile.js +++ b/src/js/_enqueues/admin/user-profile.js @@ -319,7 +319,7 @@ } } - $(document).ready( function() { + $( function() { var $colorpicker, $stylesheet, user_id, current_user_id, select = $( '#display_name' ), current_name = select.val(), @@ -374,7 +374,7 @@ return; } - var display_name = $.trim( this.value ) || current_name; + var display_name = this.value.trim() || current_name; greeting.text( display_name ); } ); @@ -466,7 +466,7 @@ * to avoid double clicking the button to retrieve the first generated password. * See ticket #39638. */ - $( document ).ready( function() { + $( function() { if ( $( '.reset-pass-submit' ).length ) { $( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); } diff --git a/src/js/_enqueues/admin/widgets.js b/src/js/_enqueues/admin/widgets.js index 245b0c12b2..e8fc42507d 100644 --- a/src/js/_enqueues/admin/widgets.js +++ b/src/js/_enqueues/admin/widgets.js @@ -741,7 +741,7 @@ window.wpWidgets = { } }; -$document.ready( function(){ wpWidgets.init(); } ); +$( function(){ wpWidgets.init(); } ); })(jQuery); diff --git a/src/js/_enqueues/admin/xfn.js b/src/js/_enqueues/admin/xfn.js index fdbe6a368f..cf7fcf8bb7 100644 --- a/src/js/_enqueues/admin/xfn.js +++ b/src/js/_enqueues/admin/xfn.js @@ -4,7 +4,7 @@ * @deprecated 3.5.0 * @output wp-admin/js/xfn.js */ -jQuery( document ).ready(function( $ ) { +jQuery( function( $ ) { $( '#link_rel' ).prop( 'readonly', true ); $( '#linkxfndiv input' ).on( 'click keyup', function() { var isMe = $( '#me' ).is( ':checked' ), inputs = ''; diff --git a/src/js/_enqueues/lib/accordion.js b/src/js/_enqueues/lib/accordion.js index 7eacbec966..c420e8ccb8 100644 --- a/src/js/_enqueues/lib/accordion.js +++ b/src/js/_enqueues/lib/accordion.js @@ -31,7 +31,7 @@ ( function( $ ){ - $( document ).ready( function () { + $( function () { // Expand/Collapse accordion sections on click. $( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) { diff --git a/src/js/_enqueues/lib/ajax-response.js b/src/js/_enqueues/lib/ajax-response.js index 6b356d8a94..38816f3c38 100644 --- a/src/js/_enqueues/lib/ajax-response.js +++ b/src/js/_enqueues/lib/ajax-response.js @@ -65,6 +65,6 @@ window.wpAjax = jQuery.extend( { }, wpAjax || { noPerm: 'Sorry, you are not allowed to do that.', broken: 'Something went wrong.' } ); // Basic form validation. -jQuery(document).ready( function($){ +jQuery( function($){ $('form.validate').on( 'submit', function() { return wpAjax.validateForm( $(this) ); } ); }); diff --git a/src/js/_enqueues/lib/auth-check.js b/src/js/_enqueues/lib/auth-check.js index c574c992ef..44ff15a153 100644 --- a/src/js/_enqueues/lib/auth-check.js +++ b/src/js/_enqueues/lib/auth-check.js @@ -144,15 +144,7 @@ * @param {Object} e The heartbeat-tick event that has been triggered. * @param {Object} data Response data. */ - $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { - if ( 'wp-auth-check' in data ) { - if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) { - show(); - } else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) { - hide(); - } - } - }).ready( function() { + $( function() { /** * Hides the authentication form popup when the close icon is clicked. @@ -166,6 +158,14 @@ hide(); setShowTimeout(); }); + }).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { + if ( 'wp-auth-check' in data ) { + if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) { + show(); + } else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) { + hide(); + } + } }); }(jQuery)); diff --git a/src/js/_enqueues/lib/color-picker.js b/src/js/_enqueues/lib/color-picker.js index f41f00af18..600e0235b3 100644 --- a/src/js/_enqueues/lib/color-picker.js +++ b/src/js/_enqueues/lib/color-picker.js @@ -101,7 +101,7 @@ } // Bind the close event. - self.close = $.proxy( self.close, self ); + self.close = self.close.bind( self ); self.initialValue = el.val(); @@ -277,7 +277,7 @@ if ( me.hasClass( 'wp-picker-clear' ) ) { self.element.val( '' ); self.toggler.css( 'backgroundColor', '' ); - if ( $.isFunction( self.options.clear ) ) { + if ( typeof self.options.clear === 'function' ) { self.options.clear.call( this, event ); } } else if ( me.hasClass( 'wp-picker-default' ) ) { diff --git a/src/js/_enqueues/lib/gallery.js b/src/js/_enqueues/lib/gallery.js index e1c34b5b9f..d493946c5b 100644 --- a/src/js/_enqueues/lib/gallery.js +++ b/src/js/_enqueues/lib/gallery.js @@ -4,7 +4,7 @@ /* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */ -jQuery(document).ready(function($) { +jQuery( function($) { var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false; gallerySortableInit = function() { diff --git a/src/js/_enqueues/lib/link.js b/src/js/_enqueues/lib/link.js index 7fa60a8e83..89adf33796 100644 --- a/src/js/_enqueues/lib/link.js +++ b/src/js/_enqueues/lib/link.js @@ -93,7 +93,7 @@ // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://. correctURL: function () { - var url = $.trim( inputs.url.val() ); + var url = inputs.url.val().trim(); if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) { inputs.url.val( 'http://' + url ); @@ -238,7 +238,7 @@ linkText = linkNode.text(); href = linkNode.attr( 'href' ); - if ( ! $.trim( linkText ) ) { + if ( ! linkText.trim() ) { linkText = text || ''; } @@ -312,7 +312,7 @@ wpLink.correctURL(); return { - href: $.trim( inputs.url.val() ), + href: inputs.url.val().trim(), target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : null }; }, @@ -425,7 +425,7 @@ if ( ! $link.length ) { editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } ); $link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' ); - hasText = $.trim( $link.text() ); + hasText = $link.text().trim(); } if ( ! $link.length ) { @@ -483,7 +483,8 @@ } } - selection = $.trim( selection ); + selection = selection || ''; + selection = selection.trim(); if ( selection && emailRegexp.test( selection ) ) { // Selection is email address. @@ -797,5 +798,5 @@ } }); - $( document ).ready( wpLink.init ); + $( wpLink.init ); })( jQuery, window.wpLinkL10n, window.wp ); diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index bd031d9905..d3b9663487 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -1331,7 +1331,7 @@ }; - $(document).ready(function() { + $( function() { wpNavMenu.init(); diff --git a/src/js/_enqueues/lib/quicktags.js b/src/js/_enqueues/lib/quicktags.js index 2224cbed84..4b1a80fa28 100644 --- a/src/js/_enqueues/lib/quicktags.js +++ b/src/js/_enqueues/lib/quicktags.js @@ -57,7 +57,7 @@ window.edToolbar = function(){}; var t, i, DOMContentLoaded, _tryReady; if ( typeof jQuery !== 'undefined' ) { - jQuery(document).ready(func); + jQuery( func ); } else { t = _domReady; t.funcs = []; diff --git a/src/js/_enqueues/lib/user-suggest.js b/src/js/_enqueues/lib/user-suggest.js index 19770df075..f05b7ffa88 100644 --- a/src/js/_enqueues/lib/user-suggest.js +++ b/src/js/_enqueues/lib/user-suggest.js @@ -14,7 +14,7 @@ (function( $ ) { var id = ( typeof current_site_id !== 'undefined' ) ? '&site_id=' + current_site_id : ''; - $(document).ready( function() { + $( function() { var position = { offset: '0, -1' }; if ( typeof isRtl !== 'undefined' && isRtl ) { position.my = 'right top'; diff --git a/src/js/_enqueues/wp/autosave.js b/src/js/_enqueues/wp/autosave.js index 0351388c4a..29d81e6e9d 100644 --- a/src/js/_enqueues/wp/autosave.js +++ b/src/js/_enqueues/wp/autosave.js @@ -582,7 +582,7 @@ window.autosave = function() { * Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'. */ if ( checkStorage() && blog_id && ( $('#content').length || $('#excerpt').length ) ) { - $document.ready( run ); + $( run ); } return { @@ -798,7 +798,9 @@ window.autosave = function() { * * @return {void} */ - $document.on( 'heartbeat-send.autosave', function( event, data ) { + $( function() { + _schedule(); + }).on( 'heartbeat-send.autosave', function( event, data ) { var autosaveData = save(); if ( autosaveData ) { @@ -848,8 +850,6 @@ window.autosave = function() { }).on( 'heartbeat-connection-restored.autosave', function() { $('#lost-connection-notice').hide(); enableButtons(); - }).ready( function() { - _schedule(); }); return { @@ -873,7 +873,10 @@ window.autosave = function() { * * @return {void} */ - $document.on( 'tinymce-editor-init.autosave', function( event, editor ) { + $( function() { + // Set the initial compare string in case TinyMCE is not used or not loaded first. + setInitialCompare(); + }).on( 'tinymce-editor-init.autosave', function( event, editor ) { // Reset the initialCompare data after the TinyMCE instances have been initialized. if ( 'content' === editor.id || 'excerpt' === editor.id ) { window.setTimeout( function() { @@ -881,9 +884,6 @@ window.autosave = function() { setInitialCompare(); }, 1000 ); } - }).ready( function() { - // Set the initial compare string in case TinyMCE is not used or not loaded first. - setInitialCompare(); }); return { diff --git a/src/js/_enqueues/wp/customize/base.js b/src/js/_enqueues/wp/customize/base.js index a088c34386..24a5bf6669 100644 --- a/src/js/_enqueues/wp/customize/base.js +++ b/src/js/_enqueues/wp/customize/base.js @@ -197,7 +197,7 @@ window.wp = window.wp || {}; $.extend( this, options || {} ); - this.set = $.proxy( this.set, this ); + this.set = this.set.bind( this ); }, /* @@ -734,7 +734,7 @@ window.wp = window.wp || {}; * This will prevent every Messenger's receive function from being * unbound when calling $.off( 'message', this.receive ); */ - this.receive = $.proxy( this.receive, this ); + this.receive = this.receive.bind( this ); this.receive.guid = $.guid++; $( window ).on( 'message', this.receive ); diff --git a/src/js/_enqueues/wp/customize/controls.js b/src/js/_enqueues/wp/customize/controls.js index 45122597f0..c8ee3de8df 100644 --- a/src/js/_enqueues/wp/customize/controls.js +++ b/src/js/_enqueues/wp/customize/controls.js @@ -289,7 +289,7 @@ collection.focusContainer.focus(); } } else if ( collection.previousActiveElement ) { - $( collection.previousActiveElement ).focus(); + $( collection.previousActiveElement ).trigger( 'focus' ); collection.previousActiveElement = null; } @@ -1592,7 +1592,7 @@ if ( args.unchanged ) { expand = args.completeCallback; } else { - expand = $.proxy( function() { + expand = function() { section._animateChangeExpanded( function() { sectionTitle.attr( 'tabindex', '-1' ); backBtn.attr( 'tabindex', '0' ); @@ -1609,7 +1609,7 @@ content.addClass( 'open' ); overlay.addClass( 'section-open' ); api.state( 'expandedSection' ).set( section ); - }, this ); + }.bind( this ); } if ( ! args.allowMultiple ) { @@ -2696,12 +2696,12 @@ if ( args.unchanged ) { expand = args.completeCallback; } else { - expand = $.proxy( function() { + expand = function() { section._animateChangeExpanded( function() { sectionTitle.attr( 'tabindex', '-1' ); backBtn.attr( 'tabindex', '0' ); - backBtn.focus(); + backBtn.trigger( 'focus' ); content.css( 'top', '' ); container.scrollTop( 0 ); @@ -2711,7 +2711,7 @@ } ); content.addClass( 'open' ); - }, this ); + }.bind( this ); } if ( section.panel() ) { @@ -2956,7 +2956,7 @@ topPanel.attr( 'tabindex', '-1' ); backBtn.attr( 'tabindex', '0' ); - backBtn.focus(); + backBtn.trigger( 'focus' ); accordionSection.css( 'top', '' ); container.scrollTop( 0 ); @@ -3874,9 +3874,9 @@ control.container.toggleClass( 'has-notifications', 0 !== notifications.length ); control.container.toggleClass( 'has-error', hasError ); - container.empty().append( $.trim( - control.notificationsTemplate( { notifications: notifications, altNotice: Boolean( control.altNotice ) } ) - ) ); + container.empty().append( + control.notificationsTemplate( { notifications: notifications, altNotice: Boolean( control.altNotice ) } ).trim() + ); }, /** diff --git a/src/js/_enqueues/wp/customize/nav-menus.js b/src/js/_enqueues/wp/customize/nav-menus.js index a9033dbd27..8930f15ddf 100644 --- a/src/js/_enqueues/wp/customize/nav-menus.js +++ b/src/js/_enqueues/wp/customize/nav-menus.js @@ -218,7 +218,7 @@ // Clear the search results and trigger an `input` event to fire a new search. this.$clearResults.on( 'click', function() { - self.$search.val( '' ).focus().trigger( 'input' ); + self.$search.val( '' ).trigger( 'focus' ).trigger( 'input' ); } ); this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() { @@ -446,7 +446,7 @@ self.pages[ name ] = -1; return; } else if ( ( 'post_type:page' === name ) && ( ! availableMenuItemContainers[ name ].hasClass( 'open' ) ) ) { - availableMenuItemContainers[ name ].find( '.accordion-section-title > button' ).click(); + availableMenuItemContainers[ name ].find( '.accordion-section-title > button' ).trigger( 'click' ); } typeItems = new api.Menus.AvailableItemCollection( typeItems ); // @todo Why is this collection created and then thrown away? self.collection.add( typeItems.models ); @@ -644,7 +644,7 @@ return; } - if ( '' === $.trim( itemName.val() ) ) { + if ( '' === itemName.val().trim() ) { itemName.addClass( 'invalid' ); itemName.focus(); return; @@ -716,7 +716,7 @@ this.$el.find( '.selected' ).removeClass( 'selected' ); - this.$search.focus(); + this.$search.trigger( 'focus' ); }, // Closes the panel. @@ -1879,7 +1879,7 @@ // Ensure that whitespace is trimmed on blur so placeholder can be shown. control.container.find( '.edit-menu-item-title' ).on( 'blur', function() { - $( this ).val( $.trim( $( this ).val() ) ); + $( this ).val( $( this ).val().trim() ); } ); titleEl = control.container.find( '.menu-item-title' ); @@ -1888,7 +1888,8 @@ if ( ! item ) { return; } - trimmedTitle = $.trim( item.title ); + item.title = item.title || ''; + trimmedTitle = item.title.trim(); titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled; diff --git a/src/js/_enqueues/wp/customize/widgets.js b/src/js/_enqueues/wp/customize/widgets.js index 8d320c8c86..a33bfe1e78 100644 --- a/src/js/_enqueues/wp/customize/widgets.js +++ b/src/js/_enqueues/wp/customize/widgets.js @@ -195,7 +195,7 @@ // Clear the search results and trigger an `input` event to fire a new search. this.$clearResults.on( 'click', function() { - self.$search.val( '' ).focus().trigger( 'input' ); + self.$search.val( '' ).trigger( 'focus' ).trigger( 'input' ); } ); // Close the panel if the URL in the preview changes. @@ -365,7 +365,7 @@ this.collection.doSearch( '' ); if ( ! api.settings.browser.mobile ) { - this.$search.focus(); + this.$search.trigger( 'focus' ); } }, @@ -421,9 +421,9 @@ this.select( selected ); if ( selected ) { - selected.focus(); + selected.trigger( 'focus' ); } else { - this.$search.focus(); + this.$search.trigger( 'focus' ); } return; @@ -818,7 +818,7 @@ if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } - $( this ).focus(); + $( this ).trigger( 'focus' ); if ( $( this ).is( '.move-widget' ) ) { self.toggleWidgetMoveArea(); @@ -839,7 +839,7 @@ wp.a11y.speak( l10n.widgetMovedDown ); } - $( this ).focus(); // Re-focus after the container was moved. + $( this ).trigger( 'focus' ); // Re-focus after the container was moved. } } ); @@ -1103,7 +1103,7 @@ if ( input.is( ':radio, :checkbox' ) ) { input.prop( 'checked', state ); } else if ( input.is( 'select[multiple]' ) ) { - if ( ! $.isArray( state ) ) { + if ( ! Array.isArray( state ) ) { state = []; } else { // Make sure all state items are strings since the DOM value is a string. @@ -2089,7 +2089,7 @@ widgetNumber = widget.get( 'multi_number' ); } - controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() ); + controlHtml = $( '#widget-tpl-' + widget.get( 'id' ) ).html().trim(); if ( widget.get( 'is_multi' ) ) { controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) { return m.replace( /__i__|%i%/g, widgetNumber ); diff --git a/src/js/_enqueues/wp/dashboard.js b/src/js/_enqueues/wp/dashboard.js index f2ddad2d45..3354790472 100644 --- a/src/js/_enqueues/wp/dashboard.js +++ b/src/js/_enqueues/wp/dashboard.js @@ -12,7 +12,7 @@ window.communityEventsData = window.communityEventsData || {}; * * @since 2.7.0 */ -jQuery(document).ready( function($) { +jQuery( function($) { var welcomePanel = $( '#welcome-panel' ), welcomePanelHide = $('#wp_welcome_panel-hide'), updateWelcomePanel; @@ -328,7 +328,7 @@ jQuery( function( $ ) { * @return {void} */ $container.on( 'submit', '.community-events-form', function( event ) { - var location = $.trim( $( '#community-events-location' ).val() ); + var location = $( '#community-events-location' ).val().trim(); event.preventDefault(); diff --git a/src/js/_enqueues/wp/editor/base.js b/src/js/_enqueues/wp/editor/base.js index 5fc41f5998..d5fe958c19 100644 --- a/src/js/_enqueues/wp/editor/base.js +++ b/src/js/_enqueues/wp/editor/base.js @@ -1178,7 +1178,7 @@ window.wp = window.wp || {}; } if ( $ ) { - $( document ).ready( init ); + $( init ); } else if ( document.addEventListener ) { document.addEventListener( 'DOMContentLoaded', init, false ); window.addEventListener( 'load', init, false ); diff --git a/src/js/_enqueues/wp/heartbeat.js b/src/js/_enqueues/wp/heartbeat.js index aff58b12a3..4f71c1cab4 100644 --- a/src/js/_enqueues/wp/heartbeat.js +++ b/src/js/_enqueues/wp/heartbeat.js @@ -234,7 +234,7 @@ window.setInterval( checkUserActivity, 30000 ); // Start one tick after DOM ready. - $document.ready( function() { + $( function() { settings.lastTick = time(); scheduleNextTick(); }); diff --git a/src/js/_enqueues/wp/svg-painter.js b/src/js/_enqueues/wp/svg-painter.js index 85bc04ac65..a356735446 100644 --- a/src/js/_enqueues/wp/svg-painter.js +++ b/src/js/_enqueues/wp/svg-painter.js @@ -12,7 +12,7 @@ wp.svgPainter = ( function( $, window, document, undefined ) { colorscheme = {}, elements = []; - $(document).ready( function() { + $( function() { // Detection for browser SVG capability. if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) { $( document.body ).removeClass( 'no-svg' ).addClass( 'svg' ); diff --git a/src/js/_enqueues/wp/theme-plugin-editor.js b/src/js/_enqueues/wp/theme-plugin-editor.js index 511d46f164..8871b0432a 100644 --- a/src/js/_enqueues/wp/theme-plugin-editor.js +++ b/src/js/_enqueues/wp/theme-plugin-editor.js @@ -328,7 +328,7 @@ wp.themePluginEditor = (function( $ ) { * @return {void} */ codeEditorSettings.onTabPrevious = function() { - $( '#templateside' ).find( ':tabbable' ).last().focus(); + $( '#templateside' ).find( ':tabbable' ).last().trigger( 'focus' ); }; /** @@ -339,7 +339,7 @@ wp.themePluginEditor = (function( $ ) { * @return {void} */ codeEditorSettings.onTabNext = function() { - $( '#template' ).find( ':tabbable:not(.CodeMirror-code)' ).first().focus(); + $( '#template' ).find( ':tabbable:not(.CodeMirror-code)' ).first().trigger( 'focus' ); }; /** diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index 2e0445c5df..f4ea7d57a2 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -2061,7 +2061,7 @@ themes.RunInstaller = { }; // Ready... -$( document ).ready(function() { +$( function() { if ( themes.isInstall ) { themes.RunInstaller.init(); } else { @@ -2089,7 +2089,7 @@ $( document ).ready(function() { })( jQuery ); // Align theme browser thickbox. -jQuery(document).ready( function($) { +jQuery( function($) { window.tb_position = function() { var tbWindow = $('#TB_window'), width = $(window).width(), diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js index f98a48e5d6..1e101f0c59 100644 --- a/src/js/_enqueues/wp/updates.js +++ b/src/js/_enqueues/wp/updates.js @@ -1803,7 +1803,7 @@ $( 'body' ).removeClass( 'modal-open' ); if ( wp.updates.$elToReturnFocusToFromCredentialsModal ) { - wp.updates.$elToReturnFocusToFromCredentialsModal.focus(); + wp.updates.$elToReturnFocusToFromCredentialsModal.trigger( 'focus' ); } }; diff --git a/src/js/_enqueues/wp/widgets/media.js b/src/js/_enqueues/wp/widgets/media.js index 6f8beda739..dbe007cdb8 100644 --- a/src/js/_enqueues/wp/widgets/media.js +++ b/src/js/_enqueues/wp/widgets/media.js @@ -551,13 +551,13 @@ wp.mediaWidgets = ( function( $ ) { // Update the title. control.$el.on( 'input change', '.title', function updateTitle() { control.model.set({ - title: $.trim( $( this ).val() ) + title: $( this ).val().trim() }); }); // Update link_url attribute. control.$el.on( 'input change', '.link', function updateLinkUrl() { - var linkUrl = $.trim( $( this ).val() ), linkType = 'custom'; + var linkUrl = $( this ).val().trim(), linkType = 'custom'; if ( control.selectedAttachment.get( 'linkUrl' ) === linkUrl || control.selectedAttachment.get( 'link' ) === linkUrl ) { linkType = 'post'; } else if ( control.selectedAttachment.get( 'url' ) === linkUrl ) { diff --git a/src/js/media/views/embed/url.js b/src/js/media/views/embed/url.js index 21ac1a9203..e593b7bc4f 100644 --- a/src/js/media/views/embed/url.js +++ b/src/js/media/views/embed/url.js @@ -57,7 +57,8 @@ EmbedUrl = View.extend(/** @lends wp.media.view.EmbedUrl.prototype */{ }, url: function( event ) { - this.model.set( 'url', $.trim( event.target.value ) ); + var url = event.target.value || ''; + this.model.set( 'url', url.trim() ); } }); diff --git a/src/js/media/views/modal.js b/src/js/media/views/modal.js index 7253d5cd4d..42fc7c9f60 100644 --- a/src/js/media/views/modal.js +++ b/src/js/media/views/modal.js @@ -133,7 +133,7 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{ } // Pause current audio/video even after closing the modal. - $( '.mejs-pause button' ).click(); + $( '.mejs-pause button' ).trigger( 'click' ); // Enable page scrolling. $( 'body' ).removeClass( 'modal-open' ); @@ -155,7 +155,7 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{ // Fallback to the admin page main element. $( '#wpbody-content' ) .attr( 'tabindex', '-1' ) - .focus(); + .trigger( 'focus' ); } this.propagate('close'); diff --git a/src/js/media/views/uploader/inline.js b/src/js/media/views/uploader/inline.js index c6bc5fa068..57016aec49 100644 --- a/src/js/media/views/uploader/inline.js +++ b/src/js/media/views/uploader/inline.js @@ -134,7 +134,7 @@ UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype * this.controller.$uploaderToggler .attr( 'aria-expanded', 'false' ) // Move focus back to the toggle button when closing the uploader. - .focus(); + .trigger( 'focus' ); } }