2016-09-22 20:47:31 +02:00
|
|
|
/**
|
|
|
|
* Contains the postboxes logic, opening and closing postboxes, reordering and saving
|
|
|
|
* the state and ordering to the database.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
* @requires jQuery
|
2018-06-28 04:30:15 +02:00
|
|
|
* @output wp-admin/js/postbox.js
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
|
|
|
|
2020-07-06 20:03:02 +02:00
|
|
|
/* global ajaxurl, postboxes */
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
(function($) {
|
2020-07-06 20:03:02 +02:00
|
|
|
var $document = $( document ),
|
|
|
|
__ = wp.i18n.__;
|
2014-08-18 02:35:18 +02:00
|
|
|
|
2018-08-19 15:33:24 +02:00
|
|
|
/**
|
|
|
|
* This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
|
|
|
|
* around the content on the edit page.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @namespace postboxes
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
window.postboxes = {
|
2016-09-22 20:47:31 +02:00
|
|
|
|
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Handles a click on either the postbox heading or the postbox open/close icon.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* Opens or closes the postbox. Expects `this` to equal the clicked element.
|
|
|
|
* Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide
|
|
|
|
* if the postbox has been closed.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @memberof postboxes
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @fires postboxes#postbox-toggled
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2015-10-07 03:58:25 +02:00
|
|
|
handle_click : function () {
|
|
|
|
var $el = $( this ),
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
p = $el.closest( '.postbox' ),
|
2015-10-07 03:58:25 +02:00
|
|
|
id = p.attr( 'id' ),
|
|
|
|
ariaExpandedValue;
|
|
|
|
|
|
|
|
if ( 'dashboard_browser_nag' === id ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
p.toggleClass( 'closed' );
|
|
|
|
ariaExpandedValue = ! p.hasClass( 'closed' );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
if ( $el.hasClass( 'handlediv' ) ) {
|
|
|
|
// The handle button was clicked.
|
|
|
|
$el.attr( 'aria-expanded', ariaExpandedValue );
|
|
|
|
} else {
|
|
|
|
// The handle heading was clicked.
|
|
|
|
$el.closest( '.postbox' ).find( 'button.handlediv' )
|
|
|
|
.attr( 'aria-expanded', ariaExpandedValue );
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
if ( postboxes.page !== 'press-this' ) {
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.save_state( postboxes.page );
|
2015-10-07 03:58:25 +02:00
|
|
|
}
|
2015-08-26 17:23:24 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
if ( id ) {
|
2021-01-22 13:32:03 +01:00
|
|
|
if ( !p.hasClass('closed') && typeof postboxes.pbshow === 'function' ) {
|
2015-10-07 03:58:25 +02:00
|
|
|
postboxes.pbshow( id );
|
2021-01-22 13:32:03 +01:00
|
|
|
} else if ( p.hasClass('closed') && typeof postboxes.pbhide === 'function' ) {
|
2015-10-07 03:58:25 +02:00
|
|
|
postboxes.pbhide( id );
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Fires when a postbox has been opened or closed.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* Contains a jQuery object with the relevant postbox element.
|
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2017-12-15 14:42:46 +01:00
|
|
|
* @ignore
|
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @event postboxes#postbox-toggled
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2015-10-07 03:58:25 +02:00
|
|
|
$document.trigger( 'postbox-toggled', p );
|
|
|
|
},
|
2012-08-23 02:04:18 +02:00
|
|
|
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
/**
|
|
|
|
* Handles clicks on the move up/down buttons.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
handleOrder: function() {
|
|
|
|
var button = $( this ),
|
|
|
|
postbox = button.closest( '.postbox' ),
|
|
|
|
postboxId = postbox.attr( 'id' ),
|
|
|
|
postboxesWithinSortables = postbox.closest( '.meta-box-sortables' ).find( '.postbox:visible' ),
|
|
|
|
postboxesWithinSortablesCount = postboxesWithinSortables.length,
|
|
|
|
postboxWithinSortablesIndex = postboxesWithinSortables.index( postbox ),
|
|
|
|
firstOrLastPositionMessage;
|
|
|
|
|
|
|
|
if ( 'dashboard_browser_nag' === postboxId ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If on the first or last position, do nothing and send an audible message to screen reader users.
|
|
|
|
if ( 'true' === button.attr( 'aria-disabled' ) ) {
|
|
|
|
firstOrLastPositionMessage = button.hasClass( 'handle-order-higher' ) ?
|
|
|
|
__( 'The box is on the first position' ) :
|
|
|
|
__( 'The box is on the last position' );
|
|
|
|
|
|
|
|
wp.a11y.speak( firstOrLastPositionMessage );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
// Move a postbox up.
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
if ( button.hasClass( 'handle-order-higher' ) ) {
|
|
|
|
// If the box is first within a sortable area, move it to the previous sortable area.
|
|
|
|
if ( 0 === postboxWithinSortablesIndex ) {
|
|
|
|
postboxes.handleOrderBetweenSortables( 'previous', button, postbox );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
postbox.prevAll( '.postbox:visible' ).eq( 0 ).before( postbox );
|
|
|
|
button.focus();
|
|
|
|
postboxes.updateOrderButtonsProperties();
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.save_order( postboxes.page );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move a postbox down.
|
|
|
|
if ( button.hasClass( 'handle-order-lower' ) ) {
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
// If the box is last within a sortable area, move it to the next sortable area.
|
|
|
|
if ( postboxWithinSortablesIndex + 1 === postboxesWithinSortablesCount ) {
|
|
|
|
postboxes.handleOrderBetweenSortables( 'next', button, postbox );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
postbox.nextAll( '.postbox:visible' ).eq( 0 ).after( postbox );
|
|
|
|
button.focus();
|
|
|
|
postboxes.updateOrderButtonsProperties();
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.save_order( postboxes.page );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
}
|
2020-10-27 11:47:12 +01:00
|
|
|
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves postboxes between the sortables areas.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
|
|
|
* @param {string} position The "previous" or "next" sortables area.
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {Object} button The jQuery object representing the button that was clicked.
|
|
|
|
* @param {Object} postbox The jQuery object representing the postbox to be moved.
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
handleOrderBetweenSortables: function( position, button, postbox ) {
|
|
|
|
var closestSortablesId = button.closest( '.meta-box-sortables' ).attr( 'id' ),
|
|
|
|
sortablesIds = [],
|
|
|
|
sortablesIndex,
|
|
|
|
detachedPostbox;
|
|
|
|
|
|
|
|
// Get the list of sortables within the page.
|
|
|
|
$( '.meta-box-sortables:visible' ).each( function() {
|
|
|
|
sortablesIds.push( $( this ).attr( 'id' ) );
|
|
|
|
});
|
|
|
|
|
|
|
|
// Return if there's only one visible sortables area, e.g. in the block editor page.
|
|
|
|
if ( 1 === sortablesIds.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the index of the current sortables area within all the sortable areas.
|
|
|
|
sortablesIndex = $.inArray( closestSortablesId, sortablesIds );
|
|
|
|
// Detach the postbox to be moved.
|
|
|
|
detachedPostbox = postbox.detach();
|
|
|
|
|
|
|
|
// Move the detached postbox to its new position.
|
|
|
|
if ( 'previous' === position ) {
|
|
|
|
$( detachedPostbox ).appendTo( '#' + sortablesIds[ sortablesIndex - 1 ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'next' === position ) {
|
|
|
|
$( detachedPostbox ).prependTo( '#' + sortablesIds[ sortablesIndex + 1 ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
postboxes._mark_area();
|
|
|
|
button.focus();
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.updateOrderButtonsProperties();
|
|
|
|
postboxes.save_order( postboxes.page );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the move buttons properties depending on the postbox position.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
updateOrderButtonsProperties: function() {
|
2020-10-27 11:47:12 +01:00
|
|
|
var firstSortablesId = $( '.meta-box-sortables:visible:first' ).attr( 'id' ),
|
|
|
|
lastSortablesId = $( '.meta-box-sortables:visible:last' ).attr( 'id' ),
|
|
|
|
firstPostbox = $( '.postbox:visible:first' ),
|
|
|
|
lastPostbox = $( '.postbox:visible:last' ),
|
|
|
|
firstPostboxId = firstPostbox.attr( 'id' ),
|
|
|
|
lastPostboxId = lastPostbox.attr( 'id' ),
|
|
|
|
firstPostboxSortablesId = firstPostbox.closest( '.meta-box-sortables' ).attr( 'id' ),
|
|
|
|
lastPostboxSortablesId = lastPostbox.closest( '.meta-box-sortables' ).attr( 'id' ),
|
|
|
|
moveUpButtons = $( '.handle-order-higher' ),
|
|
|
|
moveDownButtons = $( '.handle-order-lower' );
|
|
|
|
|
|
|
|
// Enable all buttons as a reset first.
|
|
|
|
moveUpButtons
|
|
|
|
.attr( 'aria-disabled', 'false' )
|
|
|
|
.removeClass( 'hidden' );
|
|
|
|
moveDownButtons
|
|
|
|
.attr( 'aria-disabled', 'false' )
|
|
|
|
.removeClass( 'hidden' );
|
2020-07-13 20:03:05 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
// When there's only one "sortables" area (e.g. in the block editor) and only one visible postbox, hide the buttons.
|
|
|
|
if ( firstSortablesId === lastSortablesId && firstPostboxId === lastPostboxId ) {
|
|
|
|
moveUpButtons.addClass( 'hidden' );
|
|
|
|
moveDownButtons.addClass( 'hidden' );
|
2020-07-13 20:03:05 +02:00
|
|
|
}
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
// Set an aria-disabled=true attribute on the first visible "move" buttons.
|
|
|
|
if ( firstSortablesId === firstPostboxSortablesId ) {
|
|
|
|
$( firstPostbox ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'true' );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
}
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
// Set an aria-disabled=true attribute on the last visible "move" buttons.
|
|
|
|
if ( lastSortablesId === lastPostboxSortablesId ) {
|
|
|
|
$( '.postbox:visible .handle-order-lower' ).last().attr( 'aria-disabled', 'true' );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
|
|
|
* Adds event handlers to all postboxes and screen option on the current page.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @memberof postboxes
|
|
|
|
*
|
|
|
|
* @param {string} page The page we are currently on.
|
|
|
|
* @param {Object} [args]
|
|
|
|
* @param {Function} args.pbshow A callback that is called when a postbox opens.
|
|
|
|
* @param {Function} args.pbhide A callback that is called when a postbox closes.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2020-10-27 11:47:12 +01:00
|
|
|
add_postbox_toggles : function (page, args) {
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
var $handles = $( '.postbox .hndle, .postbox .handlediv' ),
|
2020-10-27 11:47:12 +01:00
|
|
|
$orderButtons = $( '.postbox .handle-order-higher, .postbox .handle-order-lower' );
|
2014-08-18 02:35:18 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
this.page = page;
|
|
|
|
this.init( page, args );
|
|
|
|
|
2015-12-31 12:52:26 +01:00
|
|
|
$handles.on( 'click.postboxes', this.handle_click );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
// Handle the order of the postboxes.
|
|
|
|
$orderButtons.on( 'click.postboxes', this.handleOrder );
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
|
|
|
* @since 2.7.0
|
|
|
|
*/
|
2021-01-22 13:32:03 +01:00
|
|
|
$('.postbox .hndle a').on( 'click', function(e) {
|
2020-10-27 11:47:12 +01:00
|
|
|
e.stopPropagation();
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Hides a postbox.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* Event handler for the postbox dismiss button. After clicking the button
|
|
|
|
* the postbox will be hidden.
|
|
|
|
*
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
* As of WordPress 5.5, this is only used for the browser update nag.
|
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2020-10-27 11:47:12 +01:00
|
|
|
$( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) {
|
|
|
|
var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
|
|
|
|
e.preventDefault();
|
|
|
|
$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Hides the postbox element
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* Event handler for the screen options checkboxes. When a checkbox is
|
|
|
|
* clicked this function will hide or show the relevant postboxes.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
2017-12-15 14:42:46 +01:00
|
|
|
* @ignore
|
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @fires postboxes#postbox-toggled
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2021-01-22 13:32:03 +01:00
|
|
|
$('.hide-postbox-tog').on('click.postboxes', function() {
|
2020-10-27 11:47:12 +01:00
|
|
|
var $el = $(this),
|
2015-10-07 03:58:25 +02:00
|
|
|
boxId = $el.val(),
|
2014-08-18 02:35:18 +02:00
|
|
|
$postbox = $( '#' + boxId );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
if ( $el.prop( 'checked' ) ) {
|
2014-08-18 02:35:18 +02:00
|
|
|
$postbox.show();
|
2021-01-22 13:32:03 +01:00
|
|
|
if ( typeof postboxes.pbshow === 'function' ) {
|
2015-10-07 03:58:25 +02:00
|
|
|
postboxes.pbshow( boxId );
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
} else {
|
2014-08-18 02:35:18 +02:00
|
|
|
$postbox.hide();
|
2021-01-22 13:32:03 +01:00
|
|
|
if ( typeof postboxes.pbhide === 'function' ) {
|
2015-10-07 03:58:25 +02:00
|
|
|
postboxes.pbhide( boxId );
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
2016-09-22 20:47:31 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.save_state( page );
|
2015-10-07 03:58:25 +02:00
|
|
|
postboxes._mark_area();
|
2016-09-22 20:47:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 4.0.0
|
|
|
|
* @see postboxes.handle_click
|
|
|
|
*/
|
2014-08-18 02:35:18 +02:00
|
|
|
$document.trigger( 'postbox-toggled', $postbox );
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Changes the amount of columns based on the layout preferences.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2021-01-22 13:32:03 +01:00
|
|
|
$('.columns-prefs input[type="radio"]').on('click.postboxes', function(){
|
2020-10-27 11:47:12 +01:00
|
|
|
var n = parseInt($(this).val(), 10);
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
if ( n ) {
|
|
|
|
postboxes._pb_edit(n);
|
|
|
|
postboxes.save_order( page );
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
/**
|
|
|
|
* Initializes all the postboxes, mainly their sortable behaviour.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @memberof postboxes
|
|
|
|
*
|
|
|
|
* @param {string} page The page we are currently on.
|
|
|
|
* @param {Object} [args={}] The arguments for the postbox initializer.
|
|
|
|
* @param {Function} args.pbshow A callback that is called when a postbox opens.
|
|
|
|
* @param {Function} args.pbhide A callback that is called when a postbox
|
|
|
|
* closes.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
init : function(page, args) {
|
|
|
|
var isMobile = $( document.body ).hasClass( 'mobile' ),
|
|
|
|
$handleButtons = $( '.postbox .handlediv' );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
$.extend( this, args || {} );
|
|
|
|
$('.meta-box-sortables').sortable({
|
2012-08-23 02:04:18 +02:00
|
|
|
placeholder: 'sortable-placeholder',
|
|
|
|
connectWith: '.meta-box-sortables',
|
|
|
|
items: '.postbox',
|
|
|
|
handle: '.hndle',
|
|
|
|
cursor: 'move',
|
2020-10-27 11:47:12 +01:00
|
|
|
delay: ( isMobile ? 200 : 0 ),
|
2012-08-23 02:04:18 +02:00
|
|
|
distance: 2,
|
|
|
|
tolerance: 'pointer',
|
|
|
|
forcePlaceholderSize: true,
|
2015-12-06 23:23:49 +01:00
|
|
|
helper: function( event, element ) {
|
2016-09-22 20:47:31 +02:00
|
|
|
/* `helper: 'clone'` is equivalent to `return element.clone();`
|
|
|
|
* Cloning a checked radio and then inserting that clone next to the original
|
|
|
|
* radio unchecks the original radio (since only one of the two can be checked).
|
|
|
|
* We get around this by renaming the helper's inputs' name attributes so that,
|
|
|
|
* when the helper is inserted into the DOM for the sortable, no radios are
|
|
|
|
* duplicated, and no original radio gets unchecked.
|
|
|
|
*/
|
2015-12-06 23:23:49 +01:00
|
|
|
return element.clone()
|
|
|
|
.find( ':input' )
|
2020-10-27 11:47:12 +01:00
|
|
|
.attr( 'name', function( i, currentName ) {
|
|
|
|
return 'sort_' + parseInt( Math.random() * 100000, 10 ).toString() + '_' + currentName;
|
|
|
|
} )
|
2015-12-06 23:23:49 +01:00
|
|
|
.end();
|
|
|
|
},
|
2020-10-27 11:47:12 +01:00
|
|
|
opacity: 0.65,
|
2020-07-06 20:03:02 +02:00
|
|
|
start: function() {
|
2020-10-27 11:47:12 +01:00
|
|
|
$( 'body' ).addClass( 'is-dragging-metaboxes' );
|
2020-08-04 15:17:02 +02:00
|
|
|
// Refresh the cached positions of all the sortable items so that the min-height set while dragging works.
|
|
|
|
$( '.meta-box-sortables' ).sortable( 'refreshPositions' );
|
2020-07-06 20:03:02 +02:00
|
|
|
},
|
2013-11-14 19:10:09 +01:00
|
|
|
stop: function() {
|
2015-10-07 03:58:25 +02:00
|
|
|
var $el = $( this );
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
$( 'body' ).removeClass( 'is-dragging-metaboxes' );
|
2020-07-06 20:03:02 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
if ( $el.find( '#dashboard_browser_nag' ).is( ':visible' ) && 'dashboard_browser_nag' != this.firstChild.id ) {
|
2020-10-27 11:47:12 +01:00
|
|
|
$el.sortable('cancel');
|
2012-08-23 02:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.updateOrderButtonsProperties();
|
|
|
|
postboxes.save_order(page);
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
2020-10-27 11:47:12 +01:00
|
|
|
receive: function(e,ui) {
|
|
|
|
if ( 'dashboard_browser_nag' == ui.item[0].id )
|
|
|
|
$(ui.sender).sortable('cancel');
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes._mark_area();
|
2016-06-09 00:37:29 +02:00
|
|
|
$document.trigger( 'postbox-moved', ui.item );
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
if ( isMobile ) {
|
2021-01-22 13:32:03 +01:00
|
|
|
$(document.body).on('orientationchange.postboxes', function(){ postboxes._pb_change(); });
|
2012-08-23 02:04:18 +02:00
|
|
|
this._pb_change();
|
|
|
|
}
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
this._mark_area();
|
2020-10-17 12:00:06 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
// Update the "move" buttons properties.
|
|
|
|
this.updateOrderButtonsProperties();
|
|
|
|
$document.on( 'postbox-toggled', this.updateOrderButtonsProperties );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
|
2015-10-07 03:58:25 +02:00
|
|
|
// Set the handle buttons `aria-expanded` attribute initial value on page load.
|
2020-10-27 11:47:12 +01:00
|
|
|
$handleButtons.each( function () {
|
2015-10-07 03:58:25 +02:00
|
|
|
var $el = $( this );
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
$el.attr( 'aria-expanded', ! $el.closest( '.postbox' ).hasClass( 'closed' ) );
|
2015-10-07 03:58:25 +02:00
|
|
|
});
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Saves the state of the postboxes to the server.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
2017-12-18 15:14:53 +01:00
|
|
|
* It sends two lists, one with all the closed postboxes, one with all the
|
|
|
|
* hidden postboxes.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @memberof postboxes
|
|
|
|
*
|
|
|
|
* @param {string} page The page we are currently on.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2020-10-27 11:47:12 +01:00
|
|
|
save_state : function(page) {
|
2015-12-31 12:52:26 +01:00
|
|
|
var closed, hidden;
|
|
|
|
|
|
|
|
// Return on the nav-menus.php screen, see #35112.
|
2020-10-27 11:47:12 +01:00
|
|
|
if ( 'nav-menus' === page ) {
|
2015-12-31 12:52:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
closed = $( '.postbox' ).filter( '.closed' ).map( function() { return this.id; } ).get().join( ',' );
|
|
|
|
hidden = $( '.postbox' ).filter( ':hidden' ).map( function() { return this.id; } ).get().join( ',' );
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
$.post(ajaxurl, {
|
2012-08-23 02:04:18 +02:00
|
|
|
action: 'closed-postboxes',
|
|
|
|
closed: closed,
|
|
|
|
hidden: hidden,
|
2020-10-27 11:47:12 +01:00
|
|
|
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
|
|
|
page: page
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Saves the order of the postboxes to the server.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
2017-12-18 15:14:53 +01:00
|
|
|
* Sends a list of all postboxes inside a sortable area to the server.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* @since 2.8.0
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @memberof postboxes
|
|
|
|
*
|
2020-10-27 11:47:12 +01:00
|
|
|
* @param {string} page The page we are currently on.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2020-10-27 11:47:12 +01:00
|
|
|
save_order : function(page) {
|
|
|
|
var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
|
|
|
|
|
|
|
|
postVars = {
|
2012-08-23 02:04:18 +02:00
|
|
|
action: 'meta-box-order',
|
2020-10-27 11:47:12 +01:00
|
|
|
_ajax_nonce: $('#meta-box-order-nonce').val(),
|
|
|
|
page_columns: page_columns,
|
|
|
|
page: page
|
2013-11-14 19:10:09 +01:00
|
|
|
};
|
2016-09-22 20:47:31 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
$('.meta-box-sortables').each( function() {
|
2013-11-14 19:10:09 +01:00
|
|
|
postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
|
2012-08-23 02:04:18 +02:00
|
|
|
} );
|
2016-09-22 20:47:31 +02:00
|
|
|
|
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 15:00:02 +02:00
|
|
|
$.post(
|
|
|
|
ajaxurl,
|
|
|
|
postVars,
|
|
|
|
function( response ) {
|
|
|
|
if ( response.success ) {
|
|
|
|
wp.a11y.speak( __( 'The boxes order has been saved.' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Marks empty postbox areas.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* Adds a message to empty sortable areas on the dashboard page. Also adds a
|
|
|
|
* border around the side area on the post edit screen if there are no postboxes
|
|
|
|
* present.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @access private
|
|
|
|
*
|
2020-01-29 01:45:18 +01:00
|
|
|
* @memberof postboxes
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2012-08-23 02:04:18 +02:00
|
|
|
_mark_area : function() {
|
2020-10-27 11:47:12 +01:00
|
|
|
var visible = $( 'div.postbox:visible' ).length,
|
|
|
|
visibleSortables = $( '#dashboard-widgets .meta-box-sortables:visible, #post-body .meta-box-sortables:visible' ),
|
|
|
|
areAllVisibleSortablesEmpty = true;
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
visibleSortables.each( function() {
|
|
|
|
var t = $(this);
|
2012-08-23 02:04:18 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
if ( visible == 1 || t.children( '.postbox:visible' ).length ) {
|
|
|
|
t.removeClass('empty-container');
|
|
|
|
areAllVisibleSortablesEmpty = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
t.addClass('empty-container');
|
2020-10-17 12:00:06 +02:00
|
|
|
}
|
|
|
|
});
|
2020-07-06 20:03:02 +02:00
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
postboxes.updateEmptySortablesText( visibleSortables, areAllVisibleSortablesEmpty );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the text for the empty sortable areas on the Dashboard.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
|
|
|
* @param {Object} visibleSortables The jQuery object representing the visible sortable areas.
|
|
|
|
* @param {boolean} areAllVisibleSortablesEmpty Whether all the visible sortable areas are "empty".
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
updateEmptySortablesText: function( visibleSortables, areAllVisibleSortablesEmpty ) {
|
|
|
|
var isDashboard = $( '#dashboard-widgets' ).length,
|
|
|
|
emptySortableText = areAllVisibleSortablesEmpty ? __( 'Add boxes from the Screen Options menu' ) : __( 'Drag boxes here' );
|
|
|
|
|
|
|
|
if ( ! isDashboard ) {
|
|
|
|
return;
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
2020-10-27 11:47:12 +01:00
|
|
|
|
|
|
|
visibleSortables.each( function() {
|
|
|
|
if ( $( this ).hasClass( 'empty-container' ) ) {
|
|
|
|
$( this ).attr( 'data-emptyString', emptySortableText );
|
|
|
|
}
|
|
|
|
} );
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Changes the amount of columns on the post edit page.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2020-01-29 01:45:18 +01:00
|
|
|
* @access private
|
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @memberof postboxes
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @fires postboxes#postboxes-columnchange
|
|
|
|
*
|
|
|
|
* @param {number} n The amount of columns to divide the post edit page in.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2020-10-27 11:47:12 +01:00
|
|
|
_pb_edit : function(n) {
|
|
|
|
var el = $('.metabox-holder').get(0);
|
2013-12-09 05:21:10 +01:00
|
|
|
|
|
|
|
if ( el ) {
|
2020-10-27 11:47:12 +01:00
|
|
|
el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
|
2013-12-09 05:21:10 +01:00
|
|
|
}
|
2014-07-10 00:06:15 +02:00
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
|
|
|
* Fires when the amount of columns on the post edit page has been changed.
|
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2017-12-15 14:42:46 +01:00
|
|
|
* @ignore
|
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @event postboxes#postboxes-columnchange
|
|
|
|
*/
|
2014-07-10 00:06:15 +02:00
|
|
|
$( document ).trigger( 'postboxes-columnchange' );
|
2012-08-23 02:04:18 +02:00
|
|
|
},
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Changes the amount of columns the postboxes are in based on the current
|
|
|
|
* orientation of the browser.
|
2016-09-22 20:47:31 +02:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @access private
|
|
|
|
*
|
2020-01-29 01:45:18 +01:00
|
|
|
* @memberof postboxes
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2012-08-23 02:04:18 +02:00
|
|
|
_pb_change : function() {
|
|
|
|
var check = $( 'label.columns-prefs-1 input[type="radio"]' );
|
|
|
|
|
|
|
|
switch ( window.orientation ) {
|
|
|
|
case 90:
|
|
|
|
case -90:
|
2020-10-27 11:47:12 +01:00
|
|
|
if ( !check.length || !check.is(':checked') )
|
|
|
|
this._pb_edit(2);
|
2012-08-23 02:04:18 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
case 180:
|
2020-03-03 01:37:06 +01:00
|
|
|
if ( $( '#poststuff' ).length ) {
|
2020-10-27 11:47:12 +01:00
|
|
|
this._pb_edit(1);
|
|
|
|
} else {
|
|
|
|
if ( !check.length || !check.is(':checked') )
|
|
|
|
this._pb_edit(2);
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Callbacks */
|
2016-09-22 20:47:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.7.0
|
|
|
|
* @access public
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2016-09-22 20:47:31 +02:00
|
|
|
* @property {Function|boolean} pbshow A callback that is called when a postbox
|
|
|
|
* is opened.
|
2020-01-29 01:45:18 +01:00
|
|
|
* @memberof postboxes
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2012-08-23 02:04:18 +02:00
|
|
|
pbshow : false,
|
|
|
|
|
2016-09-22 20:47:31 +02:00
|
|
|
/**
|
|
|
|
* @since 2.7.0
|
|
|
|
* @access public
|
|
|
|
* @property {Function|boolean} pbhide A callback that is called when a postbox
|
|
|
|
* is closed.
|
2020-01-29 01:45:18 +01:00
|
|
|
* @memberof postboxes
|
2016-09-22 20:47:31 +02:00
|
|
|
*/
|
2012-08-23 02:04:18 +02:00
|
|
|
pbhide : false
|
|
|
|
};
|
|
|
|
|
2020-10-27 11:47:12 +01:00
|
|
|
}(jQuery));
|