Make WordPress Core

Changeset 43577


Ignore:
Timestamp:
08/19/2018 01:32:27 PM (6 years ago)
Author:
omarreiss
Message:

General: Explicitly assigns all JS globals to the window.

Many variables in the JavaScript were defined in the global scope without being explicitly assigned to the window. When built with Webpack, the code gets encapsulated in anonymous functions and those implicit globals get assigned to the wrong scope. This patch prevents that from happening.

Fixes #44371. See #43731.

Location:
trunk/src/js/_enqueues
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r43347 r43577  
    44
    55/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
    6 var showNotice, adminMenu, columns, validateForm, screenMeta;
     6/* global columns, screenMeta */
    77
    88/**
     
    2424 * @deprecated 3.3.0
    2525 */
    26 adminMenu = {
     26window.adminMenu = {
    2727    init : function() {},
    2828    fold : function() {},
     
    3333
    3434// Show/hide/save table columns.
    35 columns = {
     35window.columns = {
    3636
    3737    /**
     
    159159 * @returns {boolean} Returns true if all required fields are not an empty string.
    160160 */
    161 validateForm = function( form ) {
     161window.validateForm = function( form ) {
    162162    return !$( form )
    163163        .find( '.form-required' )
     
    179179 * @returns {void}
    180180 */
    181 showNotice = {
     181window.showNotice = {
    182182
    183183    /**
     
    220220 * @returns {void}
    221221 */
    222 screenMeta = {
     222window.screenMeta = {
    223223    element: null, // #screen-meta
    224224    toggles: null, // .screen-meta-toggle
  • trunk/src/js/_enqueues/admin/edit-comments.js

    r43347 r43577  
    44
    55/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
    6 var setCommentsList, theList, theExtraList, commentReply;
     6/* global commentReply, theExtraList, theList, setCommentsList */
    77
    88(function($) {
     
    189189    };
    190190
    191 setCommentsList = function() {
     191window.setCommentsList = function() {
    192192    var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
    193193        lastConfidentTime = 0;
     
    565565    };
    566566
    567     theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
    568     theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
     567    window.theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
     568    window.theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
    569569        .bind('wpListDelEnd', function(e, s){
    570570            var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
     
    575575};
    576576
    577 commentReply = {
     577window.commentReply = {
    578578    cid : '',
    579579    act : '',
  • trunk/src/js/_enqueues/admin/inline-edit-post.js

    r43347 r43577  
    66 */
    77
    8 /* global inlineEditL10n, ajaxurl, typenow */
     8/* global inlineEditL10n, ajaxurl, typenow, inlineEditPost */
    99
    1010window.wp = window.wp || {};
     
    2323 *
    2424 */
    25 var inlineEditPost;
    2625( function( $, wp ) {
    2726
    28     inlineEditPost = {
     27    window.inlineEditPost = {
    2928
    3029    /**
  • trunk/src/js/_enqueues/admin/inline-edit-tax.js

    r43347 r43577  
    55 */
    66
    7 /* global inlineEditL10n, ajaxurl */
     7/* global inlineEditL10n, ajaxurl, inlineEditTax */
    88
    99window.wp = window.wp || {};
     
    1818 *                         suffixed.
    1919 */
    20 var inlineEditTax;
    21 
    2220( function( $, wp ) {
    2321
    24 inlineEditTax = {
     22window.inlineEditTax = {
    2523
    2624    /**
  • trunk/src/js/_enqueues/admin/media-upload.js

    r43347 r43577  
    1313 */
    1414
    15 /* global tinymce, QTags */
    16 
    17 var wpActiveEditor, send_to_editor;
     15/* global tinymce, QTags, wpActiveEditor, tb_position */
    1816
    1917/**
     
    2927 *                         sent to the editor.
    3028 */
    31 send_to_editor = function( html ) {
     29window.send_to_editor = function( html ) {
    3230    var editor,
    3331        hasTinymce = typeof tinymce !== 'undefined',
     
    3836        if ( hasTinymce && tinymce.activeEditor ) {
    3937            editor = tinymce.activeEditor;
    40             wpActiveEditor = editor.id;
     38            window.wpActiveEditor = editor.id;
    4139        } else if ( ! hasQuicktags ) {
    4240            return false;
     
    6563};
    6664
    67 var tb_position;
    6865(function($) {
    6966    /**
     
    7875     *                     ThickBox anchors.
    7976     */
    80     tb_position = function() {
     77    window.tb_position = function() {
    8178        var tbWindow = $('#TB_window'),
    8279            width = $(window).width(),
  • trunk/src/js/_enqueues/admin/media.js

    r43347 r43577  
    1111 */
    1212
    13 /* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice */
    14 
    15 var findPosts;
     13/* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice, findPosts */
    1614
    1715( function( $ ){
    18     findPosts = {
     16    window.findPosts = {
    1917        /**
    2018         * Opens a dialog to attach media to a post.
  • trunk/src/js/_enqueues/admin/plugin-install.js

    r43347 r43577  
    55 */
    66
    7 /* global plugininstallL10n, tb_click, tb_remove */
    8 var tb_position;
     7/* global plugininstallL10n, tb_click, tb_remove, tb_position */
     8
    99jQuery( document ).ready( function( $ ) {
    1010
     
    1919        $body = $( document.body );
    2020
    21     tb_position = function() {
     21    window.tb_position = function() {
    2222        var width = $( window ).width(),
    2323            H = $( window ).height() - ( ( 792 < width ) ? 60 : 20 ),
  • trunk/src/js/_enqueues/admin/post.js

    r43347 r43577  
    66
    77 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
    8  /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply */
    9 
    10 var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
     8 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
     9 /* global WPSetThumbnailHTML, wptitlehint */
     10
    1111// Backwards compatibility: prevent fatal errors.
    12 makeSlugeditClickable = editPermalink = function(){};
     12window.makeSlugeditClickable = window.editPermalink = function(){};
    1313
    1414// Make sure the wp object exists.
     
    2525     * @namespace commentsBox
    2626     */
    27     commentsBox = {
     27    window.commentsBox = {
    2828        // Comment offset to use when fetching new comments.
    2929        st : 0,
     
    109109     * @global
    110110     */
    111     WPSetThumbnailHTML = function(html){
     111    window.WPSetThumbnailHTML = function(html){
    112112        $('.inside', '#postimagediv').html(html);
    113113    };
     
    120120     * @global
    121121     */
    122     WPSetThumbnailID = function(id){
     122    window.WPSetThumbnailID = function(id){
    123123        var field = $('input[value="_thumbnail_id"]', '#list-table');
    124124        if ( field.length > 0 ) {
     
    134134     * @global
    135135     */
    136     WPRemoveThumbnail = function(nonce){
     136    window.WPRemoveThumbnail = function(nonce){
    137137        $.post(ajaxurl, {
    138138            action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
     
    10491049     * @returns void
    10501050     */
    1051     wptitlehint = function(id) {
     1051    window.wptitlehint = function(id) {
    10521052        id = id || 'title';
    10531053
  • trunk/src/js/_enqueues/admin/postbox.js

    r43347 r43577  
    88 */
    99
    10 /* global ajaxurl, postBoxL10n */
    11 
    12 /**
    13  * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
    14  * around the content on the edit page.
    15  *
    16  * @since 2.7.0
    17  *
    18  * @namespace postboxes
    19  *
    20  * @type {Object}
    21  */
    22 var postboxes;
     10/* global ajaxurl, postBoxL10n, postboxes */
    2311
    2412(function($) {
    2513    var $document = $( document );
    2614
    27     postboxes = {
     15    /**
     16     * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
     17     * around the content on the edit page.
     18     *
     19     * @since 2.7.0
     20     *
     21     * @namespace postboxes
     22     *
     23     * @type {Object}
     24     */
     25    window.postboxes = {
    2826
    2927        /**
  • trunk/src/js/_enqueues/admin/set-post-thumbnail.js

    r43347 r43577  
    66/* exported WPSetAsThumbnail */
    77
    8 function WPSetAsThumbnail( id, nonce ) {
     8window.WPSetAsThumbnail = function( id, nonce ) {
    99    var $link = jQuery('a#wp-post-thumbnail-' + id);
    1010
     
    2626    }
    2727    );
    28 }
     28};
  • trunk/src/js/_enqueues/admin/tags-box.js

    r43347 r43577  
    44
    55/* jshint curly: false, eqeqeq: false */
    6 /* global ajaxurl */
    7 
    8 var tagBox, array_unique_noempty;
     6/* global ajaxurl, tagBox, array_unique_noempty */
    97
    108( function( $ ) {
     
    2523     * @return {Array} A new array containing only the unique items.
    2624     */
    27     array_unique_noempty = function( array ) {
     25    window.array_unique_noempty = function( array ) {
    2826        var out = [];
    2927
     
    5048     * @global
    5149     */
    52     tagBox = {
     50    window.tagBox = {
    5351        /**
    5452         * Cleans up tags by removing redundant characters.
  • trunk/src/js/_enqueues/admin/widgets.js

    r43347 r43577  
    33 */
    44
    5 /* global ajaxurl, isRtl */
    6 var wpWidgets;
     5/* global ajaxurl, isRtl, wpWidgets */
     6
    77(function($) {
    88    var $document = $( document );
    99
    10 wpWidgets = {
     10window.wpWidgets = {
    1111    /**
    1212     * A closed Sidebar that gets a Widget dragged over it.
  • trunk/src/js/_enqueues/lib/ajax-response.js

    r43347 r43577  
    33 */
    44
    5 var wpAjax = jQuery.extend( {
     5 /* global wpAjax */
     6
     7window.wpAjax = jQuery.extend( {
    68    unserialize: function( s ) {
    79        var r = {}, q, pp, i, p;
  • trunk/src/js/_enqueues/lib/comment-reply.js

    r43347 r43577  
    99 * @type {Object}
    1010 */
    11 var addComment;
    12 addComment = ( function( window ) {
     11window.addComment = ( function( window ) {
    1312    // Avoid scope lookups on commonly used variables.
    1413    var document = window.document;
  • trunk/src/js/_enqueues/lib/cookies.js

    r43347 r43577  
    55 */
    66
    7 /* global userSettings */
     7/* global userSettings, getAllUserSettings, wpCookies, setUserSetting */
    88/* exported getUserSetting, setUserSetting, deleteUserSetting */
    99
    10 var wpCookies = {
     10window.wpCookies = {
    1111// The following functions are from Cookie.js class in TinyMCE 3, Moxiecode, used under LGPL.
    1212
     
    140140
    141141// Returns the value as string. Second arg or empty string is returned when value is not set.
    142 function getUserSetting( name, def ) {
     142window.getUserSetting = function( name, def ) {
    143143    var settings = getAllUserSettings();
    144144
     
    152152
    153153    return '';
    154 }
     154};
    155155
    156156// Both name and value must be only ASCII letters, numbers or underscore
    157157// and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
    158158// The value is converted and stored as string.
    159 function setUserSetting( name, value, _del ) {
     159window.setUserSetting = function( name, value, _del ) {
    160160    if ( 'object' !== typeof userSettings ) {
    161161        return false;
     
    187187
    188188    return name;
    189 }
    190 
    191 function deleteUserSetting( name ) {
     189};
     190
     191window.deleteUserSetting = function( name ) {
    192192    return setUserSetting( name, '', 1 );
    193 }
     193};
    194194
    195195// Returns all settings as js object.
    196 function getAllUserSettings() {
     196window.getAllUserSettings = function() {
    197197    if ( 'object' !== typeof userSettings ) {
    198198        return {};
     
    200200
    201201    return wpCookies.getHash( 'wp-settings-' + userSettings.uid ) || {};
    202 }
     202};
  • trunk/src/js/_enqueues/lib/gallery.js

    r43347 r43577  
    33 */
    44
    5 /* global unescape, getUserSetting, setUserSetting */
     5/* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
    66
    77jQuery(document).ready(function($) {
     
    8989});
    9090
    91 jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup
     91jQuery(window).unload( function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup
    9292
    9393/* gallery settings */
    94 var tinymce = null, tinyMCE, wpgallery;
    95 
    96 wpgallery = {
     94window.tinymce = null;
     95
     96window.wpgallery = {
    9797    mcemode : false,
    9898    editor : {},
     
    124124
    125125        // Find window & API
    126         tinymce = w.tinymce;
    127         tinyMCE = w.tinyMCE;
     126        window.tinymce = w.tinymce;
     127        window.tinyMCE = w.tinyMCE;
    128128        t.editor = tinymce.EditorManager.activeEditor;
    129129
  • trunk/src/js/_enqueues/lib/link.js

    r43347 r43577  
    33 */
    44
    5 var wpLink;
     5 /* global wpLink */
    66
    77( function( $, wpLinkL10n, wp ) {
     
    1717    }
    1818
    19     wpLink = {
     19    window.wpLink = {
    2020        timeToTriggerRiver: 150,
    2121        minRiverAJAXDuration: 200,
  • trunk/src/js/_enqueues/lib/nav-menu.js

    r43347 r43577  
    1010 */
    1111
    12 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl */
    13 
    14 /**
    15  * Contains all the functions to handle WordPress navigation menus administration.
    16  *
    17  * @namespace
    18  */
    19 var wpNavMenu;
     12/* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl, wpNavMenu */
    2013
    2114(function($) {
     
    2316    var api;
    2417
    25     api = wpNavMenu = {
     18    /**
     19     * Contains all the functions to handle WordPress navigation menus administration.
     20     *
     21     * @namespace wpNavMenu
     22     */
     23    api = window.wpNavMenu = {
    2624
    2725        options : {
  • trunk/src/js/_enqueues/lib/quicktags.js

    r43347 r43577  
    2525// http://www.alexking.org/
    2626
    27 /* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, prompt */
    28 
    29 var QTags, edCanvas,
    30     edButtons = [];
     27/* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, prompt, edButtons */
     28
     29window.edButtons = [];
    3130
    3231/* jshint ignore:start */
     
    3736 * Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors.
    3837 */
    39 var edAddTag = function(){},
    40 edCheckOpenTags = function(){},
    41 edCloseAllTags = function(){},
    42 edInsertImage = function(){},
    43 edInsertLink = function(){},
    44 edInsertTag = function(){},
    45 edLink = function(){},
    46 edQuickLink = function(){},
    47 edRemoveTag = function(){},
    48 edShowButton = function(){},
    49 edShowLinks = function(){},
    50 edSpell = function(){},
    51 edToolbar = function(){};
     38window.edAddTag = function(){},
     39window.edCheckOpenTags = function(){},
     40window.edCloseAllTags = function(){},
     41window.edInsertImage = function(){},
     42window.edInsertLink = function(){},
     43window.edInsertTag = function(){},
     44window.edLink = function(){},
     45window.edQuickLink = function(){},
     46window.edRemoveTag = function(){},
     47window.edShowButton = function(){},
     48window.edShowLinks = function(){},
     49window.edSpell = function(){},
     50window.edToolbar = function(){};
    5251
    5352/**
    5453 * Initialize new instance of the Quicktags editor
    5554 */
    56 function quicktags(settings) {
     55window.quicktags = function(settings) {
    5756    return new QTags(settings);
    5857}
     
    6463 * @see QTags.insertContent()
    6564 */
    66 function edInsertContent(bah, txt) {
     65window.edInsertContent = function(bah, txt) {
    6766    return QTags.insertContent(txt);
    6867}
     
    7473 * @see QTags.addButton()
    7574 */
    76 function edButton(id, display, tagStart, tagEnd, access) {
     75window.edButton = function(id, display, tagStart, tagEnd, access) {
    7776    return QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 );
    7877}
     
    154153            zeroise( now.getUTCSeconds() ) +
    155154            '+00:00';
    156     })(),
    157     qt;
    158 
    159     qt = QTags = function(settings) {
     155    })();
     156
     157    var qt = window.QTags = function(settings) {
    160158        if ( typeof(settings) === 'string' ) {
    161159            settings = {id: settings};
     
    181179        if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) {
    182180            // back compat hack :-(
    183             edCanvas = canvas;
     181            window.edCanvas = canvas;
    184182            toolbar_id = 'ed_toolbar';
    185183        } else {
  • trunk/src/js/_enqueues/wp/dashboard.js

    r43347 r43577  
    33 */
    44
    5 /* global pagenow, ajaxurl, postboxes, wpActiveEditor:true */
    6 var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
     5/* global pagenow, ajaxurl, postboxes, wpActiveEditor:true, ajaxWidgets */
     6/* global ajaxPopulateWidgets, quickPressLoad,  */
    77window.wp = window.wp || {};
    88
     
    6262     * @global
    6363     */
    64     ajaxWidgets = ['dashboard_primary'];
     64    window.ajaxWidgets = ['dashboard_primary'];
    6565
    6666    /**
     
    7575     * @returns {void}
    7676     */
    77     ajaxPopulateWidgets = function(el) {
     77    window.ajaxPopulateWidgets = function(el) {
    7878        /**
    7979         * Fetch the latest representation of the widget via Ajax and show it.
     
    130130     * @returns {void}
    131131     */
    132     quickPressLoad = function() {
     132    window.quickPressLoad = function() {
    133133        var act = $('#quickpost-action'), t;
    134134
     
    211211        autoResizeTextarea();
    212212    };
    213     quickPressLoad();
     213    window.quickPressLoad();
    214214
    215215    // Enable the dragging functionality of the widgets.
  • trunk/src/js/_enqueues/wp/password-strength-meter.js

    r43347 r43577  
    66window.wp = window.wp || {};
    77
    8 var passwordStrength;
    98(function($){
    109
     
    119118     * @type {wp.passwordStrength.meter}
    120119     */
    121     passwordStrength = wp.passwordStrength.meter;
     120    window.passwordStrength = wp.passwordStrength.meter;
    122121})(jQuery);
  • trunk/src/js/_enqueues/wp/theme.js

    r43347 r43577  
    33 */
    44
    5 /* global _wpThemeSettings, confirm */
     5/* global _wpThemeSettings, confirm, tb_position */
    66window.wp = window.wp || {};
    77
     
    20422042
    20432043// Align theme browser thickbox
    2044 var tb_position;
    20452044jQuery(document).ready( function($) {
    2046     tb_position = function() {
     2045    window.tb_position = function() {
    20472046        var tbWindow = $('#TB_window'),
    20482047            width = $(window).width(),
Note: See TracChangeset for help on using the changeset viewer.