diff --git a/src/wp-admin/js/postbox.js b/src/wp-admin/js/postbox.js
index a8222ee..d36dde6 100644
|
a
|
b
|
|
| | 1 | /** |
| | 2 | * Contains the postboxes logic, opening and closing postboxes, reordering and saving |
| | 3 | * the state and ordering to the database. |
| | 4 | * |
| | 5 | * @summary Contains postboxes logic |
| | 6 | * |
| | 7 | * @since 2.4.0 |
| | 8 | * @requires jQuery |
| | 9 | */ |
| | 10 | |
| 1 | 11 | /* global ajaxurl, postBoxL10n */ |
| 2 | 12 | |
| | 13 | /** |
| | 14 | * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see |
| | 15 | * around the content on the edit page. |
| | 16 | * |
| | 17 | * @since 2.7.0 |
| | 18 | * |
| | 19 | * @namespace postboxes |
| | 20 | * |
| | 21 | * @type {Object} |
| | 22 | */ |
| 3 | 23 | var postboxes; |
| 4 | 24 | |
| 5 | 25 | (function($) { |
| 6 | 26 | var $document = $( document ); |
| 7 | 27 | |
| 8 | 28 | postboxes = { |
| | 29 | |
| | 30 | /** |
| | 31 | * @summary Handles a click on either the postbox heading or the postbox open/close icon. |
| | 32 | * |
| | 33 | * Opens or closes the postbox. Expects `this` to equal the clicked element. |
| | 34 | * Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide |
| | 35 | * if the postbox has been closed. |
| | 36 | * |
| | 37 | * @since 4.4.0 |
| | 38 | * @memberof postboxes |
| | 39 | * @fires postboxes#postbox-toggled |
| | 40 | * |
| | 41 | * @returns {void} |
| | 42 | */ |
| 9 | 43 | handle_click : function () { |
| 10 | 44 | var $el = $( this ), |
| 11 | 45 | p = $el.parent( '.postbox' ), |
| … |
… |
var postboxes;
|
| 41 | 75 | } |
| 42 | 76 | } |
| 43 | 77 | |
| | 78 | /** |
| | 79 | * @summary Fires when a postbox has been opened or closed. |
| | 80 | * |
| | 81 | * Contains a jQuery object with the relevant postbox element. |
| | 82 | * |
| | 83 | * @since 4.0.0 |
| | 84 | * @event postboxes#postbox-toggled |
| | 85 | * @type {Object} |
| | 86 | */ |
| 44 | 87 | $document.trigger( 'postbox-toggled', p ); |
| 45 | 88 | }, |
| 46 | 89 | |
| | 90 | /** |
| | 91 | * Adds event handlers to all postboxes and screen option on the current page. |
| | 92 | * |
| | 93 | * @since 2.7.0 |
| | 94 | * @memberof postboxes |
| | 95 | * |
| | 96 | * @param {string} page The page we are currently on. |
| | 97 | * @param {Object} [args] |
| | 98 | * @param {Function} args.pbshow A callback that is called when a postbox opens. |
| | 99 | * @param {Function} args.pbhide A callback that is called when a postbox closes. |
| | 100 | * @returns {void} |
| | 101 | */ |
| 47 | 102 | add_postbox_toggles : function (page, args) { |
| 48 | 103 | var $handles = $( '.postbox .hndle, .postbox .handlediv' ); |
| 49 | 104 | |
| … |
… |
var postboxes;
|
| 52 | 107 | |
| 53 | 108 | $handles.on( 'click.postboxes', this.handle_click ); |
| 54 | 109 | |
| | 110 | /** |
| | 111 | * @since 2.7.0 |
| | 112 | */ |
| 55 | 113 | $('.postbox .hndle a').click( function(e) { |
| 56 | 114 | e.stopPropagation(); |
| 57 | 115 | }); |
| 58 | 116 | |
| | 117 | /** |
| | 118 | * @summary Hides a postbox. |
| | 119 | * |
| | 120 | * Event handler for the postbox dismiss button. After clicking the button |
| | 121 | * the postbox will be hidden. |
| | 122 | * |
| | 123 | * @since 3.2.0 |
| | 124 | * |
| | 125 | * @returns {void} |
| | 126 | */ |
| 59 | 127 | $( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) { |
| 60 | 128 | var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; |
| 61 | 129 | e.preventDefault(); |
| 62 | 130 | $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
| 63 | 131 | }); |
| 64 | 132 | |
| | 133 | /** |
| | 134 | * @summary Hides the postbox element |
| | 135 | * |
| | 136 | * Event handler for the screen options checkboxes. When a checkbox is |
| | 137 | * clicked this function will hide or show the relevant postboxes. |
| | 138 | * |
| | 139 | * @since 2.7.0 |
| | 140 | * @fires postboxes#postbox-toggled |
| | 141 | * |
| | 142 | * @returns {void} |
| | 143 | */ |
| 65 | 144 | $('.hide-postbox-tog').bind('click.postboxes', function() { |
| 66 | 145 | var $el = $(this), |
| 67 | 146 | boxId = $el.val(), |
| … |
… |
var postboxes;
|
| 78 | 157 | postboxes.pbhide( boxId ); |
| 79 | 158 | } |
| 80 | 159 | } |
| | 160 | |
| 81 | 161 | postboxes.save_state( page ); |
| 82 | 162 | postboxes._mark_area(); |
| | 163 | |
| | 164 | /** |
| | 165 | * @since 4.0.0 |
| | 166 | * @see postboxes.handle_click |
| | 167 | */ |
| 83 | 168 | $document.trigger( 'postbox-toggled', $postbox ); |
| 84 | 169 | }); |
| 85 | 170 | |
| | 171 | /** |
| | 172 | * @summary Changes the amount of columns based on the layout preferences. |
| | 173 | * |
| | 174 | * @since 2.8.0 |
| | 175 | * |
| | 176 | * @returns {void} |
| | 177 | */ |
| 86 | 178 | $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ |
| 87 | 179 | var n = parseInt($(this).val(), 10); |
| 88 | 180 | |
| … |
… |
var postboxes;
|
| 93 | 185 | }); |
| 94 | 186 | }, |
| 95 | 187 | |
| | 188 | /** |
| | 189 | * @summary Initializes all the postboxes, mainly their sortable behaviour. |
| | 190 | * |
| | 191 | * @since 2.7.0 |
| | 192 | * @memberof postboxes |
| | 193 | * |
| | 194 | * @param {string} page The page we are currently on. |
| | 195 | * @param {Object} [args={}] The arguments for the postbox initializer. |
| | 196 | * @param {Function} args.pbshow A callback that is called when a postbox opens. |
| | 197 | * @param {Function} args.pbhide A callback that is called when a postbox |
| | 198 | * closes. |
| | 199 | * |
| | 200 | * @returns {void} |
| | 201 | */ |
| 96 | 202 | init : function(page, args) { |
| 97 | 203 | var isMobile = $( document.body ).hasClass( 'mobile' ), |
| 98 | 204 | $handleButtons = $( '.postbox .handlediv' ); |
| … |
… |
var postboxes;
|
| 110 | 216 | tolerance: 'pointer', |
| 111 | 217 | forcePlaceholderSize: true, |
| 112 | 218 | helper: function( event, element ) { |
| 113 | | // `helper: 'clone'` is equivalent to `return element.clone();` |
| 114 | | // Cloning a checked radio and then inserting that clone next to the original |
| 115 | | // radio unchecks the original radio (since only one of the two can be checked). |
| 116 | | // We get around this by renaming the helper's inputs' name attributes so that, |
| 117 | | // when the helper is inserted into the DOM for the sortable, no radios are |
| 118 | | // duplicated, and no original radio gets unchecked. |
| | 219 | /* `helper: 'clone'` is equivalent to `return element.clone();` |
| | 220 | * Cloning a checked radio and then inserting that clone next to the original |
| | 221 | * radio unchecks the original radio (since only one of the two can be checked). |
| | 222 | * We get around this by renaming the helper's inputs' name attributes so that, |
| | 223 | * when the helper is inserted into the DOM for the sortable, no radios are |
| | 224 | * duplicated, and no original radio gets unchecked. |
| | 225 | */ |
| 119 | 226 | return element.clone() |
| 120 | 227 | .find( ':input' ) |
| 121 | 228 | .attr( 'name', function( i, currentName ) { |
| … |
… |
var postboxes;
|
| 157 | 264 | }); |
| 158 | 265 | }, |
| 159 | 266 | |
| | 267 | /** |
| | 268 | * @summary Saves the state of the postboxes to the server. |
| | 269 | * |
| | 270 | * Saves the state of the postboxes to the server. It sends two lists, one with |
| | 271 | * all the closed postboxes, one with all the hidden postboxes. |
| | 272 | * |
| | 273 | * @since 2.7.0 |
| | 274 | * @memberof postboxes |
| | 275 | * |
| | 276 | * @param {string} page The page we are currently on. |
| | 277 | * @returns {void} |
| | 278 | */ |
| 160 | 279 | save_state : function(page) { |
| 161 | 280 | var closed, hidden; |
| 162 | 281 | |
| … |
… |
var postboxes;
|
| 177 | 296 | }); |
| 178 | 297 | }, |
| 179 | 298 | |
| | 299 | /** |
| | 300 | * @summary Saves the order of the postboxes to the server. |
| | 301 | * |
| | 302 | * Saves the order of the postboxes to the server. Sends a list of all postboxes |
| | 303 | * inside a sortable area to the server. |
| | 304 | * |
| | 305 | * @since 2.8.0 |
| | 306 | * @memberof postboxes |
| | 307 | * |
| | 308 | * @param {string} page The page we are currently on. |
| | 309 | * @returns {void} |
| | 310 | */ |
| 180 | 311 | save_order : function(page) { |
| 181 | 312 | var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; |
| 182 | 313 | |
| … |
… |
var postboxes;
|
| 186 | 317 | page_columns: page_columns, |
| 187 | 318 | page: page |
| 188 | 319 | }; |
| | 320 | |
| 189 | 321 | $('.meta-box-sortables').each( function() { |
| 190 | 322 | postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' ); |
| 191 | 323 | } ); |
| | 324 | |
| 192 | 325 | $.post( ajaxurl, postVars ); |
| 193 | 326 | }, |
| 194 | 327 | |
| | 328 | /** |
| | 329 | * @summary Marks empty postbox areas. |
| | 330 | * |
| | 331 | * Adds a message to empty sortable areas on the dashboard page. Also adds a |
| | 332 | * border around the side area on the post edit screen if there are no postboxes |
| | 333 | * present. |
| | 334 | * |
| | 335 | * @since 3.3.0 |
| | 336 | * @memberof postboxes |
| | 337 | * @access private |
| | 338 | * |
| | 339 | * @returns {void} |
| | 340 | */ |
| 195 | 341 | _mark_area : function() { |
| 196 | 342 | var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); |
| 197 | 343 | |
| … |
… |
var postboxes;
|
| 215 | 361 | } |
| 216 | 362 | }, |
| 217 | 363 | |
| | 364 | /** |
| | 365 | * @summary Changes the amount of columns on the post edit page. |
| | 366 | * |
| | 367 | * @since 3.3.0 |
| | 368 | * @memberof postboxes |
| | 369 | * @fires postboxes#postboxes-columnchange |
| | 370 | * @access private |
| | 371 | * |
| | 372 | * @param {number} n The amount of columns to divide the post edit page in. |
| | 373 | * @returns {void} |
| | 374 | */ |
| 218 | 375 | _pb_edit : function(n) { |
| 219 | 376 | var el = $('.metabox-holder').get(0); |
| 220 | 377 | |
| … |
… |
var postboxes;
|
| 222 | 379 | el.className = el.className.replace(/columns-\d+/, 'columns-' + n); |
| 223 | 380 | } |
| 224 | 381 | |
| | 382 | /** |
| | 383 | * Fires when the amount of columns on the post edit page has been changed. |
| | 384 | * |
| | 385 | * @since 4.0.0 |
| | 386 | * @event postboxes#postboxes-columnchange |
| | 387 | */ |
| 225 | 388 | $( document ).trigger( 'postboxes-columnchange' ); |
| 226 | 389 | }, |
| 227 | 390 | |
| | 391 | /** |
| | 392 | * @summary Changes the amount of columns the postboxes are in based on the |
| | 393 | * current orientation of the browser. |
| | 394 | * |
| | 395 | * @since 3.3.0 |
| | 396 | * @memberof postboxes |
| | 397 | * @access private |
| | 398 | * |
| | 399 | * @returns {void} |
| | 400 | */ |
| 228 | 401 | _pb_change : function() { |
| 229 | 402 | var check = $( 'label.columns-prefs-1 input[type="radio"]' ); |
| 230 | 403 | |
| … |
… |
var postboxes;
|
| 247 | 420 | }, |
| 248 | 421 | |
| 249 | 422 | /* Callbacks */ |
| | 423 | |
| | 424 | /** |
| | 425 | * @since 2.7.0 |
| | 426 | * @memberof postboxes |
| | 427 | * @access public |
| | 428 | * @property {Function|boolean} pbshow A callback that is called when a postbox |
| | 429 | * is opened. |
| | 430 | */ |
| 250 | 431 | pbshow : false, |
| 251 | 432 | |
| | 433 | /** |
| | 434 | * @since 2.7.0 |
| | 435 | * @memberof postboxes |
| | 436 | * @access public |
| | 437 | * @property {Function|boolean} pbhide A callback that is called when a postbox |
| | 438 | * is closed. |
| | 439 | */ |
| 252 | 440 | pbhide : false |
| 253 | 441 | }; |
| 254 | 442 | |