2012-02-25 05:12:43 +01:00
|
|
|
if ( typeof wp === 'undefined' )
|
|
|
|
var wp = {};
|
|
|
|
|
|
|
|
(function( exports, $ ){
|
2012-04-16 16:02:28 +02:00
|
|
|
var api = wp.customize,
|
|
|
|
Loader;
|
|
|
|
|
|
|
|
Loader = {
|
2012-02-25 05:12:43 +01:00
|
|
|
initialize: function() {
|
2012-04-16 16:02:28 +02:00
|
|
|
this.body = $( document.body ).addClass('customize-support');
|
|
|
|
this.element = $( '<div id="customize-container" class="wp-full-overlay" />' ).appendTo( this.body );
|
2012-02-25 05:12:43 +01:00
|
|
|
|
2012-04-16 16:02:28 +02:00
|
|
|
$('#wpbody').on( 'click', '.load-customize', function( event ) {
|
|
|
|
event.preventDefault();
|
2012-02-25 05:12:43 +01:00
|
|
|
|
2012-04-16 16:02:28 +02:00
|
|
|
// Load the theme.
|
|
|
|
Loader.open( $(this).attr('href') );
|
2012-02-25 05:12:43 +01:00
|
|
|
});
|
|
|
|
},
|
2012-04-16 16:02:28 +02:00
|
|
|
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 );
|
|
|
|
});
|
2012-02-25 05:12:43 +01:00
|
|
|
|
2012-04-16 16:02:28 +02:00
|
|
|
this.messenger.bind( 'close', function() {
|
|
|
|
Loader.close();
|
|
|
|
});
|
2012-02-25 05:12:43 +01:00
|
|
|
|
|
|
|
this.element.fadeIn( 200, function() {
|
2012-03-07 04:19:35 +01:00
|
|
|
Loader.body.addClass( 'customize-active full-overlay-active' );
|
2012-02-25 05:12:43 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
this.element.fadeOut( 200, function() {
|
|
|
|
Loader.iframe.remove();
|
2012-04-16 16:02:28 +02:00
|
|
|
Loader.iframe = null;
|
|
|
|
Loader.messenger = null;
|
2012-03-07 04:19:35 +01:00
|
|
|
Loader.body.removeClass( 'customize-active full-overlay-active' );
|
2012-02-25 05:12:43 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$( function() {
|
2012-04-16 16:02:28 +02:00
|
|
|
if ( !! window.postMessage )
|
|
|
|
Loader.initialize();
|
2012-02-25 05:12:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Expose the API to the world.
|
2012-04-16 16:02:28 +02:00
|
|
|
api.Loader = Loader;
|
2012-02-25 05:12:43 +01:00
|
|
|
})( wp, jQuery );
|