Make WordPress Core


Ignore:
Timestamp:
10/29/2014 10:50:21 PM (10 years ago)
Author:
ocean90
Message:

Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.

  • Introduce models for panels and sections.
  • Introduce API to expand and focus a control, section or panel.
  • Allow deep-linking to panels, sections, and controls inside of the Customizer.
  • Clean up accordion.js, removing all Customizer-specific logic.
  • Add initial unit tests for wp.customize.Class in customize-base.js.

https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.

props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r30055 r30102  
    499499            'values'  => array(),
    500500            'channel' => wp_unslash( $_POST['customize_messenger_channel'] ),
     501            'activePanels' => array(),
     502            'activeSections' => array(),
    501503            'activeControls' => array(),
    502504        );
     
    511513        foreach ( $this->settings as $id => $setting ) {
    512514            $settings['values'][ $id ] = $setting->js_value();
     515        }
     516        foreach ( $this->panels as $id => $panel ) {
     517            $settings['activePanels'][ $id ] = $panel->active();
     518        }
     519        foreach ( $this->sections as $id => $section ) {
     520            $settings['activeSections'][ $id ] = $section->active();
    513521        }
    514522        foreach ( $this->controls as $id => $control ) {
     
    912920            if ( ! $section->panel ) {
    913921                // Top-level section.
    914                 $sections[] = $section;
     922                $sections[ $section->id ] = $section;
    915923            } else {
    916924                // This section belongs to a panel.
    917925                if ( isset( $this->panels [ $section->panel ] ) ) {
    918                     $this->panels[ $section->panel ]->sections[] = $section;
     926                    $this->panels[ $section->panel ]->sections[ $section->id ] = $section;
    919927                }
    920928            }
     
    933941            }
    934942
    935             usort( $panel->sections, array( $this, '_cmp_priority' ) );
    936             $panels[] = $panel;
     943            uasort( $panel->sections, array( $this, '_cmp_priority' ) );
     944            $panels[ $panel->id ] = $panel;
    937945        }
    938946        $this->panels = $panels;
Note: See TracChangeset for help on using the changeset viewer.