X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..refs/tags/wordpress-4.2:/wp-includes/js/customize-loader.js diff --git a/wp-includes/js/customize-loader.js b/wp-includes/js/customize-loader.js index 2ecbbe0f..ce69a359 100644 --- a/wp-includes/js/customize-loader.js +++ b/wp-includes/js/customize-loader.js @@ -1,3 +1,4 @@ +/* global _wpCustomizeLoaderSettings, confirm */ window.wp = window.wp || {}; (function( exports, $ ){ @@ -9,7 +10,20 @@ window.wp = window.wp || {}; hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7) }); + /** + * Allows the Customizer to be overlayed on any page. + * + * By default, any element in the body with the load-customize class will open + * an iframe overlay with the URL specified. + * + * e.g. Open Customizer + * + * @augments wp.customize.Events + */ Loader = $.extend( {}, api.Events, { + /** + * Setup the Loader; triggered on document#ready. + */ initialize: function() { this.body = $( document.body ); @@ -22,21 +36,25 @@ window.wp = window.wp || {}; this.window = $( window ); this.element = $( '
' ).appendTo( this.body ); + // Bind events for opening and closing the overlay. this.bind( 'open', this.overlay.show ); this.bind( 'close', this.overlay.hide ); + // Any element in the body with the `load-customize` class opens + // the Customizer. $('#wpbody').on( 'click', '.load-customize', function( event ) { event.preventDefault(); - // Store a reference to the link that opened the customizer. + // 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 ) + if ( $.support.history ) { this.window.on( 'popstate', Loader.popstate ); + } if ( $.support.hashchange ) { this.window.on( 'hashchange', Loader.hashchange ); @@ -46,36 +64,57 @@ window.wp = window.wp || {}; popstate: function( e ) { var state = e.originalEvent.state; - if ( state && state.customize ) + if ( state && state.customize ) { Loader.open( state.customize ); - else if ( Loader.active ) + } else if ( Loader.active ) { Loader.close(); + } }, - hashchange: function( e ) { + hashchange: function() { var hash = window.location.toString().split('#')[1]; - if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) + if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) { Loader.open( Loader.settings.url + '?' + hash ); + } - if ( ! hash && ! $.support.history ) + if ( ! hash && ! $.support.history ) { Loader.close(); + } + }, + + beforeunload: function () { + if ( ! Loader.saved() ) { + return Loader.settings.l10n.saveAlert; + } }, + /** + * Open the Customizer overlay for a specific URL. + * + * @param string src URL to load in the Customizer. + */ open: function( src ) { - var hash; - if ( this.active ) + if ( this.active ) { return; + } // Load the full page on mobile devices. - if ( Loader.settings.browser.mobile ) + if ( Loader.settings.browser.mobile ) { return window.location = src; + } + + // Store the document title prior to opening the Live Preview + this.originalDocumentTitle = document.title; this.active = true; this.body.addClass('customize-loading'); - this.iframe = $( '