Make WordPress Core

Ticket #42831: dashboard.js.diff

File dashboard.js.diff, 11.4 KB (added by jipmoors, 6 years ago)
  • src/wp-admin/js/dashboard.js

    diff --git src/wp-admin/js/dashboard.js src/wp-admin/js/dashboard.js
    index a6b56c37ef..c180623fea 100644
     
    22var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
    33window.wp = window.wp || {};
    44
     5/**
     6 * Dashboard widget functionality.
     7 *
     8 * @since 2.7.0
     9 */
    510jQuery(document).ready( function($) {
    611        var welcomePanel = $( '#welcome-panel' ),
    712                welcomePanelHide = $('#wp_welcome_panel-hide'),
    813                updateWelcomePanel;
    914
     15        /**
     16         * Save the visibility of the welcome panel.
     17         *
     18         * @since 3.3.0
     19         *
     20         * @param {boolean} visible Should it be visible or not.
     21         *
     22         * @returns {void}
     23         */
    1024        updateWelcomePanel = function( visible ) {
    1125                $.post( ajaxurl, {
    1226                        action: 'update-welcome-panel',
    jQuery(document).ready( function($) { 
    1529                });
    1630        };
    1731
     32        // Unhide the welcome panel if the Welcome Option checkbox is checked.
    1833        if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
    1934                welcomePanel.removeClass('hidden');
    2035        }
    2136
     37        // Hide the welcome panel when the dismiss button or close button is clicked.
    2238        $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) {
    2339                e.preventDefault();
    2440                welcomePanel.addClass('hidden');
    jQuery(document).ready( function($) { 
    2642                $('#wp_welcome_panel-hide').prop('checked', false);
    2743        });
    2844
     45        // Set welcome panel visibility based on Welcome Option checkbox value.
    2946        welcomePanelHide.click( function() {
    3047                welcomePanel.toggleClass('hidden', ! this.checked );
    3148                updateWelcomePanel( this.checked ? 1 : 0 );
    3249        });
    3350
    34         // These widgets are sometimes populated via ajax
     51        // These widgets can be populated via ajax.
    3552        ajaxWidgets = ['dashboard_primary'];
    3653
     54        /**
     55         * Trigger widget updates via AJAX.
     56         *
     57         * @since 2.7.0
     58         *
     59         * @param {string} el Optional. Widget to fetch or none to update all.
     60         *
     61         * @returns {void}
     62         */
    3763        ajaxPopulateWidgets = function(el) {
     64                /**
     65                 * Fetch the latest representation of the widget via Ajax and show it.
     66                 *
     67                 * @param {int} i Number of half-seconds to use as the timeout.
     68                 * @param {string} id ID of the element which is going to be checked for changes.
     69                 *
     70                 * @returns {void}
     71                 */
    3872                function show(i, id) {
    3973                        var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
     74                        // If the element is found in the dom, queue to load latest representation.
    4075                        if ( e.length ) {
    4176                                p = e.parent();
    4277                                setTimeout( function(){
     78                                        // Request the widget content.
    4379                                        p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
     80                                                // Hide the parent and slide it out for visual fancyness.
    4481                                                p.hide().slideDown('normal', function(){
    4582                                                        $(this).css('display', '');
    4683                                                });
    jQuery(document).ready( function($) { 
    4986                        }
    5087                }
    5188
     89                // If we have received a specific element to fetch, check if it is valid.
    5290                if ( el ) {
    5391                        el = el.toString();
     92                        // If the element is available as AJAX widget, show it.
    5493                        if ( $.inArray(el, ajaxWidgets) !== -1 ) {
     94                                // Show element without any delay.
    5595                                show(0, el);
    5696                        }
    5797                } else {
     98                        // Walk through all ajaxWidgets, loading them after each other.
    5899                        $.each( ajaxWidgets, show );
    59100                }
    60101        };
     102
     103        // Initially populate ajax widgets.
    61104        ajaxPopulateWidgets();
    62105
     106        // Register ajax widgets as postbox toggles.
    63107        postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
    64108
    65         /* QuickPress */
     109        /**
     110         * Control the Quick Press (Quick Draft) widget.
     111         *
     112         * @since 2.7.0
     113         *
     114         * @returns {void}
     115         */
    66116        quickPressLoad = function() {
    67117                var act = $('#quickpost-action'), t;
    68118
     119                // Enable the submit buttons.
    69120                $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );
    70121
    71122                t = $('#quick-press').submit( function( e ) {
    72123                        e.preventDefault();
     124
     125                        // Show a spinner.
    73126                        $('#dashboard_quick_press #publishing-action .spinner').show();
     127
     128                        // Disable the submit button to prevent duplicate submissions.
    74129                        $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
    75130
     131                        // Post the entered data to save it.
    76132                        $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
    77133                                // Replace the form, and prepend the published post.
    78134                                $('#dashboard_quick_press .inside').html( data );
    79135                                $('#quick-press').removeClass('initial-form');
    80136                                quickPressLoad();
    81137                                highlightLatestPost();
     138
     139                                // Focus the title to allow for quickly drafting another post.
    82140                                $('#title').focus();
    83141                        });
    84142
     143                        /**
     144                         * @summary Highlights the latest post for one second.
     145                         *
     146                         * @returns {void}
     147                         */
    85148                        function highlightLatestPost () {
    86149                                var latestPost = $('.drafts ul li').first();
    87150                                latestPost.css('background', '#fffbe5');
    jQuery(document).ready( function($) { 
    91154                        }
    92155                } );
    93156
     157                // Change the QuickPost action to the publish value.
    94158                $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
    95159
     160                /**
     161                 * Use the 'screen-reader-text' class to hide the label when entering a value.
     162                 * Apply it when the input is not empty or the input has focus.
     163                 *
     164                 * @summary Adds accessibility context to inputs.
     165                 *
     166                 * @returns {void}
     167                 */
    96168                $('#title, #tags-input, #content').each( function() {
    97169                        var input = $(this), prompt = $('#' + this.id + '-prompt-text');
    98170
    jQuery(document).ready( function($) { 
    124196        };
    125197        quickPressLoad();
    126198
     199        // Enable the dragging functionality of the widgets.
    127200        $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' );
    128201
     202        /**
     203         * Adjust the height of the textarea based on the content.
     204         *
     205         * @since 3.6.0
     206         *
     207         * @returns {void}
     208         */
    129209        function autoResizeTextarea() {
     210                // When IE8 or older is used to render this document, exit.
    130211                if ( document.documentMode && document.documentMode < 9 ) {
    131212                        return;
    132213                }
    jQuery(document).ready( function($) { 
    137218                var clone = $('.quick-draft-textarea-clone'),
    138219                        editor = $('#content'),
    139220                        editorHeight = editor.height(),
    140                         // 100px roughly accounts for browser chrome and allows the
    141                         // save draft button to show on-screen at the same time.
     221                        /*
     222                         * 100px roughly accounts for browser chrome and allows the
     223                         * save draft button to show on-screen at the same time.
     224                         */
    142225                        editorMaxHeight = $(window).height() - 100;
    143226
    144                 // Match up textarea and clone div as much as possible.
    145                 // Padding cannot be reliably retrieved using shorthand in all browsers.
     227                /*
     228                 * Match up textarea and clone div as much as possible.
     229                 * Padding cannot be reliably retrieved using shorthand in all browsers.
     230                 */
    146231                clone.css({
    147232                        'font-family': editor.css('font-family'),
    148233                        'font-size':   editor.css('font-size'),
    jQuery(document).ready( function($) { 
    156241                        'display': 'none'
    157242                });
    158243
    159                 // propertychange is for IE < 9
     244                // The 'propertychange' is used in IE < 9.
    160245                editor.on('focus input propertychange', function() {
    161246                        var $this = $(this),
    162                                 // &nbsp; is to ensure that the height of a final trailing newline is included.
     247                                // Add a non-breaking space to ensure that the height of a trailing newline is included.
    163248                                textareaContent = $this.val() + '&nbsp;',
    164                                 // 2px is for border-top & border-bottom
     249                                // Add 2px to compensate for border-top & border-bottom.
    165250                                cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
    166251
    167                         // Default to having scrollbars
     252                        // Default to show a vertical scrollbar, if needed.
    168253                        editor.css('overflow-y', 'auto');
    169254
    170                         // Only change the height if it has indeed changed and both heights are below the max.
     255                        // Only change the height if it has changed and both heights are below the max.
    171256                        if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
    172257                                return;
    173258                        }
    174259
    175                         // Don't allow editor to exceed height of window.
    176                         // This is also bound in CSS to a max-height of 1300px to be extra safe.
     260                        /*
     261                         * Don't allow editor to exceed the height of the window.
     262                         * This is also bound in CSS to a max-height of 1300px to be extra safe.
     263                         */
    177264                        if ( cloneHeight > editorMaxHeight ) {
    178265                                editorHeight = editorMaxHeight;
    179266                        } else {
    180267                                editorHeight = cloneHeight;
    181268                        }
    182269
    183                         // No scrollbars as we change height, not for IE < 9
     270                        // Disable scrollbars because we adjust the height to the content.
    184271                        editor.css('overflow', 'hidden');
    185272
    186273                        $this.css('height', editorHeight + 'px');
    jQuery( function( $ ) { 
    195282        var communityEventsData = window.communityEventsData || {},
    196283                app;
    197284
     285        /**
     286         * Global Community Events class.
     287         *
     288         * @since 4.8.0
     289         *
     290         * @global
     291         * @class
     292         */
    198293        app = window.wp.communityEvents = {
    199294                initialized: false,
    200295                model: null,
    jQuery( function( $ ) { 
    203298                 * Initializes the wp.communityEvents object.
    204299                 *
    205300                 * @since 4.8.0
     301                 *
     302                 * @returns {void}
    206303                 */
    207304                init: function() {
    208305                        if ( app.initialized ) {
    jQuery( function( $ ) { 
    233330
    234331                        $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm );
    235332
     333                        /**
     334                         * Filter events based on entered location.
     335                         *
     336                         * @returns {void}
     337                         */
    236338                        $container.on( 'submit', '.community-events-form', function( event ) {
    237339                                var location = $.trim( $( '#community-events-location' ).val() );
    238340
    jQuery( function( $ ) { 
    267369                 *
    268370                 * @param {event|string} action 'show' or 'hide' to specify a state;
    269371                 *                              or an event object to flip between states.
     372                 *
     373                 * @returns {void}
    270374                 */
    271375                toggleLocationForm: function( action ) {
    272376                        var $toggleButton = $( '.community-events-toggle-location' ),
    jQuery( function( $ ) { 
    309413                 *
    310414                 * @since 4.8.0
    311415                 *
    312                  * @param {object} requestParams
     416                 * @param {object} requestParams REST API Request parameters object.
     417                 *
     418                 * @returns {void}
    313419                 */
    314420                getEvents: function( requestParams ) {
    315421                        var initiatedBy,
    jQuery( function( $ ) { 
    362468                 * @param {Object} templateParams The various parameters that will get passed to wp.template.
    363469                 * @param {string} initiatedBy    'user' to indicate that this was triggered manually by the user;
    364470                 *                                'app' to indicate it was triggered automatically by the app itself.
     471                 *
     472                 * @returns {void}
    365473                 */
    366474                renderEventsTemplate: function( templateParams, initiatedBy ) {
    367475                        var template,
  • src/wp-includes/class-wp-comment-query.php

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index 34255953f5..cdbe0d7792 100644
    class WP_Comment_Query { 
    471471         * @since 4.4.0
    472472         *
    473473         * @global wpdb $wpdb WordPress database abstraction object.
    474          *
    475          * @return int|array A single count of comment IDs if a count query. An array of comment IDs if a full query.
    476474         */
    477475        protected function get_comment_ids() {
    478476                global $wpdb;
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index b50772b99c..17e3fed1cb 100644
    if ( ! function_exists( 'wp_rand' ) ) : 
    23582358         *
    23592359         * @global string $rnd_value
    23602360         * @staticvar string $seed
    2361          * @staticvar bool $use_random_int_functionality
     2361         * @staticvar bool $external_rand_source_available
    23622362         *
    23632363         * @param int $min Lower limit for the generated number
    23642364         * @param int $max Upper limit for the generated number