Theme Customizer: Separate message url from preview url in customizer JS Previewer and PreviewFrame objects. fixes #20892.
git-svn-id: http://core.svn.wordpress.org/trunk@21033 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
82e9205d58
commit
6c273ba9e4
@ -301,6 +301,8 @@
|
|||||||
|
|
||||||
api.Messenger.prototype.initialize.call( this, params, options );
|
api.Messenger.prototype.initialize.call( this, params, options );
|
||||||
|
|
||||||
|
this.add( 'previewUrl', params.previewUrl );
|
||||||
|
|
||||||
this.bind( 'ready', function() {
|
this.bind( 'ready', function() {
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|
||||||
@ -310,7 +312,7 @@
|
|||||||
|
|
||||||
params.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() });
|
params.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() });
|
||||||
|
|
||||||
this.request = $.ajax( this.url(), {
|
this.request = $.ajax( this.previewUrl(), {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: params.query,
|
data: params.query,
|
||||||
xhrFields: {
|
xhrFields: {
|
||||||
@ -329,7 +331,7 @@
|
|||||||
|
|
||||||
// Check if the location response header differs from the current URL.
|
// Check if the location response header differs from the current URL.
|
||||||
// If so, the request was redirected; try loading the requested page.
|
// If so, the request was redirected; try loading the requested page.
|
||||||
if ( location && location != self.url() ) {
|
if ( location && location != self.previewUrl() ) {
|
||||||
deferred.rejectWith( self, [ 'redirect', location ] );
|
deferred.rejectWith( self, [ 'redirect', location ] );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -410,8 +412,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Requires params:
|
* Requires params:
|
||||||
* - container - a selector or jQuery element
|
* - container - a selector or jQuery element
|
||||||
* - url - the URL of preview frame
|
* - previewUrl - the URL of preview frame
|
||||||
*/
|
*/
|
||||||
initialize: function( params, options ) {
|
initialize: function( params, options ) {
|
||||||
var self = this,
|
var self = this,
|
||||||
@ -457,15 +459,10 @@
|
|||||||
this.container = api.ensure( params.container );
|
this.container = api.ensure( params.container );
|
||||||
this.allowedUrls = params.allowedUrls;
|
this.allowedUrls = params.allowedUrls;
|
||||||
|
|
||||||
url = params.url;
|
params.url = window.location.href;
|
||||||
delete params.url;
|
|
||||||
|
|
||||||
api.Messenger.prototype.initialize.call( this, params );
|
api.Messenger.prototype.initialize.call( this, params );
|
||||||
|
|
||||||
// We're dynamically generating the iframe, so the origin is set
|
|
||||||
// to the current window's location, not the url's.
|
|
||||||
this.origin.unlink( this.url ).set( window.location.href );
|
|
||||||
|
|
||||||
this.add( 'scheme', this.origin() ).link( this.origin ).setter( function( to ) {
|
this.add( 'scheme', this.origin() ).link( this.origin ).setter( function( to ) {
|
||||||
var match = to.match( rscheme );
|
var match = to.match( rscheme );
|
||||||
return match ? match[0] : '';
|
return match ? match[0] : '';
|
||||||
@ -479,7 +476,7 @@
|
|||||||
// are on different domains to avoid the case where the frontend doesn't have
|
// are on different domains to avoid the case where the frontend doesn't have
|
||||||
// ssl certs.
|
// ssl certs.
|
||||||
|
|
||||||
this.url.setter( function( to ) {
|
this.add( 'previewUrl', params.previewUrl ).setter( function( to ) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// Check for URLs that include "/wp-admin/" or end in "/wp-admin".
|
// Check for URLs that include "/wp-admin/" or end in "/wp-admin".
|
||||||
@ -504,11 +501,8 @@
|
|||||||
return result ? result : null;
|
return result ? result : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set the url.
|
|
||||||
this.url( url );
|
|
||||||
|
|
||||||
// Refresh the preview when the URL is changed (but not yet).
|
// Refresh the preview when the URL is changed (but not yet).
|
||||||
this.url.bind( this.refresh );
|
this.previewUrl.bind( this.refresh );
|
||||||
|
|
||||||
this.scroll = 0;
|
this.scroll = 0;
|
||||||
this.bind( 'scroll', function( distance ) {
|
this.bind( 'scroll', function( distance ) {
|
||||||
@ -516,7 +510,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Update the URL when the iframe sends a URL message.
|
// Update the URL when the iframe sends a URL message.
|
||||||
this.bind( 'url', this.url );
|
this.bind( 'url', this.previewUrl );
|
||||||
},
|
},
|
||||||
|
|
||||||
query: function() {},
|
query: function() {},
|
||||||
@ -534,17 +528,18 @@
|
|||||||
this.abort();
|
this.abort();
|
||||||
|
|
||||||
this.loading = new api.PreviewFrame({
|
this.loading = new api.PreviewFrame({
|
||||||
url: this.url(),
|
url: this.url(),
|
||||||
query: this.query() || {},
|
previewUrl: this.previewUrl(),
|
||||||
previewer: this
|
query: this.query() || {},
|
||||||
|
previewer: this
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loading.done( function() {
|
this.loading.done( function() {
|
||||||
// 'this' is the loading frame
|
// 'this' is the loading frame
|
||||||
this.bind( 'synced', function() {
|
this.bind( 'synced', function() {
|
||||||
if ( self.iframe )
|
if ( self.preview )
|
||||||
self.iframe.destroy();
|
self.preview.destroy();
|
||||||
self.iframe = this;
|
self.preview = this;
|
||||||
delete self.loading;
|
delete self.loading;
|
||||||
|
|
||||||
self.targetWindow( this.targetWindow() );
|
self.targetWindow( this.targetWindow() );
|
||||||
@ -559,12 +554,12 @@
|
|||||||
|
|
||||||
this.loading.fail( function( reason, location ) {
|
this.loading.fail( function( reason, location ) {
|
||||||
if ( 'redirect' === reason && location )
|
if ( 'redirect' === reason && location )
|
||||||
self.url( location );
|
self.previewUrl( location );
|
||||||
|
|
||||||
if ( 'logged out' === reason ) {
|
if ( 'logged out' === reason ) {
|
||||||
if ( self.iframe ) {
|
if ( self.preview ) {
|
||||||
self.iframe.destroy();
|
self.preview.destroy();
|
||||||
delete self.iframe;
|
delete self.preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.login().done( self.refresh );
|
self.login().done( self.refresh );
|
||||||
@ -648,7 +643,7 @@
|
|||||||
previewer = new api.Previewer({
|
previewer = new api.Previewer({
|
||||||
container: '#customize-preview',
|
container: '#customize-preview',
|
||||||
form: '#customize-controls',
|
form: '#customize-controls',
|
||||||
url: api.settings.url.preview,
|
previewUrl: api.settings.url.preview,
|
||||||
allowedUrls: api.settings.url.allowed
|
allowedUrls: api.settings.url.allowed
|
||||||
}, {
|
}, {
|
||||||
query: function() {
|
query: function() {
|
||||||
@ -680,10 +675,10 @@
|
|||||||
request.done( function( response ) {
|
request.done( function( response ) {
|
||||||
// Check if the user is logged out.
|
// Check if the user is logged out.
|
||||||
if ( '0' === response ) {
|
if ( '0' === response ) {
|
||||||
self.iframe.iframe.hide();
|
self.preview.iframe.hide();
|
||||||
self.login().done( function() {
|
self.login().done( function() {
|
||||||
self.save();
|
self.save();
|
||||||
self.iframe.iframe.show();
|
self.preview.iframe.show();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -717,10 +712,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check if preview url is valid and load the preview frame.
|
// Check if preview url is valid and load the preview frame.
|
||||||
if ( previewer.url() )
|
if ( previewer.previewUrl() )
|
||||||
previewer.refresh();
|
previewer.refresh();
|
||||||
else
|
else
|
||||||
previewer.url( api.settings.url.home );
|
previewer.previewUrl( api.settings.url.home );
|
||||||
|
|
||||||
// Save and activated states
|
// Save and activated states
|
||||||
(function() {
|
(function() {
|
||||||
|
@ -192,8 +192,11 @@ if ( typeof wp === 'undefined' )
|
|||||||
},
|
},
|
||||||
|
|
||||||
setter: function( callback ) {
|
setter: function( callback ) {
|
||||||
|
var from = this.get();
|
||||||
this._setter = callback;
|
this._setter = callback;
|
||||||
this.set( this.get() );
|
// Temporarily clear value so setter can decide if it's valid.
|
||||||
|
this._value = null;
|
||||||
|
this.set( from );
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user