Theme Customizer: Improve activate and publish flow, make customizer states easier to track. fixes #20743, see #19910.

git-svn-id: https://develop.svn.wordpress.org/trunk@20899 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith
2012-05-25 17:42:06 +00:00
parent 53d8ab60ec
commit d49df83c8c
4 changed files with 70 additions and 44 deletions
+64 -14
View File
@@ -439,13 +439,14 @@
api.settings = window._wpCustomizeSettings;
api.l10n = window._wpCustomizeControlsL10n;
// Check if we can run the customizer.
if ( ! api.settings )
return;
// Redirect to the fallback preview if any incompatibilities are found.
if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) )
return window.location = api.settings.url.fallback;
// Initialize Previewer
var body = $( document.body ),
query, previewer, parent;
@@ -455,6 +456,7 @@
e.preventDefault();
});
// Initialize Previewer
previewer = new api.Previewer({
container: '#customize-preview',
form: '#customize-controls',
@@ -481,9 +483,14 @@
api.trigger( 'save', request );
body.addClass('saving');
request.always( function() {
body.removeClass('saving');
});
request.done( function() {
api.trigger( 'saved' );
});
}
});
@@ -507,6 +514,57 @@
// Load the preview frame.
previewer.refresh();
// Save and activated states
(function() {
var state = new api.Values(),
saved = state.create('saved'),
activated = state.create('activated');
state.bind( 'change', function() {
var save = $('#save'),
back = $('.back');
if ( ! activated() ) {
save.val( api.l10n.activate ).prop( 'disabled', false );
back.text( api.l10n.cancel );
} else if ( saved() ) {
save.val( api.l10n.saved ).prop( 'disabled', true );
back.text( api.l10n.close );
} else {
save.val( api.l10n.save ).prop( 'disabled', false );
back.text( api.l10n.cancel );
}
});
// Set default states.
saved( true );
activated( api.settings.theme.active );
api.bind( 'change', function() {
state('saved').set( false );
});
api.bind( 'saved', function() {
state('saved').set( true );
state('activated').set( true );
});
activated.bind( function( to ) {
if ( to )
api.trigger( 'activated' );
});
// Expose states to the API.
api.state = state;
}());
api.bind( 'activated', function() {
if ( api.settings.url.activated )
window.location = api.settings.url.activated;
});
// Temporary accordion code.
$('.customize-section-title').click( function() {
var clicked = $( this ).parents( '.customize-section' );
@@ -538,20 +596,12 @@
});
});
// If the current theme isn't active, it will be activated on save,
// rendering the previous page
api.bind( 'save', function( request ) {
request.done( function() {
parent.send( 'saved' );
if ( ! api.settings.theme.active ) {
parent.send( 'switched' );
$('#save').val( api.l10n.save );
}
api.settings.theme.active = true;
// Pass events through to the parent.
$.each([ 'saved', 'activated' ], function( i, id ) {
api.bind( id, function() {
parent.send( id );
});
} );
});
// Initialize the connection with the parent frame.
parent.send( 'ready' );
+5 -1
View File
@@ -302,7 +302,11 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->add( 'customize-controls', "/wp-includes/js/customize-controls$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
'save' => __( 'Save & Publish' ),
'activate' => __( 'Save & Activate' ),
'save' => __( 'Save & Publish' ),
'saved' => __( 'Saved' ),
'cancel' => __( 'Cancel' ),
'close' => __( 'Close' ),
) );
if ( is_admin() ) {