Make WordPress Core

Changeset 42393


Ignore:
Timestamp:
12/14/2017 02:10:11 PM (9 years ago)
Author:
atimmer
Message:

Docs: Improve JS Docs for wp-admin/js/dashboard.js.

Props jipmoors, andizer, ireneyoast, boblinthorst.
Fixes #42831.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/dashboard.js

    r41978 r42393  
    33window.wp = window.wp || {};
    44
     5/**
     6 * Initializes the dashboard widget functionality.
     7 *
     8 * @since 2.7.0
     9 */
    510jQuery(document).ready( function($) {
    611        var welcomePanel = $( '#welcome-panel' ),
     
    813                updateWelcomePanel;
    914
     15        /**
     16         * Saves 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, {
     
    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();
     
    2743        });
    2844
     45        // Set welcome panel visibility based on Welcome Option checkbox value.
    2946        welcomePanelHide.click( function() {
    3047                welcomePanel.toggleClass('hidden', ! this.checked );
     
    3249        });
    3350
    34         // These widgets are sometimes populated via ajax
     51        /**
     52         * These widgets can be populated via ajax.
     53         *
     54         * @since 2.7.0
     55         *
     56         * @type {string[]}
     57         *
     58         * @global
     59         */
    3560        ajaxWidgets = ['dashboard_primary'];
    3661
     62        /**
     63         * Triggers widget updates via AJAX.
     64         *
     65         * @since 2.7.0
     66         *
     67         * @global
     68         *
     69         * @param {string} el Optional. Widget to fetch or none to update all.
     70         *
     71         * @returns {void}
     72         */
    3773        ajaxPopulateWidgets = function(el) {
     74                /**
     75                 * Fetch the latest representation of the widget via Ajax and show it.
     76                 *
     77                 * @param {number} i Number of half-seconds to use as the timeout.
     78                 * @param {string} id ID of the element which is going to be checked for changes.
     79                 *
     80                 * @returns {void}
     81                 */
    3882                function show(i, id) {
    3983                        var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
     84                        // If the element is found in the dom, queue to load latest representation.
    4085                        if ( e.length ) {
    4186                                p = e.parent();
    4287                                setTimeout( function(){
     88                                        // Request the widget content.
    4389                                        p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
     90                                                // Hide the parent and slide it out for visual fancyness.
    4491                                                p.hide().slideDown('normal', function(){
    4592                                                        $(this).css('display', '');
     
    5097                }
    5198
     99                // If we have received a specific element to fetch, check if it is valid.
    52100                if ( el ) {
    53101                        el = el.toString();
     102                        // If the element is available as AJAX widget, show it.
    54103                        if ( $.inArray(el, ajaxWidgets) !== -1 ) {
     104                                // Show element without any delay.
    55105                                show(0, el);
    56106                        }
    57107                } else {
     108                        // Walk through all ajaxWidgets, loading them after each other.
    58109                        $.each( ajaxWidgets, show );
    59110                }
    60111        };
     112
     113        // Initially populate ajax widgets.
    61114        ajaxPopulateWidgets();
    62115
     116        // Register ajax widgets as postbox toggles.
    63117        postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
    64118
    65         /* QuickPress */
     119        /**
     120         * Control the Quick Press (Quick Draft) widget.
     121         *
     122         * @since 2.7.0
     123         *
     124         * @global
     125         *
     126         * @returns {void}
     127         */
    66128        quickPressLoad = function() {
    67129                var act = $('#quickpost-action'), t;
    68130
     131                // Enable the submit buttons.
    69132                $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );
    70133
    71134                t = $('#quick-press').submit( function( e ) {
    72135                        e.preventDefault();
     136
     137                        // Show a spinner.
    73138                        $('#dashboard_quick_press #publishing-action .spinner').show();
     139
     140                        // Disable the submit button to prevent duplicate submissions.
    74141                        $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
    75142
     143                        // Post the entered data to save it.
    76144                        $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
    77145                                // Replace the form, and prepend the published post.
     
    80148                                quickPressLoad();
    81149                                highlightLatestPost();
     150
     151                                // Focus the title to allow for quickly drafting another post.
    82152                                $('#title').focus();
    83153                        });
    84154
     155                        /**
     156                         * Highlights the latest post for one second.
     157                         *
     158                         * @returns {void}
     159                         */
    85160                        function highlightLatestPost () {
    86161                                var latestPost = $('.drafts ul li').first();
     
    92167                } );
    93168
     169                // Change the QuickPost action to the publish value.
    94170                $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
    95171
     172                /**
     173                 * Adds accessibility context to inputs.
     174                 *
     175                 * Use the 'screen-reader-text' class to hide the label when entering a value.
     176                 * Apply it when the input is not empty or the input has focus.
     177                 *
     178                 * @returns {void}
     179                 */
    96180                $('#title, #tags-input, #content').each( function() {
    97181                        var input = $(this), prompt = $('#' + this.id + '-prompt-text');
     
    125209        quickPressLoad();
    126210
     211        // Enable the dragging functionality of the widgets.
    127212        $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' );
    128213
     214        /**
     215         * Adjust the height of the textarea based on the content.
     216         *
     217         * @since 3.6.0
     218         *
     219         * @returns {void}
     220         */
    129221        function autoResizeTextarea() {
     222                // When IE8 or older is used to render this document, exit.
    130223                if ( document.documentMode && document.documentMode < 9 ) {
    131224                        return;
     
    138231                        editor = $('#content'),
    139232                        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.
     233                        /*
     234                         * 100px roughly accounts for browser chrome and allows the
     235                         * save draft button to show on-screen at the same time.
     236                         */
    142237                        editorMaxHeight = $(window).height() - 100;
    143238
    144                 // Match up textarea and clone div as much as possible.
    145                 // Padding cannot be reliably retrieved using shorthand in all browsers.
     239                /*
     240                 * Match up textarea and clone div as much as possible.
     241                 * Padding cannot be reliably retrieved using shorthand in all browsers.
     242                 */
    146243                clone.css({
    147244                        'font-family': editor.css('font-family'),
     
    157254                });
    158255
    159                 // propertychange is for IE < 9
     256                // The 'propertychange' is used in IE < 9.
    160257                editor.on('focus input propertychange', function() {
    161258                        var $this = $(this),
    162                                 // &nbsp; is to ensure that the height of a final trailing newline is included.
     259                                // Add a non-breaking space to ensure that the height of a trailing newline is
     260                                // included.
    163261                                textareaContent = $this.val() + '&nbsp;',
    164                                 // 2px is for border-top & border-bottom
     262                                // Add 2px to compensate for border-top & border-bottom.
    165263                                cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
    166264
    167                         // Default to having scrollbars
     265                        // Default to show a vertical scrollbar, if needed.
    168266                        editor.css('overflow-y', 'auto');
    169267
    170                         // Only change the height if it has indeed changed and both heights are below the max.
     268                        // Only change the height if it has changed and both heights are below the max.
    171269                        if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
    172270                                return;
    173271                        }
    174272
    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.
     273                        /*
     274                         * Don't allow editor to exceed the height of the window.
     275                         * This is also bound in CSS to a max-height of 1300px to be extra safe.
     276                         */
    177277                        if ( cloneHeight > editorMaxHeight ) {
    178278                                editorHeight = editorMaxHeight;
     
    181281                        }
    182282
    183                         // No scrollbars as we change height, not for IE < 9
     283                        // Disable scrollbars because we adjust the height to the content.
    184284                        editor.css('overflow', 'hidden');
    185285
     
    196296                app;
    197297
    198         app = window.wp.communityEvents = {
     298        /**
     299         * Global Community Events namespace.
     300         *
     301         * @since 4.8.0
     302         *
     303         * @memberOf wp
     304         * @namespace wp.communityEvents
     305         */
     306        app = window.wp.communityEvents = /** @lends wp.communityEvents */{
    199307                initialized: false,
    200308                model: null,
     
    204312                 *
    205313                 * @since 4.8.0
     314                 *
     315                 * @returns {void}
    206316                 */
    207317                init: function() {
     
    234344                        $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm );
    235345
     346                        /**
     347                         * Filters events based on entered location.
     348                         *
     349                         * @returns {void}
     350                         */
    236351                        $container.on( 'submit', '.community-events-form', function( event ) {
    237352                                var location = $.trim( $( '#community-events-location' ).val() );
     
    268383                 * @param {event|string} action 'show' or 'hide' to specify a state;
    269384                 *                              or an event object to flip between states.
     385                 *
     386                 * @returns {void}
    270387                 */
    271388                toggleLocationForm: function( action ) {
     
    310427                 * @since 4.8.0
    311428                 *
    312                  * @param {object} requestParams
     429                 * @param {Object} requestParams REST API Request parameters object.
     430                 *
     431                 * @returns {void}
    313432                 */
    314433                getEvents: function( requestParams ) {
     
    363482                 * @param {string} initiatedBy    'user' to indicate that this was triggered manually by the user;
    364483                 *                                'app' to indicate it was triggered automatically by the app itself.
     484                 *
     485                 * @returns {void}
    365486                 */
    366487                renderEventsTemplate: function( templateParams, initiatedBy ) {
Note: See TracChangeset for help on using the changeset viewer.