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