From a0a2a4a1057c78a4daf277032a81ff5797961c07 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Oct 2017 16:48:50 +0000 Subject: [PATCH] Customize: Fix theme details modal by updating logic in `getPreviousTheme` and `getNextTheme` to not rely on DOM traversal and manually constructing control IDs. Amends [41726]. See #42083, #37661. git-svn-id: https://develop.svn.wordpress.org/trunk@41739 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index bcfe9a8278..d94dba91f8 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -2208,19 +2208,22 @@ * * @since 4.2.0 * - * @returns {object|boolean} Next theme. + * @returns {wp.customize.ThemeControl|boolean} Next theme. */ getNextTheme: function () { - var section = this, control, next; - control = api.control( section.params.action + '_theme_' + this.currentTheme ); - next = control.container.next( 'li.customize-control-theme' ); - if ( ! next.length ) { + var section = this, control, nextControl, sectionControls, i; + control = api.control( section.params.action + '_theme_' + section.currentTheme ); + sectionControls = section.controls(); + i = _.indexOf( sectionControls, control ); + if ( -1 === i ) { return false; } - next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); - control = api.control( next ); - return control.params.theme; + nextControl = sectionControls[ i + 1 ]; + if ( ! nextControl ) { + return false; + } + return nextControl.params.theme; }, /** @@ -2242,19 +2245,22 @@ * Get the previous theme model. * * @since 4.2.0 - * @returns {object|boolean} Previous theme. + * @returns {wp.customize.ThemeControl|boolean} Previous theme. */ getPreviousTheme: function () { - var section = this, control, previous; - control = api.control( section.params.action + '_theme_' + this.currentTheme ); - previous = control.container.prev( 'li.customize-control-theme' ); - if ( ! previous.length ) { + var section = this, control, nextControl, sectionControls, i; + control = api.control( section.params.action + '_theme_' + section.currentTheme ); + sectionControls = section.controls(); + i = _.indexOf( sectionControls, control ); + if ( -1 === i ) { return false; } - previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); - control = api.control( previous ); - return control.params.theme; + nextControl = sectionControls[ i - 1 ]; + if ( ! nextControl ) { + return false; + } + return nextControl.params.theme; }, /**