Make WordPress Core

Changeset 41739


Ignore:
Timestamp:
10/04/2017 04:48:50 PM (7 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r41726 r41739  
    22092209         * @since 4.2.0
    22102210         *
    2211          * @returns {object|boolean} Next theme.
     2211         * @returns {wp.customize.ThemeControl|boolean} Next theme.
    22122212         */
    22132213        getNextTheme: function () {
    2214             var section = this, control, next;
    2215             control = api.control( section.params.action + '_theme_' + this.currentTheme );
    2216             next = control.container.next( 'li.customize-control-theme' );
    2217             if ( ! next.length ) {
     2214            var section = this, control, nextControl, sectionControls, i;
     2215            control = api.control( section.params.action + '_theme_' + section.currentTheme );
     2216            sectionControls = section.controls();
     2217            i = _.indexOf( sectionControls, control );
     2218            if ( -1 === i ) {
    22182219                return false;
    22192220            }
    2220             next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' );
    2221             control = api.control( next );
    2222 
    2223             return control.params.theme;
     2221
     2222            nextControl = sectionControls[ i + 1 ];
     2223            if ( ! nextControl ) {
     2224                return false;
     2225            }
     2226            return nextControl.params.theme;
    22242227        },
    22252228
     
    22432246         *
    22442247         * @since 4.2.0
    2245          * @returns {object|boolean} Previous theme.
     2248         * @returns {wp.customize.ThemeControl|boolean} Previous theme.
    22462249         */
    22472250        getPreviousTheme: function () {
    2248             var section = this, control, previous;
    2249             control = api.control( section.params.action + '_theme_' + this.currentTheme );
    2250             previous = control.container.prev( 'li.customize-control-theme' );
    2251             if ( ! previous.length ) {
     2251            var section = this, control, nextControl, sectionControls, i;
     2252            control = api.control( section.params.action + '_theme_' + section.currentTheme );
     2253            sectionControls = section.controls();
     2254            i = _.indexOf( sectionControls, control );
     2255            if ( -1 === i ) {
    22522256                return false;
    22532257            }
    2254             previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' );
    2255             control = api.control( previous );
    2256 
    2257             return control.params.theme;
     2258
     2259            nextControl = sectionControls[ i - 1 ];
     2260            if ( ! nextControl ) {
     2261                return false;
     2262            }
     2263            return nextControl.params.theme;
    22582264        },
    22592265
Note: See TracChangeset for help on using the changeset viewer.