author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 18 | be944660c56a |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
* Contains the postboxes logic, opening and closing postboxes, reordering and saving |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* the state and ordering to the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @requires jQuery |
9 | 7 |
* @output wp-admin/js/postbox.js |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
*/ |
5 | 9 |
|
16 | 10 |
/* global ajaxurl, postboxes */ |
0 | 11 |
|
12 |
(function($) { |
|
16 | 13 |
var $document = $( document ), |
14 |
__ = wp.i18n.__; |
|
5 | 15 |
|
9 | 16 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
17 |
* This object contains all function to handle the behavior of the post boxes. The post boxes are the boxes you see |
9 | 18 |
* around the content on the edit page. |
19 |
* |
|
20 |
* @since 2.7.0 |
|
21 |
* |
|
22 |
* @namespace postboxes |
|
23 |
* |
|
24 |
* @type {Object} |
|
25 |
*/ |
|
26 |
window.postboxes = { |
|
0 | 27 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
/** |
9 | 29 |
* Handles a click on either the postbox heading or the postbox open/close icon. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* Opens or closes the postbox. Expects `this` to equal the clicked element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* if the postbox has been closed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* @since 4.4.0 |
16 | 36 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* @memberof postboxes |
16 | 38 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @fires postboxes#postbox-toggled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* |
16 | 41 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
handle_click : function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
var $el = $( this ), |
16 | 45 |
p = $el.closest( '.postbox' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
id = p.attr( 'id' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
ariaExpandedValue; |
0 | 48 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
if ( 'dashboard_browser_nag' === id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
p.toggleClass( 'closed' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
ariaExpandedValue = ! p.hasClass( 'closed' ); |
0 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
if ( $el.hasClass( 'handlediv' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
// The handle button was clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
$el.attr( 'aria-expanded', ariaExpandedValue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
// The handle heading was clicked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
$el.closest( '.postbox' ).find( 'button.handlediv' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
.attr( 'aria-expanded', ariaExpandedValue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
} |
0 | 64 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
if ( postboxes.page !== 'press-this' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
postboxes.save_state( postboxes.page ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
} |
0 | 68 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
if ( id ) { |
18 | 70 |
if ( !p.hasClass('closed') && typeof postboxes.pbshow === 'function' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
postboxes.pbshow( id ); |
18 | 72 |
} else if ( p.hasClass('closed') && typeof postboxes.pbhide === 'function' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
postboxes.pbhide( id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
/** |
9 | 78 |
* Fires when a postbox has been opened or closed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* Contains a jQuery object with the relevant postbox element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @since 4.0.0 |
9 | 83 |
* @ignore |
84 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* @event postboxes#postbox-toggled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* @type {Object} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
$document.trigger( 'postbox-toggled', p ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
}, |
0 | 90 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
/** |
16 | 92 |
* Handles clicks on the move up/down buttons. |
93 |
* |
|
94 |
* @since 5.5.0 |
|
95 |
* |
|
96 |
* @return {void} |
|
97 |
*/ |
|
98 |
handleOrder: function() { |
|
99 |
var button = $( this ), |
|
100 |
postbox = button.closest( '.postbox' ), |
|
101 |
postboxId = postbox.attr( 'id' ), |
|
102 |
postboxesWithinSortables = postbox.closest( '.meta-box-sortables' ).find( '.postbox:visible' ), |
|
103 |
postboxesWithinSortablesCount = postboxesWithinSortables.length, |
|
104 |
postboxWithinSortablesIndex = postboxesWithinSortables.index( postbox ), |
|
105 |
firstOrLastPositionMessage; |
|
106 |
||
107 |
if ( 'dashboard_browser_nag' === postboxId ) { |
|
108 |
return; |
|
109 |
} |
|
110 |
||
111 |
// If on the first or last position, do nothing and send an audible message to screen reader users. |
|
112 |
if ( 'true' === button.attr( 'aria-disabled' ) ) { |
|
113 |
firstOrLastPositionMessage = button.hasClass( 'handle-order-higher' ) ? |
|
114 |
__( 'The box is on the first position' ) : |
|
115 |
__( 'The box is on the last position' ); |
|
116 |
||
117 |
wp.a11y.speak( firstOrLastPositionMessage ); |
|
118 |
return; |
|
119 |
} |
|
120 |
||
121 |
// Move a postbox up. |
|
122 |
if ( button.hasClass( 'handle-order-higher' ) ) { |
|
123 |
// If the box is first within a sortable area, move it to the previous sortable area. |
|
124 |
if ( 0 === postboxWithinSortablesIndex ) { |
|
125 |
postboxes.handleOrderBetweenSortables( 'previous', button, postbox ); |
|
126 |
return; |
|
127 |
} |
|
128 |
||
129 |
postbox.prevAll( '.postbox:visible' ).eq( 0 ).before( postbox ); |
|
18 | 130 |
button.trigger( 'focus' ); |
16 | 131 |
postboxes.updateOrderButtonsProperties(); |
132 |
postboxes.save_order( postboxes.page ); |
|
133 |
} |
|
134 |
||
135 |
// Move a postbox down. |
|
136 |
if ( button.hasClass( 'handle-order-lower' ) ) { |
|
137 |
// If the box is last within a sortable area, move it to the next sortable area. |
|
138 |
if ( postboxWithinSortablesIndex + 1 === postboxesWithinSortablesCount ) { |
|
139 |
postboxes.handleOrderBetweenSortables( 'next', button, postbox ); |
|
140 |
return; |
|
141 |
} |
|
142 |
||
143 |
postbox.nextAll( '.postbox:visible' ).eq( 0 ).after( postbox ); |
|
18 | 144 |
button.trigger( 'focus' ); |
16 | 145 |
postboxes.updateOrderButtonsProperties(); |
146 |
postboxes.save_order( postboxes.page ); |
|
147 |
} |
|
148 |
||
149 |
}, |
|
150 |
||
151 |
/** |
|
152 |
* Moves postboxes between the sortables areas. |
|
153 |
* |
|
154 |
* @since 5.5.0 |
|
155 |
* |
|
156 |
* @param {string} position The "previous" or "next" sortables area. |
|
157 |
* @param {Object} button The jQuery object representing the button that was clicked. |
|
158 |
* @param {Object} postbox The jQuery object representing the postbox to be moved. |
|
159 |
* |
|
160 |
* @return {void} |
|
161 |
*/ |
|
162 |
handleOrderBetweenSortables: function( position, button, postbox ) { |
|
163 |
var closestSortablesId = button.closest( '.meta-box-sortables' ).attr( 'id' ), |
|
164 |
sortablesIds = [], |
|
165 |
sortablesIndex, |
|
166 |
detachedPostbox; |
|
167 |
||
168 |
// Get the list of sortables within the page. |
|
169 |
$( '.meta-box-sortables:visible' ).each( function() { |
|
170 |
sortablesIds.push( $( this ).attr( 'id' ) ); |
|
171 |
}); |
|
172 |
||
173 |
// Return if there's only one visible sortables area, e.g. in the block editor page. |
|
174 |
if ( 1 === sortablesIds.length ) { |
|
175 |
return; |
|
176 |
} |
|
177 |
||
178 |
// Find the index of the current sortables area within all the sortable areas. |
|
179 |
sortablesIndex = $.inArray( closestSortablesId, sortablesIds ); |
|
180 |
// Detach the postbox to be moved. |
|
181 |
detachedPostbox = postbox.detach(); |
|
182 |
||
183 |
// Move the detached postbox to its new position. |
|
184 |
if ( 'previous' === position ) { |
|
185 |
$( detachedPostbox ).appendTo( '#' + sortablesIds[ sortablesIndex - 1 ] ); |
|
186 |
} |
|
187 |
||
188 |
if ( 'next' === position ) { |
|
189 |
$( detachedPostbox ).prependTo( '#' + sortablesIds[ sortablesIndex + 1 ] ); |
|
190 |
} |
|
191 |
||
192 |
postboxes._mark_area(); |
|
193 |
button.focus(); |
|
194 |
postboxes.updateOrderButtonsProperties(); |
|
195 |
postboxes.save_order( postboxes.page ); |
|
196 |
}, |
|
197 |
||
198 |
/** |
|
199 |
* Update the move buttons properties depending on the postbox position. |
|
200 |
* |
|
201 |
* @since 5.5.0 |
|
202 |
* |
|
203 |
* @return {void} |
|
204 |
*/ |
|
205 |
updateOrderButtonsProperties: function() { |
|
206 |
var firstSortablesId = $( '.meta-box-sortables:visible:first' ).attr( 'id' ), |
|
207 |
lastSortablesId = $( '.meta-box-sortables:visible:last' ).attr( 'id' ), |
|
208 |
firstPostbox = $( '.postbox:visible:first' ), |
|
209 |
lastPostbox = $( '.postbox:visible:last' ), |
|
210 |
firstPostboxId = firstPostbox.attr( 'id' ), |
|
211 |
lastPostboxId = lastPostbox.attr( 'id' ), |
|
212 |
firstPostboxSortablesId = firstPostbox.closest( '.meta-box-sortables' ).attr( 'id' ), |
|
213 |
lastPostboxSortablesId = lastPostbox.closest( '.meta-box-sortables' ).attr( 'id' ), |
|
214 |
moveUpButtons = $( '.handle-order-higher' ), |
|
215 |
moveDownButtons = $( '.handle-order-lower' ); |
|
216 |
||
217 |
// Enable all buttons as a reset first. |
|
218 |
moveUpButtons |
|
219 |
.attr( 'aria-disabled', 'false' ) |
|
220 |
.removeClass( 'hidden' ); |
|
221 |
moveDownButtons |
|
222 |
.attr( 'aria-disabled', 'false' ) |
|
223 |
.removeClass( 'hidden' ); |
|
224 |
||
225 |
// When there's only one "sortables" area (e.g. in the block editor) and only one visible postbox, hide the buttons. |
|
226 |
if ( firstSortablesId === lastSortablesId && firstPostboxId === lastPostboxId ) { |
|
227 |
moveUpButtons.addClass( 'hidden' ); |
|
228 |
moveDownButtons.addClass( 'hidden' ); |
|
229 |
} |
|
230 |
||
231 |
// Set an aria-disabled=true attribute on the first visible "move" buttons. |
|
232 |
if ( firstSortablesId === firstPostboxSortablesId ) { |
|
233 |
$( firstPostbox ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'true' ); |
|
234 |
} |
|
235 |
||
236 |
// Set an aria-disabled=true attribute on the last visible "move" buttons. |
|
237 |
if ( lastSortablesId === lastPostboxSortablesId ) { |
|
238 |
$( '.postbox:visible .handle-order-lower' ).last().attr( 'aria-disabled', 'true' ); |
|
239 |
} |
|
240 |
}, |
|
241 |
||
242 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* Adds event handlers to all postboxes and screen option on the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* @since 2.7.0 |
16 | 246 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* @memberof postboxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* @param {string} page The page we are currently on. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @param {Object} [args] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @param {Function} args.pbshow A callback that is called when a postbox opens. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* @param {Function} args.pbhide A callback that is called when a postbox closes. |
16 | 253 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
add_postbox_toggles : function (page, args) { |
16 | 256 |
var $handles = $( '.postbox .hndle, .postbox .handlediv' ), |
257 |
$orderButtons = $( '.postbox .handle-order-higher, .postbox .handle-order-lower' ); |
|
5 | 258 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
this.page = page; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
this.init( page, args ); |
0 | 261 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
$handles.on( 'click.postboxes', this.handle_click ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
|
16 | 264 |
// Handle the order of the postboxes. |
265 |
$orderButtons.on( 'click.postboxes', this.handleOrder ); |
|
266 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
*/ |
18 | 270 |
$('.postbox .hndle a').on( 'click', function(e) { |
0 | 271 |
e.stopPropagation(); |
272 |
}); |
|
273 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
/** |
9 | 275 |
* Hides a postbox. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* Event handler for the postbox dismiss button. After clicking the button |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* the postbox will be hidden. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* |
16 | 280 |
* As of WordPress 5.5, this is only used for the browser update nag. |
281 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
* @since 3.2.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* |
16 | 284 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
$( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) { |
0 | 287 |
var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
e.preventDefault(); |
0 | 289 |
$( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
290 |
}); |
|
291 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
/** |
9 | 293 |
* Hides the postbox element |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
* Event handler for the screen options checkboxes. When a checkbox is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
* clicked this function will hide or show the relevant postboxes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* @since 2.7.0 |
9 | 299 |
* @ignore |
300 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
* @fires postboxes#postbox-toggled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* |
16 | 303 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
*/ |
18 | 305 |
$('.hide-postbox-tog').on('click.postboxes', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
var $el = $(this), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
boxId = $el.val(), |
5 | 308 |
$postbox = $( '#' + boxId ); |
0 | 309 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
if ( $el.prop( 'checked' ) ) { |
5 | 311 |
$postbox.show(); |
18 | 312 |
if ( typeof postboxes.pbshow === 'function' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
postboxes.pbshow( boxId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
} |
0 | 315 |
} else { |
5 | 316 |
$postbox.hide(); |
18 | 317 |
if ( typeof postboxes.pbhide === 'function' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
postboxes.pbhide( boxId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
} |
0 | 320 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
postboxes.save_state( page ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
postboxes._mark_area(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @since 4.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* @see postboxes.handle_click |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
*/ |
5 | 329 |
$document.trigger( 'postbox-toggled', $postbox ); |
0 | 330 |
}); |
331 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
/** |
9 | 333 |
* Changes the amount of columns based on the layout preferences. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* |
16 | 337 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
*/ |
18 | 339 |
$('.columns-prefs input[type="radio"]').on('click.postboxes', function(){ |
0 | 340 |
var n = parseInt($(this).val(), 10); |
341 |
||
342 |
if ( n ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
postboxes._pb_edit(n); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
postboxes.save_order( page ); |
0 | 345 |
} |
346 |
}); |
|
347 |
}, |
|
348 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
350 |
* Initializes all the postboxes, mainly their sortable behavior. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
* @since 2.7.0 |
16 | 353 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
* @memberof postboxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
* @param {string} page The page we are currently on. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
* @param {Object} [args={}] The arguments for the postbox initializer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
* @param {Function} args.pbshow A callback that is called when a postbox opens. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
* @param {Function} args.pbhide A callback that is called when a postbox |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* closes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* |
16 | 362 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
*/ |
0 | 364 |
init : function(page, args) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
var isMobile = $( document.body ).hasClass( 'mobile' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
$handleButtons = $( '.postbox .handlediv' ); |
0 | 367 |
|
368 |
$.extend( this, args || {} ); |
|
369 |
$('.meta-box-sortables').sortable({ |
|
370 |
placeholder: 'sortable-placeholder', |
|
371 |
connectWith: '.meta-box-sortables', |
|
372 |
items: '.postbox', |
|
373 |
handle: '.hndle', |
|
374 |
cursor: 'move', |
|
375 |
delay: ( isMobile ? 200 : 0 ), |
|
376 |
distance: 2, |
|
377 |
tolerance: 'pointer', |
|
378 |
forcePlaceholderSize: true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
helper: function( event, element ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
/* `helper: 'clone'` is equivalent to `return element.clone();` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* Cloning a checked radio and then inserting that clone next to the original |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* radio unchecks the original radio (since only one of the two can be checked). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* We get around this by renaming the helper's inputs' name attributes so that, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* when the helper is inserted into the DOM for the sortable, no radios are |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* duplicated, and no original radio gets unchecked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
return element.clone() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
.find( ':input' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
.attr( 'name', function( i, currentName ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
return 'sort_' + parseInt( Math.random() * 100000, 10 ).toString() + '_' + currentName; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
} ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
.end(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
}, |
0 | 394 |
opacity: 0.65, |
16 | 395 |
start: function() { |
396 |
$( 'body' ).addClass( 'is-dragging-metaboxes' ); |
|
397 |
// Refresh the cached positions of all the sortable items so that the min-height set while dragging works. |
|
398 |
$( '.meta-box-sortables' ).sortable( 'refreshPositions' ); |
|
399 |
}, |
|
5 | 400 |
stop: function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
var $el = $( this ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
|
16 | 403 |
$( 'body' ).removeClass( 'is-dragging-metaboxes' ); |
404 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
if ( $el.find( '#dashboard_browser_nag' ).is( ':visible' ) && 'dashboard_browser_nag' != this.firstChild.id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
$el.sortable('cancel'); |
0 | 407 |
return; |
408 |
} |
|
409 |
||
16 | 410 |
postboxes.updateOrderButtonsProperties(); |
0 | 411 |
postboxes.save_order(page); |
412 |
}, |
|
413 |
receive: function(e,ui) { |
|
414 |
if ( 'dashboard_browser_nag' == ui.item[0].id ) |
|
415 |
$(ui.sender).sortable('cancel'); |
|
416 |
||
417 |
postboxes._mark_area(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
$document.trigger( 'postbox-moved', ui.item ); |
0 | 419 |
} |
420 |
}); |
|
421 |
||
422 |
if ( isMobile ) { |
|
18 | 423 |
$(document.body).on('orientationchange.postboxes', function(){ postboxes._pb_change(); }); |
0 | 424 |
this._pb_change(); |
425 |
} |
|
426 |
||
427 |
this._mark_area(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
|
16 | 429 |
// Update the "move" buttons properties. |
430 |
this.updateOrderButtonsProperties(); |
|
431 |
$document.on( 'postbox-toggled', this.updateOrderButtonsProperties ); |
|
432 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
// Set the handle buttons `aria-expanded` attribute initial value on page load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
$handleButtons.each( function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
var $el = $( this ); |
16 | 436 |
$el.attr( 'aria-expanded', ! $el.closest( '.postbox' ).hasClass( 'closed' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
}); |
0 | 438 |
}, |
439 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
/** |
9 | 441 |
* Saves the state of the postboxes to the server. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* |
9 | 443 |
* It sends two lists, one with all the closed postboxes, one with all the |
444 |
* hidden postboxes. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* @since 2.7.0 |
16 | 447 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @memberof postboxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* @param {string} page The page we are currently on. |
16 | 451 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
*/ |
0 | 453 |
save_state : function(page) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
var closed, hidden; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
// Return on the nav-menus.php screen, see #35112. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
if ( 'nav-menus' === page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
closed = $( '.postbox' ).filter( '.closed' ).map( function() { return this.id; } ).get().join( ',' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
hidden = $( '.postbox' ).filter( ':hidden' ).map( function() { return this.id; } ).get().join( ',' ); |
0 | 463 |
|
464 |
$.post(ajaxurl, { |
|
465 |
action: 'closed-postboxes', |
|
466 |
closed: closed, |
|
467 |
hidden: hidden, |
|
468 |
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |
|
469 |
page: page |
|
470 |
}); |
|
471 |
}, |
|
472 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
/** |
9 | 474 |
* Saves the order of the postboxes to the server. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* |
9 | 476 |
* Sends a list of all postboxes inside a sortable area to the server. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* @since 2.8.0 |
16 | 479 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @memberof postboxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* @param {string} page The page we are currently on. |
16 | 483 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
*/ |
0 | 485 |
save_order : function(page) { |
486 |
var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; |
|
487 |
||
488 |
postVars = { |
|
489 |
action: 'meta-box-order', |
|
490 |
_ajax_nonce: $('#meta-box-order-nonce').val(), |
|
491 |
page_columns: page_columns, |
|
492 |
page: page |
|
5 | 493 |
}; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
|
0 | 495 |
$('.meta-box-sortables').each( function() { |
5 | 496 |
postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' ); |
0 | 497 |
} ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
|
16 | 499 |
$.post( |
500 |
ajaxurl, |
|
501 |
postVars, |
|
502 |
function( response ) { |
|
503 |
if ( response.success ) { |
|
504 |
wp.a11y.speak( __( 'The boxes order has been saved.' ) ); |
|
505 |
} |
|
506 |
} |
|
507 |
); |
|
0 | 508 |
}, |
509 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
/** |
9 | 511 |
* Marks empty postbox areas. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* Adds a message to empty sortable areas on the dashboard page. Also adds a |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* border around the side area on the post edit screen if there are no postboxes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* |
16 | 520 |
* @memberof postboxes |
521 |
* |
|
522 |
* @return {void} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
*/ |
0 | 524 |
_mark_area : function() { |
16 | 525 |
var visible = $( 'div.postbox:visible' ).length, |
526 |
visibleSortables = $( '#dashboard-widgets .meta-box-sortables:visible, #post-body .meta-box-sortables:visible' ), |
|
527 |
areAllVisibleSortablesEmpty = true; |
|
0 | 528 |
|
16 | 529 |
visibleSortables.each( function() { |
0 | 530 |
var t = $(this); |
531 |
||
16 | 532 |
if ( visible == 1 || t.children( '.postbox:visible' ).length ) { |
0 | 533 |
t.removeClass('empty-container'); |
16 | 534 |
areAllVisibleSortablesEmpty = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
else { |
0 | 537 |
t.addClass('empty-container'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
} |
0 | 539 |
}); |
540 |
||
16 | 541 |
postboxes.updateEmptySortablesText( visibleSortables, areAllVisibleSortablesEmpty ); |
542 |
}, |
|
543 |
||
544 |
/** |
|
545 |
* Updates the text for the empty sortable areas on the Dashboard. |
|
546 |
* |
|
547 |
* @since 5.5.0 |
|
548 |
* |
|
549 |
* @param {Object} visibleSortables The jQuery object representing the visible sortable areas. |
|
550 |
* @param {boolean} areAllVisibleSortablesEmpty Whether all the visible sortable areas are "empty". |
|
551 |
* |
|
552 |
* @return {void} |
|
553 |
*/ |
|
554 |
updateEmptySortablesText: function( visibleSortables, areAllVisibleSortablesEmpty ) { |
|
555 |
var isDashboard = $( '#dashboard-widgets' ).length, |
|
556 |
emptySortableText = areAllVisibleSortablesEmpty ? __( 'Add boxes from the Screen Options menu' ) : __( 'Drag boxes here' ); |
|
557 |
||
558 |
if ( ! isDashboard ) { |
|
559 |
return; |
|
0 | 560 |
} |
16 | 561 |
|
562 |
visibleSortables.each( function() { |
|
563 |
if ( $( this ).hasClass( 'empty-container' ) ) { |
|
564 |
$( this ).attr( 'data-emptyString', emptySortableText ); |
|
565 |
} |
|
566 |
} ); |
|
0 | 567 |
}, |
568 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
/** |
9 | 570 |
* Changes the amount of columns on the post edit page. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* |
16 | 575 |
* @memberof postboxes |
576 |
* |
|
577 |
* @fires postboxes#postboxes-columnchange |
|
578 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* @param {number} n The amount of columns to divide the post edit page in. |
16 | 580 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
*/ |
0 | 582 |
_pb_edit : function(n) { |
583 |
var el = $('.metabox-holder').get(0); |
|
5 | 584 |
|
585 |
if ( el ) { |
|
586 |
el.className = el.className.replace(/columns-\d+/, 'columns-' + n); |
|
587 |
} |
|
588 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* Fires when the amount of columns on the post edit page has been changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* @since 4.0.0 |
9 | 593 |
* @ignore |
594 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* @event postboxes#postboxes-columnchange |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
*/ |
5 | 597 |
$( document ).trigger( 'postboxes-columnchange' ); |
0 | 598 |
}, |
599 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
/** |
9 | 601 |
* Changes the amount of columns the postboxes are in based on the current |
602 |
* orientation of the browser. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* |
16 | 607 |
* @memberof postboxes |
608 |
* |
|
609 |
* @return {void} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
*/ |
0 | 611 |
_pb_change : function() { |
612 |
var check = $( 'label.columns-prefs-1 input[type="radio"]' ); |
|
613 |
||
614 |
switch ( window.orientation ) { |
|
615 |
case 90: |
|
616 |
case -90: |
|
617 |
if ( !check.length || !check.is(':checked') ) |
|
618 |
this._pb_edit(2); |
|
619 |
break; |
|
620 |
case 0: |
|
621 |
case 180: |
|
16 | 622 |
if ( $( '#poststuff' ).length ) { |
0 | 623 |
this._pb_edit(1); |
624 |
} else { |
|
625 |
if ( !check.length || !check.is(':checked') ) |
|
626 |
this._pb_edit(2); |
|
627 |
} |
|
628 |
break; |
|
629 |
} |
|
630 |
}, |
|
631 |
||
632 |
/* Callbacks */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* @access public |
16 | 637 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* @property {Function|boolean} pbshow A callback that is called when a postbox |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* is opened. |
16 | 640 |
* @memberof postboxes |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
*/ |
0 | 642 |
pbshow : false, |
643 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
* @property {Function|boolean} pbhide A callback that is called when a postbox |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
* is closed. |
16 | 649 |
* @memberof postboxes |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
*/ |
0 | 651 |
pbhide : false |
652 |
}; |
|
653 |
||
654 |
}(jQuery)); |