Wordpress/wp-includes/js/customize-preview.dev.js
Daryl Koopersmith a43958baeb Theme Customizer: Allow the customize iframe to be accessed directly (with full feature support). see #19910.
* Move the 'Return to Manage Themes' and 'Collapse Sidebar' actions from themes.php to customize-controls.php.
* Create a postMessage connection between themes.php and customize-controls.php.
* Allow the theme customizer to be accessed directly (independent of themes.php and the customize loader).
* Add wp_customize_href() and wp_customize_url().
* Remove wp_customize_loader(). To include the loader, use wp_enqueue_script( 'customize-loader' ).
* The theme customizer now requires postMessage browser support.
* Add .hide-if-customize and .hide-if-no-customize CSS classes.
* Clean up customize-preview.js.

git-svn-id: https://develop.svn.wordpress.org/trunk@20476 602fd350-edb4-49c9-b593-d223f7449a82
2012-04-16 14:02:28 +00:00

58 lines
1.4 KiB
JavaScript

(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;
api.Messenger.prototype.initialize.call( this, url, null, options );
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() {
if ( ! api.settings )
return;
var preview, body;
preview = new api.Preview( api.settings.parent );
$.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
api( 'background_color', function( value ) {
value.bind( function( to ) {
body.css( 'background-color', '#' + to );
});
});
});
})( wp, jQuery );