2012-02-24 23:12:43 -05:00
|
|
|
(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;
|
|
|
|
|
2012-04-16 10:02:28 -04:00
|
|
|
api.Messenger.prototype.initialize.call( this, url, null, options );
|
2012-02-24 23:12:43 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( function() {
|
2012-05-07 16:03:39 -04:00
|
|
|
api.settings = window._wpCustomizeSettings;
|
2012-03-05 21:49:02 -05:00
|
|
|
if ( ! api.settings )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var preview, body;
|
2012-02-24 23:12:43 -05:00
|
|
|
|
2012-05-08 16:13:34 -04:00
|
|
|
preview = new api.Preview( window.location.href );
|
2012-03-05 21:49:02 -05:00
|
|
|
|
|
|
|
$.each( api.settings.values, function( id, value ) {
|
|
|
|
api.set( id, value );
|
|
|
|
});
|
|
|
|
|
|
|
|
preview.bind( 'setting', function( args ) {
|
|
|
|
api.set.apply( api, args );
|
|
|
|
});
|
|
|
|
|
|
|
|
body = $(document.body);
|
|
|
|
// Auto update background color by default
|
2012-03-22 03:03:44 -04:00
|
|
|
api( 'background_color', function( value ) {
|
|
|
|
value.bind( function( to ) {
|
2012-04-25 17:03:29 -04:00
|
|
|
body.css( 'background-color', to ? '#' + to : '' );
|
2012-03-22 03:03:44 -04:00
|
|
|
});
|
2012-03-05 21:49:02 -05:00
|
|
|
});
|
2012-02-24 23:12:43 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
})( wp, jQuery );
|