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
|
|
| 1 | 1 | /* global ajaxurl, postBoxL10n */ |
| 2 | 2 | |
| | 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 | */ |
| 3 | 11 | var postboxes; |
| 4 | 12 | |
| 5 | 13 | (function($) { |
| 6 | 14 | var $document = $( document ); |
| 7 | 15 | |
| 8 | 16 | 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 | */ |
| 9 | 28 | handle_click : function () { |
| 10 | 29 | var $el = $( this ), |
| 11 | 30 | p = $el.parent( '.postbox' ), |
| … |
… |
var postboxes;
|
| 41 | 60 | } |
| 42 | 61 | } |
| 43 | 62 | |
| | 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 | */ |
| 44 | 70 | $document.trigger( 'postbox-toggled', p ); |
| 45 | 71 | }, |
| 46 | 72 | |
| | 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 | */ |
| 47 | 83 | add_postbox_toggles : function (page, args) { |
| 48 | 84 | var $handles = $( '.postbox .hndle, .postbox .handlediv' ); |
| 49 | 85 | |
| … |
… |
var postboxes;
|
| 56 | 92 | e.stopPropagation(); |
| 57 | 93 | }); |
| 58 | 94 | |
| | 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 | */ |
| 59 | 99 | $( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) { |
| 60 | 100 | var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; |
| 61 | 101 | e.preventDefault(); |
| 62 | 102 | $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
| 63 | 103 | }); |
| 64 | 104 | |
| | 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 | */ |
| 65 | 110 | $('.hide-postbox-tog').bind('click.postboxes', function() { |
| 66 | 111 | var $el = $(this), |
| 67 | 112 | boxId = $el.val(), |
| … |
… |
var postboxes;
|
| 78 | 123 | postboxes.pbhide( boxId ); |
| 79 | 124 | } |
| 80 | 125 | } |
| | 126 | |
| 81 | 127 | postboxes.save_state( page ); |
| 82 | 128 | postboxes._mark_area(); |
| 83 | 129 | $document.trigger( 'postbox-toggled', $postbox ); |
| 84 | 130 | }); |
| 85 | 131 | |
| | 132 | /** |
| | 133 | * Adds an event handler to the screen options layout preferences. |
| | 134 | */ |
| 86 | 135 | $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ |
| 87 | 136 | var n = parseInt($(this).val(), 10); |
| 88 | 137 | |
| … |
… |
var postboxes;
|
| 93 | 142 | }); |
| 94 | 143 | }, |
| 95 | 144 | |
| | 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 | */ |
| 96 | 155 | init : function(page, args) { |
| 97 | 156 | var isMobile = $( document.body ).hasClass( 'mobile' ), |
| 98 | 157 | $handleButtons = $( '.postbox .handlediv' ); |
| … |
… |
var postboxes;
|
| 157 | 216 | }); |
| 158 | 217 | }, |
| 159 | 218 | |
| | 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 | */ |
| 160 | 227 | save_state : function(page) { |
| 161 | 228 | var closed, hidden; |
| 162 | 229 | |
| … |
… |
var postboxes;
|
| 177 | 244 | }); |
| 178 | 245 | }, |
| 179 | 246 | |
| | 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 | */ |
| 180 | 255 | save_order : function(page) { |
| 181 | 256 | var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; |
| 182 | 257 | |
| … |
… |
var postboxes;
|
| 186 | 261 | page_columns: page_columns, |
| 187 | 262 | page: page |
| 188 | 263 | }; |
| | 264 | |
| 189 | 265 | $('.meta-box-sortables').each( function() { |
| 190 | 266 | postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' ); |
| 191 | 267 | } ); |
| | 268 | |
| 192 | 269 | $.post( ajaxurl, postVars ); |
| 193 | 270 | }, |
| 194 | 271 | |
| | 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 | */ |
| 195 | 279 | _mark_area : function() { |
| 196 | 280 | var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); |
| 197 | 281 | |
| … |
… |
var postboxes;
|
| 215 | 299 | } |
| 216 | 300 | }, |
| 217 | 301 | |
| | 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 | */ |
| 218 | 311 | _pb_edit : function(n) { |
| 219 | 312 | var el = $('.metabox-holder').get(0); |
| 220 | 313 | |
| … |
… |
var postboxes;
|
| 222 | 315 | el.className = el.className.replace(/columns-\d+/, 'columns-' + n); |
| 223 | 316 | } |
| 224 | 317 | |
| | 318 | /** |
| | 319 | * Fires when the amount of columns on the post edit page has been changed. |
| | 320 | * |
| | 321 | * @event postboxes#postboxes-columnchange |
| | 322 | */ |
| 225 | 323 | $( document ).trigger( 'postboxes-columnchange' ); |
| 226 | 324 | }, |
| 227 | 325 | |
| | 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 | */ |
| 228 | 333 | _pb_change : function() { |
| 229 | 334 | var check = $( 'label.columns-prefs-1 input[type="radio"]' ); |
| 230 | 335 | |
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;
|
| 352 | 352 | }, |
| 353 | 353 | |
| 354 | 354 | /* Callbacks */ |
| | 355 | |
| | 356 | /** |
| | 357 | * @property {Function|boolean} pbshow A callback that is called when a postbox is opened. |
| | 358 | * @memberof postboxes |
| | 359 | */ |
| 355 | 360 | pbshow : false, |
| 356 | 361 | |
| | 362 | /** |
| | 363 | * @property {Function|boolean} pbhide A callback that is called when a postbox is closed. |
| | 364 | * @memberof postboxes |
| | 365 | */ |
| 357 | 366 | pbhide : false |
| 358 | 367 | }; |
| 359 | 368 | |
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;
|
| 126 | 126 | |
| 127 | 127 | postboxes.save_state( page ); |
| 128 | 128 | postboxes._mark_area(); |
| | 129 | |
| | 130 | /** |
| | 131 | * @see postboxes.handle_click |
| | 132 | */ |
| 129 | 133 | $document.trigger( 'postbox-toggled', $postbox ); |
| 130 | 134 | }); |
| 131 | 135 | |