X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/8f374b7233bc2815ccc387e448d208c5434eb961..6c8f14c09105d0afa4c1574215c59b5021040e76:/wp-includes/js/customize-loader.js diff --git a/wp-includes/js/customize-loader.js b/wp-includes/js/customize-loader.js index 4c7e0853..2ecbbe0f 100644 --- a/wp-includes/js/customize-loader.js +++ b/wp-includes/js/customize-loader.js @@ -1 +1,164 @@ -if(typeof wp==="undefined"){var wp={}}(function(a,c){var b=wp.customize,d;c.extend(c.support,{history:!!(window.history&&history.pushState),hashchange:("onhashchange" in window)&&(document.documentMode===undefined||document.documentMode>7)});d=c.extend({},b.Events,{initialize:function(){this.body=c(document.body);if(!d.settings||!c.support.postMessage||(!c.support.cors&&d.settings.isCrossDomain)){return}this.window=c(window);this.element=c('
').appendTo(this.body);this.bind("open",this.overlay.show);this.bind("close",this.overlay.hide);c("#wpbody").on("click",".load-customize",function(e){e.preventDefault();d.open(c(this).attr("href"))});if(c.support.history){this.window.on("popstate",d.popstate)}if(c.support.hashchange){this.window.on("hashchange",d.hashchange);this.window.triggerHandler("hashchange")}},popstate:function(g){var f=g.originalEvent.state;if(f&&f.customize){d.open(f.customize)}else{if(d.active){d.close()}}},hashchange:function(g){var f=window.location.toString().split("#")[1];if(f&&0===f.indexOf("wp_customize=on")){d.open(d.settings.url+"?"+f)}if(!f&&!c.support.history){d.close()}},open:function(f){var e;if(this.active){return}if(d.settings.browser.mobile){return window.location=f}this.active=true;this.body.addClass("customize-loading");this.iframe=c("",{src:f}).appendTo(this.element);this.iframe.one("load",this.loaded);this.messenger=new b.Messenger({url:f,channel:"loader",targetWindow:this.iframe[0].contentWindow});this.messenger.bind("ready",function(){d.messenger.send("back")});this.messenger.bind("close",function(){if(c.support.history){history.back()}else{if(c.support.hashchange){window.location.hash=""}else{d.close()}}});this.messenger.bind("activated",function(g){if(g){window.location=g}});e=f.split("?")[1];if(c.support.history&&window.location.href!==f){history.pushState({customize:f},"",f)}else{if(!c.support.history&&c.support.hashchange&&e){window.location.hash="wp_customize=on&"+e}}this.trigger("open")},opened:function(){d.body.addClass("customize-active full-overlay-active")},close:function(){if(!this.active){return}this.active=false;this.trigger("close")},closed:function(){d.iframe.remove();d.messenger.destroy();d.iframe=null;d.messenger=null;d.body.removeClass("customize-active full-overlay-active").removeClass("customize-loading")},loaded:function(){d.body.removeClass("customize-loading")},overlay:{show:function(){this.element.fadeIn(200,d.opened)},hide:function(){this.element.fadeOut(200,d.closed)}}});c(function(){d.settings=_wpCustomizeLoaderSettings;d.initialize()});b.Loader=d})(wp,jQuery); \ No newline at end of file +window.wp = window.wp || {}; + +(function( exports, $ ){ + var api = wp.customize, + Loader; + + $.extend( $.support, { + history: !! ( window.history && history.pushState ), + hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7) + }); + + Loader = $.extend( {}, api.Events, { + initialize: function() { + this.body = $( document.body ); + + // Ensure the loader is supported. + // Check for settings, postMessage support, and whether we require CORS support. + if ( ! Loader.settings || ! $.support.postMessage || ( ! $.support.cors && Loader.settings.isCrossDomain ) ) { + return; + } + + this.window = $( window ); + this.element = $( '' ).appendTo( this.body ); + + this.bind( 'open', this.overlay.show ); + this.bind( 'close', this.overlay.hide ); + + $('#wpbody').on( 'click', '.load-customize', function( event ) { + event.preventDefault(); + + // Store a reference to the link that opened the customizer. + Loader.link = $(this); + // Load the theme. + Loader.open( Loader.link.attr('href') ); + }); + + // Add navigation listeners. + if ( $.support.history ) + this.window.on( 'popstate', Loader.popstate ); + + if ( $.support.hashchange ) { + this.window.on( 'hashchange', Loader.hashchange ); + this.window.triggerHandler( 'hashchange' ); + } + }, + + popstate: function( e ) { + var state = e.originalEvent.state; + if ( state && state.customize ) + Loader.open( state.customize ); + else if ( Loader.active ) + Loader.close(); + }, + + hashchange: function( e ) { + var hash = window.location.toString().split('#')[1]; + + if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) + Loader.open( Loader.settings.url + '?' + hash ); + + if ( ! hash && ! $.support.history ) + Loader.close(); + }, + + open: function( src ) { + var hash; + + if ( this.active ) + return; + + // Load the full page on mobile devices. + if ( Loader.settings.browser.mobile ) + return window.location = src; + + this.active = true; + this.body.addClass('customize-loading'); + + this.iframe = $( '', { src: src }).appendTo( this.element ); + this.iframe.one( 'load', this.loaded ); + + // Create a postMessage connection with the iframe. + this.messenger = new api.Messenger({ + url: src, + channel: 'loader', + targetWindow: 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' ); + }); + + this.messenger.bind( 'close', function() { + if ( $.support.history ) + history.back(); + else if ( $.support.hashchange ) + window.location.hash = ''; + else + Loader.close(); + }); + + this.messenger.bind( 'activated', function( location ) { + if ( location ) + window.location = location; + }); + + hash = src.split('?')[1]; + + // Ensure we don't call pushState if the user hit the forward button. + if ( $.support.history && window.location.href !== src ) + history.pushState( { customize: src }, '', src ); + else if ( ! $.support.history && $.support.hashchange && hash ) + window.location.hash = 'wp_customize=on&' + hash; + + this.trigger( 'open' ); + }, + + opened: function() { + Loader.body.addClass( 'customize-active full-overlay-active' ); + }, + + close: function() { + if ( ! this.active ) + return; + this.active = false; + + this.trigger( 'close' ); + + // Return focus to link that was originally clicked. + if ( this.link ) + this.link.focus(); + }, + + closed: function() { + Loader.iframe.remove(); + Loader.messenger.destroy(); + Loader.iframe = null; + Loader.messenger = null; + Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' ); + }, + + loaded: function() { + Loader.body.removeClass('customize-loading'); + }, + + overlay: { + show: function() { + this.element.fadeIn( 200, Loader.opened ); + }, + + hide: function() { + this.element.fadeOut( 200, Loader.closed ); + } + } + }); + + $( function() { + Loader.settings = _wpCustomizeLoaderSettings; + Loader.initialize(); + }); + + // Expose the API to the world. + api.Loader = Loader; +})( wp, jQuery );