Skip to content

Commit

Permalink
Add back-compat for Customizer in WP<4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter authored and Thierry Muller committed Jan 15, 2018
1 parent 2d818d5 commit 2a05c91
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions assets/js/amp-customize-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,29 @@ var ampCustomizeControls = ( function( api, $ ) {
component.boot = function boot( data ) {
component.data = data;

// Defaults.
function initPanel() {
api.panel( component.data.panelId, component.panelReady );
}

if ( api.state ) {
component.addState();
api.bind( 'ready', initPanel );
} else { // WP<4.9.
api.bind( 'ready', function() {
component.addState(); // Needed for WP<4.9.
initPanel();
} );
}
};

/**
* Add state for AMP.
*
* @returns {void}
*/
component.addState = function addState() {
api.state.add( 'ampEnabled', new api.Value( false ) );
api.state.add( 'ampAvailable', new api.Value( false ) );

api.bind( 'ready', function() {
api.panel( component.data.panelId, component.panelReady );
} );
};

/**
Expand Down

0 comments on commit 2a05c91

Please sign in to comment.