Make WordPress Core

Changeset 42393

Timestamp:
12/14/2017 02:10:11 PM (7 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
     7
     8
     9
    510jQuery(document).ready( function($) {
    611    var welcomePanel = $( '#welcome-panel' ),
     
    813        updateWelcomePanel;
    914
     15
     16
     17
     18
     19
     20
     21
     22
     23
    1024    updateWelcomePanel = function( visible ) {
    1125        $.post( ajaxurl, {
     
    1630    };
    1731
     32
    1833    if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
    1934        welcomePanel.removeClass('hidden');
    2035    }
    2136
     37
    2238    $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) {
    2339        e.preventDefault();
     
    2743    });
    2844
     45
    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
     64
     65
     66
     67
     68
     69
     70
     71
     72
    3773    ajaxPopulateWidgets = function(el) {
     74
     75
     76
     77
     78
     79
     80
     81
    3882        function show(i, id) {
    3983            var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
     84
    4085            if ( e.length ) {
    4186                p = e.parent();
    4287                setTimeout( function(){
     88
    4389                    p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
     90
    4491                        p.hide().slideDown('normal', function(){
    4592                            $(this).css('display', '');
     
    5097        }
    5198
     99
    52100        if ( el ) {
    53101            el = el.toString();
     102
    54103            if ( $.inArray(el, ajaxWidgets) !== -1 ) {
     104
    55105                show(0, el);
    56106            }
    57107        } else {
     108
    58109            $.each( ajaxWidgets, show );
    59110        }
    60111    };
     112
     113
    61114    ajaxPopulateWidgets();
    62115
     116
    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
    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
    73138            $('#dashboard_quick_press #publishing-action .spinner').show();
     139
     140
    74141            $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
    75142
     143
    76144            $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
    77145                // Replace the form, and prepend the published post.
     
    80148                quickPressLoad();
    81149                highlightLatestPost();
     150
     151
    82152                $('#title').focus();
    83153            });
    84154
     155
     156
     157
     158
     159
    85160            function highlightLatestPost () {
    86161                var latestPost = $('.drafts ul li').first();
     
    92167        } );
    93168
     169
    94170        $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
    95171
     172
     173
     174
     175
     176
     177
     178
     179
    96180        $('#title, #tags-input, #content').each( function() {
    97181            var input = $(this), prompt = $('#' + this.id + '-prompt-text');
     
    125209    quickPressLoad();
    126210
     211
    127212    $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' );
    128213
     214
     215
     216
     217
     218
     219
     220
    129221    function autoResizeTextarea() {
     222
    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        //
    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                //
    165263                cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
    166264
    167             // Default to having scrollbars
     265            // Default to
    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            //
    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
    206316         */
    207317        init: function() {
     
    234344            $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm );
    235345
     346
     347
     348
     349
     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
    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
    365486         */
    366487        renderEventsTemplate: function( templateParams, initiatedBy ) {
Note: See TracChangeset for help on using the changeset viewer.