wp/wp-includes/js/customize-loader.js
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/* global _wpCustomizeLoaderSettings, confirm */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
window.wp = window.wp || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
(function( exports, $ ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
	var api = wp.customize,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
		Loader;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
	$.extend( $.support, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
		history: !! ( window.history && history.pushState ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
		hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
	 * Allows the Customizer to be overlayed on any page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * By default, any element in the body with the load-customize class will open
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	 * an iframe overlay with the URL specified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 *     e.g. <a class="load-customize" href="<?php echo wp_customize_url(); ?>">Open Customizer</a>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	 * @augments wp.customize.Events
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	Loader = $.extend( {}, api.Events, {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
		 * Setup the Loader; triggered on document#ready.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
			this.body = $( document.body );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
			// Ensure the loader is supported.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
			// Check for settings, postMessage support, and whether we require CORS support.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
			if ( ! Loader.settings || ! $.support.postMessage || ( ! $.support.cors && Loader.settings.isCrossDomain ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			this.window  = $( window );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
			this.element = $( '<div id="customize-container" />' ).appendTo( this.body );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
			// Bind events for opening and closing the overlay.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
			this.bind( 'open', this.overlay.show );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			this.bind( 'close', this.overlay.hide );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
			// Any element in the body with the `load-customize` class opens
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
			// the Customizer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
			$('#wpbody').on( 'click', '.load-customize', function( event ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
				event.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
				// Store a reference to the link that opened the Customizer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
				Loader.link = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
				// Load the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
				Loader.open( Loader.link.attr('href') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			// Add navigation listeners.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
			if ( $.support.history ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
				this.window.on( 'popstate', Loader.popstate );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
			if ( $.support.hashchange ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
				this.window.on( 'hashchange', Loader.hashchange );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
				this.window.triggerHandler( 'hashchange' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		popstate: function( e ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			var state = e.originalEvent.state;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
			if ( state && state.customize ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
				Loader.open( state.customize );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
			} else if ( Loader.active ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
				Loader.close();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
		hashchange: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			var hash = window.location.toString().split('#')[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
			if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
				Loader.open( Loader.settings.url + '?' + hash );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			if ( ! hash && ! $.support.history ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				Loader.close();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
		beforeunload: function () {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
			if ( ! Loader.saved() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
				return Loader.settings.l10n.saveAlert;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
		 * Open the Customizer overlay for a specific URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
		 * @param  string src URL to load in the Customizer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		open: function( src ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
			if ( this.active ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
			// Load the full page on mobile devices.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
			if ( Loader.settings.browser.mobile ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
				return window.location = src;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
			// Store the document title prior to opening the Live Preview
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
			this.originalDocumentTitle = document.title;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
			this.active = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
			this.body.addClass('customize-loading');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
			// Dirty state of Customizer in iframe
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
			this.saved = new api.Value( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
			this.iframe = $( '<iframe />', { 'src': src, 'title': Loader.settings.l10n.mainIframeTitle } ).appendTo( this.element );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
			this.iframe.one( 'load', this.loaded );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			// Create a postMessage connection with the iframe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			this.messenger = new api.Messenger({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
				url: src,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
				channel: 'loader',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
				targetWindow: this.iframe[0].contentWindow
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
			// Wait for the connection from the iframe before sending any postMessage events.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
			this.messenger.bind( 'ready', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
				Loader.messenger.send( 'back' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
			this.messenger.bind( 'close', function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
				if ( $.support.history ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
					history.back();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
				} else if ( $.support.hashchange ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
					window.location.hash = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
					Loader.close();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			// Prompt AYS dialog when navigating away
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
			$( window ).on( 'beforeunload', this.beforeunload );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			this.messenger.bind( 'activated', function( location ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
				if ( location ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
					window.location = location;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
			this.messenger.bind( 'saved', function () {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
				Loader.saved( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
			this.messenger.bind( 'change', function () {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
				Loader.saved( false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
			} );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
			this.messenger.bind( 'title', function( newTitle ){
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
				window.document.title = newTitle;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
			this.pushState( src );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			this.trigger( 'open' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
		pushState: function ( src ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
			var hash = src.split( '?' )[1];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
			// Ensure we don't call pushState if the user hit the forward button.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
			if ( $.support.history && window.location.href !== src ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
				history.pushState( { customize: src }, '', src );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
			} else if ( ! $.support.history && $.support.hashchange && hash ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
				window.location.hash = 'wp_customize=on&' + hash;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
			this.trigger( 'open' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
		 * Callback after the Customizer has been opened.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		opened: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			Loader.body.addClass( 'customize-active full-overlay-active' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
		 * Close the Customizer overlay and return focus to the link that opened it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		close: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
			if ( ! this.active ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
			// Display AYS dialog if Customizer is dirty
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
			if ( ! this.saved() && ! confirm( Loader.settings.l10n.saveAlert ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
				// Go forward since Customizer is exited by history.back()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
				history.forward();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			this.active = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			this.trigger( 'close' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
			// Restore document title prior to opening the Live Preview
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
			if ( this.originalDocumentTitle ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
				document.title = this.originalDocumentTitle;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			// Return focus to link that was originally clicked.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
			if ( this.link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
				this.link.focus();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
		 * Callback after the Customizer has been closed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		closed: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			Loader.iframe.remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			Loader.messenger.destroy();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			Loader.iframe    = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			Loader.messenger = null;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			Loader.saved     = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
			$( window ).off( 'beforeunload', Loader.beforeunload );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
		 * Callback for the `load` event on the Customizer iframe.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		loaded: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			Loader.body.removeClass('customize-loading');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		 * Overlay hide/show utility methods.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		overlay: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			show: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
				this.element.fadeIn( 200, Loader.opened );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			hide: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
				this.element.fadeOut( 200, Loader.closed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
	// Bootstrap the Loader on document#ready.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	$( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		Loader.settings = _wpCustomizeLoaderSettings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		Loader.initialize();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
	// Expose the API publicly on window.wp.customize.Loader
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	api.Loader = Loader;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
})( wp, jQuery );