Make WordPress Core

Ticket #37365: document-postbox.patch

File document-postbox.patch, 7.7 KB (added by atimmer, 10 years ago)
  • src/wp-admin/js/postbox.js

    From b4ea7855bc47eac2a7ad39a4f93a46731feed689 Mon Sep 17 00:00:00 2001
    From: Anton Timmermans <email@atimmer.com>
    Date: Thu, 7 Jul 2016 16:44:45 +0200
    Subject: [PATCH 1/3] Add documentation to wp-admin/js/postbox.js
    
    ---
     src/wp-admin/js/postbox.js | 105 +++++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 105 insertions(+)
    
    diff --git a/src/wp-admin/js/postbox.js b/src/wp-admin/js/postbox.js
    index a8222ee..74f5def 100644
    a b  
    11/* global ajaxurl, postBoxL10n */
    22
     3/**
     4 * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
     5 * around the content on the edit page.
     6 *
     7 * @namespace postboxes
     8 *
     9 * @type {Object}
     10 */
    311var postboxes;
    412
    513(function($) {
    614        var $document = $( document );
    715
    816        postboxes = {
     17
     18                /**
     19                 * Handles a click on either the postbox heading or the postbox open/close icon. Opens or closes the postbox.
     20                 * Expects this to equal the clicked element.
     21                 *
     22                 * Triggers postboxes.pbshow if the postbox has just been opened, triggers postboxes.pbhide if the postbox has
     23                 * just been closed.
     24                 *
     25                 * @memberof postboxes
     26                 * @fires postboxes#postbox-toggled
     27                 */
    928                handle_click : function () {
    1029                        var $el = $( this ),
    1130                                p = $el.parent( '.postbox' ),
    var postboxes;  
    4160                                }
    4261                        }
    4362
     63                        /**
     64                         * Fires when the postbox has been opened or closed. Contains a jQuery object with the postbox element in
     65                         * it.
     66                         *
     67                         * @event postboxes#postbox-toggled
     68                         * @type {Object}
     69                         */
    4470                        $document.trigger( 'postbox-toggled', p );
    4571                },
    4672
     73                /**
     74                 * Adds event handlers to all postboxes and screen option on the current page.
     75                 *
     76                 * @memberof postboxes
     77                 *
     78                 * @param {string} page The page we are currently on.
     79                 * @param {Object} [args]
     80                 * @param {Function} args.pbshow A callback that is called when a postbox opens.
     81                 * @param {Function} args.pbhide A callback that is called when a postbox closes.
     82                 */
    4783                add_postbox_toggles : function (page, args) {
    4884                        var $handles = $( '.postbox .hndle, .postbox .handlediv' );
    4985
    var postboxes;  
    5692                                e.stopPropagation();
    5793                        });
    5894
     95                        /**
     96                         * Adds an event handler to the dismissal of a postbox. Event handler completely hides the postbox element
     97                         * and it cannot be closed or opened afterwards.
     98                         */
    5999                        $( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) {
    60100                                var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
    61101                                e.preventDefault();
    62102                                $( '#' + hide_id ).prop('checked', false).triggerHandler('click');
    63103                        });
    64104
     105                        /**
     106                         * Adds an event handler to the screen option checkboxes. Event handler completely hides the postbox element
     107                         *
     108                         * @fires postboxes#postbox-toggled
     109                         */
    65110                        $('.hide-postbox-tog').bind('click.postboxes', function() {
    66111                                var $el = $(this),
    67112                                        boxId = $el.val(),
    var postboxes;  
    78123                                                postboxes.pbhide( boxId );
    79124                                        }
    80125                                }
     126
    81127                                postboxes.save_state( page );
    82128                                postboxes._mark_area();
    83129                                $document.trigger( 'postbox-toggled', $postbox );
    84130                        });
    85131
     132                        /**
     133                         * Adds an event handler to the screen options layout preferences.
     134                         */
    86135                        $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
    87136                                var n = parseInt($(this).val(), 10);
    88137
    var postboxes;  
    93142                        });
    94143                },
    95144
     145                /**
     146                 * Initializes all the postboxes, mainly their sortable behaviour.
     147                 *
     148                 * @memberof postboxes
     149                 *
     150                 * @param {string} page The page we are currently on.
     151                 * @param {Object} [args]
     152                 * @param {Function} args.pbshow A callback that is called when a postbox opens.
     153                 * @param {Function} args.pbhide A callback that is called when a postbox closes.
     154                 */
    96155                init : function(page, args) {
    97156                        var isMobile = $( document.body ).hasClass( 'mobile' ),
    98157                                $handleButtons = $( '.postbox .handlediv' );
    var postboxes;  
    157216                        });
    158217                },
    159218
     219                /**
     220                 * Saves the state of the postboxes to the server. It sends two lists, one with all the closed postboxes, one
     221                 * with all the hidden postboxes.
     222                 *
     223                 * @memberof postboxes
     224                 *
     225                 * @param {string} page The page we are currently on.
     226                 */
    160227                save_state : function(page) {
    161228                        var closed, hidden;
    162229
    var postboxes;  
    177244                        });
    178245                },
    179246
     247                /**
     248                 * Saves the order of the postboxes to the server. Sends a list of all postboxes inside a sortable area to the
     249                 * server.
     250                 *
     251                 * @memberof postboxes
     252                 *
     253                 * @param {string} page The page we are currently on.
     254                 */
    180255                save_order : function(page) {
    181256                        var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
    182257
    var postboxes;  
    186261                                page_columns: page_columns,
    187262                                page: page
    188263                        };
     264
    189265                        $('.meta-box-sortables').each( function() {
    190266                                postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
    191267                        } );
     268
    192269                        $.post( ajaxurl, postVars );
    193270                },
    194271
     272                /**
     273                 * Adds a message to empty sortable areas on the dashboard page. Also adds a border around the side area on the
     274                 * post edit screen if there are no postboxes present.
     275                 *
     276                 * @memberof postboxes
     277                 * @private
     278                 */
    195279                _mark_area : function() {
    196280                        var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
    197281
    var postboxes;  
    215299                        }
    216300                },
    217301
     302                /**
     303                 * Changes the amount of columns on the post edit page.
     304                 *
     305                 * @memberof postboxes
     306                 * @fires postboxes#postboxes-columnchange
     307                 * @private
     308                 *
     309                 * @param {number} n The amount of columns to divide the post edit page in.
     310                 */
    218311                _pb_edit : function(n) {
    219312                        var el = $('.metabox-holder').get(0);
    220313
    var postboxes;  
    222315                                el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
    223316                        }
    224317
     318                        /**
     319                         * Fires when the amount of columns on the post edit page has been changed.
     320                         *
     321                         * @event postboxes#postboxes-columnchange
     322                         */
    225323                        $( document ).trigger( 'postboxes-columnchange' );
    226324                },
    227325
     326                /**
     327                 * Changes the postboxes based on the current orientation of the browser. Meant to be called when the
     328                 * orientation of the browser changes.
     329                 *
     330                 * @memberof postboxes
     331                 * @private
     332                 */
    228333                _pb_change : function() {
    229334                        var check = $( 'label.columns-prefs-1 input[type="radio"]' );
    230335
  • src/wp-admin/js/postbox.js

    From 68e82d0105e03727cda2850bd6e2a49acdacaa11 Mon Sep 17 00:00:00 2001
    From: Anton Timmermans <email@atimmer.com>
    Date: Thu, 7 Jul 2016 16:54:46 +0200
    Subject: [PATCH 2/3] Add documentation to pbshow and pbhide
    
    ---
     src/wp-admin/js/postbox.js | 9 +++++++++
     1 file changed, 9 insertions(+)
    
    diff --git a/src/wp-admin/js/postbox.js b/src/wp-admin/js/postbox.js
    index 74f5def..0b0be34 100644
    a b var postboxes;  
    352352                },
    353353
    354354                /* Callbacks */
     355
     356                /**
     357                 * @property {Function|boolean} pbshow A callback that is called when a postbox is opened.
     358                 * @memberof postboxes
     359                 */
    355360                pbshow : false,
    356361
     362                /**
     363                 * @property {Function|boolean} pbhide A callback that is called when a postbox is closed.
     364                 * @memberof postboxes
     365                 */
    357366                pbhide : false
    358367        };
    359368
  • src/wp-admin/js/postbox.js

    From dbc91371f87df6aec7a69af4d027b71abbe7ccc5 Mon Sep 17 00:00:00 2001
    From: Anton Timmermans <email@atimmer.com>
    Date: Thu, 14 Jul 2016 15:20:03 +0200
    Subject: [PATCH 3/3] Add comment to duplicate event trigger
    
    ---
     src/wp-admin/js/postbox.js | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/src/wp-admin/js/postbox.js b/src/wp-admin/js/postbox.js
    index 0b0be34..2b713f2 100644
    a b var postboxes;  
    126126
    127127                                postboxes.save_state( page );
    128128                                postboxes._mark_area();
     129
     130                                /**
     131                                 * @see postboxes.handle_click
     132                                 */
    129133                                $document.trigger( 'postbox-toggled', $postbox );
    130134                        });
    131135