| | |
| | |
| | |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | 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 ); |
| |
|
| | |
| | |
| | if ( ! Loader.settings || ! $.support.postMessage || ( ! $.support.cors && Loader.settings.isCrossDomain ) ) { |
| | return; |
| | } |
| |
|
| | this.window = $( window ); |
| | this.element = $( '<div id="customize-container" />' ).appendTo( this.body ); |
| |
|
| | |
| | this.bind( 'open', this.overlay.show ); |
| | this.bind( 'close', this.overlay.hide ); |
| |
|
| | |
| | |
| | $('#wpbody').on( 'click', '.load-customize', function( event ) { |
| | event.preventDefault(); |
| |
|
| | |
| | Loader.link = $(this); |
| | |
| | Loader.open( Loader.link.attr('href') ); |
| | }); |
| |
|
| | |
| | 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() { |
| | 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(); |
| | } |
| | }, |
| |
|
| | beforeunload: function () { |
| | if ( ! Loader.saved() ) { |
| | return Loader.settings.l10n.saveAlert; |
| | } |
| | }, |
| |
|
| | |
| | |
| | |
| | |
| | |
| | open: function( src ) { |
| |
|
| | if ( this.active ) { |
| | return; |
| | } |
| |
|
| | |
| | if ( Loader.settings.browser.mobile ) { |
| | return window.location = src; |
| | } |
| |
|
| | |
| | this.originalDocumentTitle = document.title; |
| |
|
| | this.active = true; |
| | this.body.addClass('customize-loading'); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | this.saved = new api.Value( true ); |
| |
|
| | this.iframe = $( '<iframe />', { 'src': src, 'title': Loader.settings.l10n.mainIframeTitle } ).appendTo( this.element ); |
| | this.iframe.one( 'load', this.loaded ); |
| |
|
| | |
| | this.messenger = new api.Messenger({ |
| | url: src, |
| | channel: 'loader', |
| | targetWindow: this.iframe[0].contentWindow |
| | }); |
| |
|
| | |
| | if ( history.replaceState ) { |
| | this.messenger.bind( 'changeset-uuid', function( changesetUuid ) { |
| | var urlParser = document.createElement( 'a' ); |
| | urlParser.href = location.href; |
| | urlParser.search = $.param( _.extend( |
| | api.utils.parseQueryString( urlParser.search.substr( 1 ) ), |
| | { changeset_uuid: changesetUuid } |
| | ) ); |
| | history.replaceState( { customize: urlParser.href }, '', urlParser.href ); |
| | } ); |
| | } |
| |
|
| | |
| | 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(); |
| | } |
| | }); |
| |
|
| | |
| | $( window ).on( 'beforeunload', this.beforeunload ); |
| |
|
| | this.messenger.bind( 'saved', function () { |
| | Loader.saved( true ); |
| | } ); |
| | this.messenger.bind( 'change', function () { |
| | Loader.saved( false ); |
| | } ); |
| |
|
| | this.messenger.bind( 'title', function( newTitle ){ |
| | window.document.title = newTitle; |
| | }); |
| |
|
| | this.pushState( src ); |
| |
|
| | this.trigger( 'open' ); |
| | }, |
| |
|
| | pushState: function ( src ) { |
| | var hash = src.split( '?' )[1]; |
| |
|
| | |
| | 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' ).attr( 'aria-busy', 'true' ); |
| | }, |
| |
|
| | |
| | |
| | |
| | close: function() { |
| | var self = this, onConfirmClose; |
| | if ( ! self.active ) { |
| | return; |
| | } |
| |
|
| | onConfirmClose = function( confirmed ) { |
| | if ( confirmed ) { |
| | self.active = false; |
| | self.trigger( 'close' ); |
| |
|
| | |
| | if ( self.originalDocumentTitle ) { |
| | document.title = self.originalDocumentTitle; |
| | } |
| | } else { |
| |
|
| | |
| | history.forward(); |
| | } |
| | self.messenger.unbind( 'confirmed-close', onConfirmClose ); |
| | }; |
| | self.messenger.bind( 'confirmed-close', onConfirmClose ); |
| |
|
| | Loader.messenger.send( 'confirm-close' ); |
| | }, |
| |
|
| | |
| | |
| | |
| | closed: function() { |
| | Loader.iframe.remove(); |
| | Loader.messenger.destroy(); |
| | Loader.iframe = null; |
| | Loader.messenger = null; |
| | Loader.saved = null; |
| | Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' ); |
| | $( window ).off( 'beforeunload', Loader.beforeunload ); |
| | |
| | |
| | |
| | |
| | if ( Loader.link ) { |
| | Loader.link.focus(); |
| | } |
| | }, |
| |
|
| | |
| | |
| | |
| | loaded: function() { |
| | Loader.body.removeClass( 'customize-loading' ).attr( 'aria-busy', 'false' ); |
| | }, |
| |
|
| | |
| | |
| | |
| | overlay: { |
| | show: function() { |
| | this.element.fadeIn( 200, Loader.opened ); |
| | }, |
| |
|
| | hide: function() { |
| | this.element.fadeOut( 200, Loader.closed ); |
| | } |
| | } |
| | }); |
| |
|
| | |
| | $( function() { |
| | Loader.settings = _wpCustomizeLoaderSettings; |
| | Loader.initialize(); |
| | }); |
| |
|
| | |
| | api.Loader = Loader; |
| | })( wp, jQuery ); |
| |
|