WordPress/wp-includes/js/customize-loader.dev.js
koopersmith a5dacf7da5 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: http://svn.automattic.com/wordpress/trunk@20476 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2012-04-16 14:02:28 +00:00

57 lines
1.5 KiB
JavaScript

if ( typeof wp === 'undefined' )
var wp = {};
(function( exports, $ ){
var api = wp.customize,
Loader;
Loader = {
initialize: function() {
this.body = $( document.body ).addClass('customize-support');
this.element = $( '<div id="customize-container" class="wp-full-overlay" />' ).appendTo( this.body );
$('#wpbody').on( 'click', '.load-customize', function( event ) {
event.preventDefault();
// Load the theme.
Loader.open( $(this).attr('href') );
});
},
open: function( src ) {
this.iframe = $( '<iframe />', { src: src }).appendTo( this.element );
// Create a postMessage connection with the iframe.
this.messenger = new api.Messenger( src, this.iframe[0].contentWindow );
// Wait for the connection from the iframe before sending any postMessage events.
this.messenger.bind( 'ready', function() {
Loader.messenger.send( 'back', wpCustomizeLoaderL10n.back );
});
this.messenger.bind( 'close', function() {
Loader.close();
});
this.element.fadeIn( 200, function() {
Loader.body.addClass( 'customize-active full-overlay-active' );
});
},
close: function() {
this.element.fadeOut( 200, function() {
Loader.iframe.remove();
Loader.iframe = null;
Loader.messenger = null;
Loader.body.removeClass( 'customize-active full-overlay-active' );
});
}
};
$( function() {
if ( !! window.postMessage )
Loader.initialize();
});
// Expose the API to the world.
api.Loader = Loader;
})( wp, jQuery );