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