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

File diff suppressed because one or more lines are too long

View File

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