mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 06:37:06 +00:00
Customizer: Add stable sorting for panels, sections and controls in JS. Improve sorting in PHP.
props westonruter. fixes #30225. git-svn-id: https://develop.svn.wordpress.org/trunk@30214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* globals _wpCustomizeHeader, _wpMediaViewsL10n */
|
||||
(function( exports, $ ){
|
||||
var bubbleChildValueChanges, Container, focus, isKeydownButNotEnterEvent, areElementListsEqual, api = wp.customize;
|
||||
var bubbleChildValueChanges, Container, focus, isKeydownButNotEnterEvent, areElementListsEqual, prioritySort, api = wp.customize;
|
||||
|
||||
// @todo Move private helper functions to wp.customize.utils so they can be unit tested
|
||||
|
||||
@@ -77,6 +77,23 @@
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stable sort for Panels, Sections, and Controls.
|
||||
*
|
||||
* If a.priority() === b.priority(), then sort by their respective params.instanceNumber.
|
||||
*
|
||||
* @param {(wp.customize.Panel|wp.customize.Section|wp.customize.Control)} a
|
||||
* @param {(wp.customize.Panel|wp.customize.Section|wp.customize.Control)} b
|
||||
* @returns {Number}
|
||||
*/
|
||||
prioritySort = function ( a, b ) {
|
||||
if ( a.priority() === b.priority() && typeof a.params.instanceNumber === 'number' && typeof b.params.instanceNumber === 'number' ) {
|
||||
return a.params.instanceNumber - b.params.instanceNumber;
|
||||
} else {
|
||||
return a.priority() - b.priority();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return whether the supplied Event object is for a keydown event but not the Enter key.
|
||||
*
|
||||
@@ -176,9 +193,7 @@
|
||||
children.push( child );
|
||||
}
|
||||
} );
|
||||
children.sort( function ( a, b ) {
|
||||
return a.priority() - b.priority();
|
||||
} );
|
||||
children.sort( prioritySort );
|
||||
return children;
|
||||
},
|
||||
|
||||
@@ -1952,9 +1967,7 @@
|
||||
} );
|
||||
|
||||
// Sort the root panels and sections
|
||||
rootNodes.sort( function ( a, b ) {
|
||||
return a.priority() - b.priority();
|
||||
} );
|
||||
rootNodes.sort( prioritySort );
|
||||
rootContainers = _.pluck( rootNodes, 'container' );
|
||||
appendContainer = $( '#customize-theme-controls' ).children( 'ul' ); // @todo This should be defined elsewhere, and to be configurable
|
||||
if ( ! areElementListsEqual( rootContainers, appendContainer.children() ) ) {
|
||||
|
||||
Reference in New Issue
Block a user