Customizer: Export Previewer instance to wp.customize.previewer, and utilize for Widget Customizer.

props westonruter.
fixes #27666.
Built from https://develop.svn.wordpress.org/trunk@29048


git-svn-id: http://core.svn.wordpress.org/trunk@28836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2014-07-09 20:58:15 +00:00
parent a180b44763
commit 3b291f7057
4 changed files with 25 additions and 36 deletions

View File

@ -913,7 +913,7 @@
if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) )
return window.location = api.settings.url.fallback;
var previewer, parent, topFocus,
var parent, topFocus,
body = $( document.body ),
overlay = body.children( '.wp-full-overlay' ),
title = $( '#customize-info .theme-name.site-title' ),
@ -931,7 +931,7 @@
});
// Initialize Previewer
previewer = new api.Previewer({
api.previewer = new api.Previewer({
container: '#customize-preview',
form: '#customize-controls',
previewUrl: api.settings.url.preview,
@ -1008,14 +1008,14 @@
});
// Refresh the nonces if the preview sends updated nonces over.
previewer.bind( 'nonce', function( nonce ) {
api.previewer.bind( 'nonce', function( nonce ) {
$.extend( this.nonce, nonce );
});
$.each( api.settings.settings, function( id, data ) {
api.create( id, id, data.value, {
transport: data.transport,
previewer: previewer
previewer: api.previewer
} );
});
@ -1025,15 +1025,16 @@
control = api.control.add( id, new constructor( id, {
params: data,
previewer: previewer
previewer: api.previewer
} ) );
});
// Check if preview url is valid and load the preview frame.
if ( previewer.previewUrl() )
previewer.refresh();
else
previewer.previewUrl( api.settings.url.home );
if ( api.previewer.previewUrl() ) {
api.previewer.refresh();
} else {
api.previewer.previewUrl( api.settings.url.home );
}
// Save and activated states
(function() {
@ -1082,13 +1083,13 @@
// Button bindings.
saveBtn.click( function( event ) {
previewer.save();
api.previewer.save();
event.preventDefault();
}).keydown( function( event ) {
if ( 9 === event.which ) // tab
return;
if ( 13 === event.which ) // enter
previewer.save();
api.previewer.save();
event.preventDefault();
});

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
// Set up our namespace...
var api = wp.customize,
l10n, OldPreviewer;
l10n;
api.Widgets = api.Widgets || {};
@ -185,7 +185,7 @@
} );
// Close the panel if the URL in the preview changes
api.Widgets.Previewer.bind( 'url', this.close );
api.previewer.bind( 'url', this.close );
},
// Performs a search and handles selected widget
@ -745,14 +745,14 @@
self.container.removeClass( 'previewer-loading' );
} );
api.Widgets.Previewer.bind( 'widget-updated', function( updatedWidgetId ) {
api.previewer.bind( 'widget-updated', function( updatedWidgetId ) {
if ( updatedWidgetId === self.params.widget_id ) {
self.container.removeClass( 'previewer-loading' );
}
} );
// Update widget control to indicate whether it is currently rendered
api.Widgets.Previewer.bind( 'rendered-widgets', function( renderedWidgets ) {
api.previewer.bind( 'rendered-widgets', function( renderedWidgets ) {
var isRendered = !! renderedWidgets[self.params.widget_id];
self.container.toggleClass( 'widget-rendered', isRendered );
@ -971,17 +971,17 @@
// Check if the user is logged out.
if ( '0' === r ) {
api.Widgets.Previewer.preview.iframe.hide();
api.Widgets.Previewer.login().done( function() {
api.previewer.preview.iframe.hide();
api.previewer.login().done( function() {
self.updateWidget( args );
api.Widgets.Previewer.preview.iframe.show();
api.previewer.preview.iframe.show();
} );
return;
}
// Check for cheaters.
if ( '-1' === r ) {
api.Widgets.Previewer.cheatin();
api.previewer.cheatin();
return;
}
@ -1418,7 +1418,7 @@
} );
// Update the model with whether or not the sidebar is rendered
api.Widgets.Previewer.bind( 'rendered-sidebars', function( renderedSidebars ) {
api.previewer.bind( 'rendered-sidebars', function( renderedSidebars ) {
var isRendered = !! renderedSidebars[self.params.sidebar_id];
registeredSidebar.set( 'is_rendered', isRendered );
@ -1738,18 +1738,6 @@
sidebar_widgets: api.Widgets.SidebarControl
});
/**
* Capture the instance of the Previewer since it is private
*/
OldPreviewer = api.Previewer;
api.Previewer = OldPreviewer.extend({
initialize: function( params, options ) {
api.Widgets.Previewer = this;
OldPreviewer.prototype.initialize.call( this, params, options );
this.bind( 'refresh', this.refresh );
}
} );
/**
* Init Customizer for widgets.
*/
@ -1760,10 +1748,10 @@
});
// Highlight widget control
api.Widgets.Previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl );
api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl );
// Open and focus widget control
api.Widgets.Previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl );
api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl );
} );
/**

File diff suppressed because one or more lines are too long