1 /** |
1 /** |
2 * Contains the postboxes logic, opening and closing postboxes, reordering and saving |
2 * Contains the postboxes logic, opening and closing postboxes, reordering and saving |
3 * the state and ordering to the database. |
3 * the state and ordering to the database. |
4 * |
4 * |
5 * @summary Contains postboxes logic |
|
6 * |
|
7 * @since 2.5.0 |
5 * @since 2.5.0 |
8 * @requires jQuery |
6 * @requires jQuery |
|
7 * @output wp-admin/js/postbox.js |
9 */ |
8 */ |
10 |
9 |
11 /* global ajaxurl, postBoxL10n */ |
10 /* global ajaxurl, postBoxL10n, postboxes */ |
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 */ |
|
23 var postboxes; |
|
24 |
11 |
25 (function($) { |
12 (function($) { |
26 var $document = $( document ); |
13 var $document = $( document ); |
27 |
14 |
28 postboxes = { |
15 /** |
29 |
16 * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see |
30 /** |
17 * around the content on the edit page. |
31 * @summary Handles a click on either the postbox heading or the postbox open/close icon. |
18 * |
|
19 * @since 2.7.0 |
|
20 * |
|
21 * @namespace postboxes |
|
22 * |
|
23 * @type {Object} |
|
24 */ |
|
25 window.postboxes = { |
|
26 |
|
27 /** |
|
28 * Handles a click on either the postbox heading or the postbox open/close icon. |
32 * |
29 * |
33 * Opens or closes the postbox. Expects `this` to equal the clicked element. |
30 * 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 |
31 * Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide |
35 * if the postbox has been closed. |
32 * if the postbox has been closed. |
36 * |
33 * |
74 postboxes.pbhide( id ); |
71 postboxes.pbhide( id ); |
75 } |
72 } |
76 } |
73 } |
77 |
74 |
78 /** |
75 /** |
79 * @summary Fires when a postbox has been opened or closed. |
76 * Fires when a postbox has been opened or closed. |
80 * |
77 * |
81 * Contains a jQuery object with the relevant postbox element. |
78 * Contains a jQuery object with the relevant postbox element. |
82 * |
79 * |
83 * @since 4.0.0 |
80 * @since 4.0.0 |
|
81 * @ignore |
|
82 * |
84 * @event postboxes#postbox-toggled |
83 * @event postboxes#postbox-toggled |
85 * @type {Object} |
84 * @type {Object} |
86 */ |
85 */ |
87 $document.trigger( 'postbox-toggled', p ); |
86 $document.trigger( 'postbox-toggled', p ); |
88 }, |
87 }, |
129 e.preventDefault(); |
128 e.preventDefault(); |
130 $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
129 $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
131 }); |
130 }); |
132 |
131 |
133 /** |
132 /** |
134 * @summary Hides the postbox element |
133 * Hides the postbox element |
135 * |
134 * |
136 * Event handler for the screen options checkboxes. When a checkbox is |
135 * Event handler for the screen options checkboxes. When a checkbox is |
137 * clicked this function will hide or show the relevant postboxes. |
136 * clicked this function will hide or show the relevant postboxes. |
138 * |
137 * |
139 * @since 2.7.0 |
138 * @since 2.7.0 |
|
139 * @ignore |
|
140 * |
140 * @fires postboxes#postbox-toggled |
141 * @fires postboxes#postbox-toggled |
141 * |
142 * |
142 * @returns {void} |
143 * @returns {void} |
143 */ |
144 */ |
144 $('.hide-postbox-tog').bind('click.postboxes', function() { |
145 $('.hide-postbox-tog').bind('click.postboxes', function() { |
263 $el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) ); |
264 $el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) ); |
264 }); |
265 }); |
265 }, |
266 }, |
266 |
267 |
267 /** |
268 /** |
268 * @summary Saves the state of the postboxes to the server. |
269 * Saves the state of the postboxes to the server. |
269 * |
270 * |
270 * Saves the state of the postboxes to the server. It sends two lists, one with |
271 * It sends two lists, one with all the closed postboxes, one with all the |
271 * all the closed postboxes, one with all the hidden postboxes. |
272 * hidden postboxes. |
272 * |
273 * |
273 * @since 2.7.0 |
274 * @since 2.7.0 |
274 * @memberof postboxes |
275 * @memberof postboxes |
275 * |
276 * |
276 * @param {string} page The page we are currently on. |
277 * @param {string} page The page we are currently on. |
381 |
381 |
382 /** |
382 /** |
383 * Fires when the amount of columns on the post edit page has been changed. |
383 * Fires when the amount of columns on the post edit page has been changed. |
384 * |
384 * |
385 * @since 4.0.0 |
385 * @since 4.0.0 |
|
386 * @ignore |
|
387 * |
386 * @event postboxes#postboxes-columnchange |
388 * @event postboxes#postboxes-columnchange |
387 */ |
389 */ |
388 $( document ).trigger( 'postboxes-columnchange' ); |
390 $( document ).trigger( 'postboxes-columnchange' ); |
389 }, |
391 }, |
390 |
392 |
391 /** |
393 /** |
392 * @summary Changes the amount of columns the postboxes are in based on the |
394 * Changes the amount of columns the postboxes are in based on the current |
393 * current orientation of the browser. |
395 * orientation of the browser. |
394 * |
396 * |
395 * @since 3.3.0 |
397 * @since 3.3.0 |
396 * @memberof postboxes |
398 * @memberof postboxes |
397 * @access private |
399 * @access private |
398 * |
400 * |