mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 06:37:06 +00:00
Introduce new theme customizer to replace theme preview. Rough first pass. props koopersmith, ocean90. see #19910.
Merges in http://plugins.svn.wordpress.org/gandalf/branches/dev/ rev 510148. git-svn-id: https://develop.svn.wordpress.org/trunk@19995 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
(function( exports, $ ){
|
||||
var api = wp.customize;
|
||||
|
||||
api.Preview = api.Messenger.extend({
|
||||
/**
|
||||
* Requires params:
|
||||
* - url - the URL of preview frame
|
||||
*
|
||||
* @todo: Perhaps add a window.onbeforeunload dialog in case the theme
|
||||
* somehow attempts to leave the page and we don't catch it
|
||||
* (which really shouldn't happen).
|
||||
*/
|
||||
initialize: function( url, options ) {
|
||||
var self = this;
|
||||
|
||||
$.extend( this, options || {} );
|
||||
|
||||
api.Messenger.prototype.initialize.call( this, url );
|
||||
|
||||
this.body = $( document.body );
|
||||
this.body.on( 'click.preview', 'a', function( event ) {
|
||||
event.preventDefault();
|
||||
self.send( 'url', $(this).attr('href') );
|
||||
});
|
||||
|
||||
// You cannot submit forms.
|
||||
// @todo: Namespace customizer settings so that we can mix the
|
||||
// $_POST data with the customize setting $_POST data.
|
||||
this.body.on( 'submit.preview', 'form', function( event ) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
this.bind( 'url', function( url ) {
|
||||
this.url( url );
|
||||
this.refresh();
|
||||
});
|
||||
},
|
||||
refresh: function() {
|
||||
this.submit({
|
||||
target: this.iframe.prop('name'),
|
||||
action: this.url()
|
||||
});
|
||||
},
|
||||
submit: function( props ) {
|
||||
if ( props )
|
||||
this.form.prop( props );
|
||||
this.form.submit();
|
||||
if ( props )
|
||||
this.form.prop( this._formOriginalProps );
|
||||
}
|
||||
});
|
||||
|
||||
$( function() {
|
||||
var preview;
|
||||
|
||||
preview = new api.Preview( api.settings.parent );
|
||||
});
|
||||
|
||||
})( wp, jQuery );
|
||||
Reference in New Issue
Block a user