@@ -5,7 +5,7 @@ if ( typeof wp === 'undefined' )
55 var api = wp . customize ,
66 Loader ;
77
8- Loader = {
8+ Loader = $ . extend ( { } , api . Events , {
99 supports : {
1010 history : ! ! ( window . history && history . pushState ) ,
1111 hashchange : ( 'onhashchange' in window ) && ( document . documentMode === undefined || document . documentMode > 7 )
@@ -16,6 +16,9 @@ if ( typeof wp === 'undefined' )
1616 this . window = $ ( window ) ;
1717 this . element = $ ( '<div id="customize-container" class="wp-full-overlay" />' ) . appendTo ( this . body ) ;
1818
19+ this . bind ( 'open' , this . overlay . show ) ;
20+ this . bind ( 'close' , this . overlay . hide ) ;
21+
1922 $ ( '#wpbody' ) . on ( 'click' , '.load-customize' , function ( event ) {
2023 event . preventDefault ( ) ;
2124
@@ -30,13 +33,15 @@ if ( typeof wp === 'undefined' )
3033 if ( this . supports . hashchange )
3134 this . window . on ( 'hashchange' , Loader . hashchange ) ;
3235 } ,
36+
3337 popstate : function ( e ) {
3438 var state = e . originalEvent . state ;
3539 if ( state && state . customize )
3640 Loader . open ( state . customize ) ;
3741 else if ( Loader . active )
3842 Loader . close ( ) ;
3943 } ,
44+
4045 hashchange : function ( e ) {
4146 var hash = window . location . toString ( ) . split ( '#' ) [ 1 ] ;
4247
@@ -46,9 +51,13 @@ if ( typeof wp === 'undefined' )
4651 if ( ! hash && ! Loader . supports . history )
4752 Loader . close ( ) ;
4853 } ,
54+
4955 open : function ( src ) {
56+ var hash ;
57+
5058 if ( this . active )
5159 return ;
60+
5261 this . active = true ;
5362 this . body . addClass ( 'customize-loading' ) ;
5463
@@ -60,7 +69,7 @@ if ( typeof wp === 'undefined' )
6069
6170 // Wait for the connection from the iframe before sending any postMessage events.
6271 this . messenger . bind ( 'ready' , function ( ) {
63- Loader . messenger . send ( 'back' , wpCustomizeLoaderL10n . back ) ;
72+ Loader . messenger . send ( 'back' , wpCustomizeLoaderL10n . back || '' ) ;
6473 } ) ;
6574
6675 this . messenger . bind ( 'close' , function ( ) {
@@ -72,35 +81,51 @@ if ( typeof wp === 'undefined' )
7281 Loader . close ( ) ;
7382 } ) ;
7483
75- this . element . fadeIn ( 200 , function ( ) {
76- var hash = src . split ( '?' ) [ 1 ] ;
84+ hash = src . split ( '?' ) [ 1 ] ;
7785
78- Loader . body . addClass ( 'customize-active full-overlay-active' ) ;
86+ // Ensure we don't call pushState if the user hit the forward button.
87+ if ( Loader . supports . history && window . location . href !== src )
88+ history . pushState ( { customize : src } , '' , src ) ;
89+ else if ( ! Loader . supports . history && Loader . supports . hashchange && hash )
90+ window . location . hash = hash ;
7991
80- // Ensure we don't call pushState if the user hit the forward button.
81- if ( Loader . supports . history && window . location . href !== src )
82- history . pushState ( { customize : src } , '' , src ) ;
83- else if ( ! Loader . supports . history && Loader . supports . hashchange && hash )
84- window . location . hash = hash ;
85- } ) ;
92+ this . trigger ( 'open' ) ;
93+ } ,
94+
95+ opened : function ( ) {
96+ Loader . body . addClass ( 'customize-active full-overlay-active' ) ;
8697 } ,
98+
8799 close : function ( ) {
88100 if ( ! this . active )
89101 return ;
90102 this . active = false ;
91103
92- this . element . fadeOut ( 200 , function ( ) {
93- Loader . iframe . remove ( ) ;
94- Loader . messenger . destroy ( ) ;
95- Loader . iframe = null ;
96- Loader . messenger = null ;
97- Loader . body . removeClass ( 'customize-active full-overlay-active' ) . removeClass ( 'customize-loading' ) ;
98- } ) ;
104+ this . trigger ( 'close' ) ;
99105 } ,
106+
107+ closed : function ( ) {
108+ Loader . iframe . remove ( ) ;
109+ Loader . messenger . destroy ( ) ;
110+ Loader . iframe = null ;
111+ Loader . messenger = null ;
112+ Loader . body . removeClass ( 'customize-active full-overlay-active' ) . removeClass ( 'customize-loading' ) ;
113+ } ,
114+
100115 loaded : function ( ) {
101116 Loader . body . removeClass ( 'customize-loading' ) ;
117+ } ,
118+
119+ overlay : {
120+ show : function ( ) {
121+ this . element . fadeIn ( 200 , Loader . opened ) ;
122+ } ,
123+
124+ hide : function ( ) {
125+ this . element . fadeOut ( 200 , Loader . closed ) ;
126+ }
102127 }
103- } ;
128+ } ) ;
104129
105130 $ ( function ( ) {
106131 if ( window . postMessage )
0 commit comments