"+c.l10n.cheatin+"
")}}),c.controlConstructor={color:c.ColorControl,upload:c.UploadControl,image:c.ImageControl,header:c.HeaderControl},b(function(){if(c.settings=window._wpCustomizeSettings,c.l10n=window._wpCustomizeControlsL10n,c.settings){if(!b.support.postMessage||!b.support.cors&&c.settings.isCrossDomain)return window.location=c.settings.url.fallback;var a,d,e,f=b(document.body),g=f.children(".wp-full-overlay");b("#customize-controls").on("keydown",function(a){var c=13===a.which,d=b(a.target);c&&(d.is("input:not([type=button])")||d.is("select"))&&a.preventDefault()}),a=new c.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:c.settings.url.preview,allowedUrls:c.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:c.settings.nonce,query:function(){return{wp_customize:"on",theme:c.settings.theme.stylesheet,customized:JSON.stringify(c.get()),nonce:this.nonce.preview}},save:function(){var a,d,e=this,g=b.extend(this.query(),{action:"customize_save",nonce:this.nonce.save}),h=c.state("processing");f.addClass("saving"),d=function(){var a=b.post(c.settings.url.ajax,g);c.trigger("save",a),a.always(function(){f.removeClass("saving")}),a.done(function(a){return"0"===a?(e.preview.iframe.hide(),void e.login().done(function(){e.save(),e.preview.iframe.show()})):"-1"===a?void e.cheatin():void c.trigger("saved")})},0===h()?d():(a=function(){0===h()&&(c.state.unbind("change",a),d())},c.state.bind("change",a))}}),a.bind("nonce",function(a){b.extend(this.nonce,a)}),b.each(c.settings.settings,function(b,d){c.create(b,b,d.value,{transport:d.transport,previewer:a})}),b.each(c.settings.controls,function(b,d){var e,f=c.controlConstructor[d.type]||c.Control;e=c.control.add(b,new f(b,{params:d,previewer:a}))}),a.previewUrl()?a.refresh():a.previewUrl(c.settings.url.home),function(){var a=new c.Values,d=a.create("saved"),e=a.create("activated"),f=a.create("processing");a.bind("change",function(){var a=b("#save"),f=b(".back");e()?d()?(a.val(c.l10n.saved).prop("disabled",!0),f.text(c.l10n.close)):(a.val(c.l10n.save).prop("disabled",!1),f.text(c.l10n.cancel)):(a.val(c.l10n.activate).prop("disabled",!1),f.text(c.l10n.cancel))}),d(!0),e(c.settings.theme.active),f(0),c.bind("change",function(){a("saved").set(!1)}),c.bind("saved",function(){a("saved").set(!0),a("activated").set(!0)}),e.bind(function(a){a&&c.trigger("activated")}),c.state=a}(),b("#save").click(function(b){a.save(),b.preventDefault()}).keydown(function(b){9!==b.which&&(13===b.which&&a.save(),b.preventDefault())}),b(".back").keydown(function(a){9!==a.which&&(13===a.which&&this.click(),a.preventDefault())}),b(".upload-dropzone a.upload").keydown(function(a){13===a.which&&this.click()}),b(".collapse-sidebar").on("click keydown",function(a){("keydown"!==a.type||13===a.which)&&(g.toggleClass("collapsed").toggleClass("expanded"),a.preventDefault())}),d=new c.Messenger({url:c.settings.url.parent,channel:"loader"}),d.bind("back",function(){b(".back").on("click.back",function(a){a.preventDefault(),d.send("close")})}),c.bind("saved",function(){d.send("saved")}),c.bind("activated",function(){d.targetWindow()?d.send("activated",c.settings.url.activated):c.settings.url.activated&&(window.location=c.settings.url.activated)}),d.send("ready"),b.each({background_image:{controls:["background_repeat","background_position_x","background_attachment"],callback:function(a){return!!a}},show_on_front:{controls:["page_on_front","page_for_posts"],callback:function(a){return"page"===a}},header_textcolor:{controls:["header_textcolor"],callback:function(a){return"blank"!==a}}},function(a,d){c(a,function(a){b.each(d.controls,function(b,e){c.control(e,function(b){var c=function(a){b.container.toggle(d.callback(a))};c(a.get()),a.bind(c)})})})}),c.control("display_header_text",function(a){var b="";a.elements[0].unsync(c("header_textcolor")),a.element=new c.Element(a.container.find("input")),a.element.set("blank"!==a.setting()),a.element.bind(function(d){d||(b=c("header_textcolor").get()),a.setting.set(d?b:"blank")}),a.setting.bind(function(b){a.element.set("blank"!==b)})}),c.trigger("ready"),e=b(".back"),e.focus(),setTimeout(function(){e.focus()},200)}})}(wp,jQuery); \ No newline at end of file +!function(a,b){var c=wp.customize;c.Setting=c.Value.extend({initialize:function(a,b,d){c.Value.prototype.initialize.call(this,b,d),this.id=a,this.transport=this.transport||"refresh",this.bind(this.preview)},preview:function(){switch(this.transport){case"refresh":return this.previewer.refresh();case"postMessage":return this.previewer.send("setting",[this.id,this()])}}}),c.Control=c.Class.extend({initialize:function(a,d){var e,f,g,h=this;this.params={},b.extend(this,d||{}),this.id=a,this.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),this.container=b(this.selector),g=b.map(this.params.settings,function(a){return a}),c.apply(c,g.concat(function(){var a;h.settings={};for(a in h.params.settings)h.settings[a]=c(h.params.settings[a]);h.setting=h.settings["default"]||null,h.ready()})),h.elements=[],e=this.container.find("[data-customize-setting-link]"),f={},e.each(function(){var a,d=b(this);if(d.is(":radio")){if(a=d.prop("name"),f[a])return;f[a]=!0,d=e.filter('[name="'+a+'"]')}c(d.data("customizeSettingLink"),function(a){var b=new c.Element(d);h.elements.push(b),b.sync(a),b.set(a())})})},ready:function(){},dropdownInit:function(){var a=this,b=this.container.find(".dropdown-status"),c=this.params,d=!1,e=function(a){"string"==typeof a&&c.statuses&&c.statuses[a]?b.html(c.statuses[a]).show():b.hide()};this.container.on("click keydown",".dropdown",function(b){("keydown"!==b.type||13===b.which)&&(b.preventDefault(),d||a.container.toggleClass("open"),a.container.hasClass("open")&&a.container.parent().parent().find("li.library-selected").focus(),d=!0,setTimeout(function(){d=!1},400))}),this.setting.bind(e),e(this.setting())}}),c.ColorControl=c.Control.extend({ready:function(){var a=this,b=this.container.find(".color-picker-hex");b.val(a.setting()).wpColorPicker({change:function(){a.setting.set(b.wpColorPicker("color"))},clear:function(){a.setting.set(!1)}})}}),c.UploadControl=c.Control.extend({ready:function(){var a=this;this.params.removed=this.params.removed||"",this.success=b.proxy(this.success,this),this.uploader=b.extend({container:this.container,browser:this.container.find(".upload"),dropzone:this.container.find(".upload-dropzone"),success:this.success,plupload:{},params:{}},this.uploader||{}),a.params.extensions&&(a.uploader.plupload.filters=[{title:c.l10n.allowedFiles,extensions:a.params.extensions}]),a.params.context&&(a.uploader.params["post_data[context]"]=this.params.context),c.settings.theme.stylesheet&&(a.uploader.params["post_data[theme]"]=c.settings.theme.stylesheet),this.uploader=new wp.Uploader(this.uploader),this.remover=this.container.find(".remove"),this.remover.on("click keydown",function(b){("keydown"!==b.type||13===b.which)&&(a.setting.set(a.params.removed),b.preventDefault())}),this.removerVisibility=b.proxy(this.removerVisibility,this),this.setting.bind(this.removerVisibility),this.removerVisibility(this.setting.get())},success:function(a){this.setting.set(a.get("url"))},removerVisibility:function(a){this.remover.toggle(a!=this.params.removed)}}),c.ImageControl=c.UploadControl.extend({ready:function(){var a,d=this;this.uploader={init:function(){var a,b;this.supports.dragdrop||(a=d.container.find(".upload-fallback"),b=a.children().detach(),this.browser.detach().empty().append(b),a.append(this.browser).show())}},c.UploadControl.prototype.ready.call(this),this.thumbnail=this.container.find(".preview-thumbnail img"),this.thumbnailSrc=b.proxy(this.thumbnailSrc,this),this.setting.bind(this.thumbnailSrc),this.library=this.container.find(".library"),this.tabs={},a=this.library.find(".library-content"),this.library.children("ul").children("li").each(function(){var c=b(this),e=c.data("customizeTab"),f=a.filter('[data-customize-tab="'+e+'"]');d.tabs[e]={both:c.add(f),link:c,panel:f}}),this.library.children("ul").on("click keydown","li",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeTab"),e=d.tabs[c];a.preventDefault(),e.link.hasClass("library-selected")||(d.selected.both.removeClass("library-selected"),d.selected=e,d.selected.both.addClass("library-selected"))}}),this.library.on("click keydown","a",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeImageValue");c&&(d.setting.set(c),a.preventDefault())}}),this.tabs.uploaded&&(this.tabs.uploaded.target=this.library.find(".uploaded-target"),this.tabs.uploaded.panel.find(".thumbnail").length||this.tabs.uploaded.both.addClass("hidden")),a.each(function(){var a=d.tabs[b(this).data("customizeTab")];return a.link.hasClass("hidden")?void 0:(d.selected=a,a.both.addClass("library-selected"),!1)}),this.dropdownInit()},success:function(a){c.UploadControl.prototype.success.call(this,a),this.tabs.uploaded&&this.tabs.uploaded.target.length&&(this.tabs.uploaded.both.removeClass("hidden"),a.element=b('').data("customizeImageValue",a.get("url")).append('').appendTo(this.tabs.uploaded.target))},thumbnailSrc:function(a){/^(https?:)?\/\//.test(a)?this.thumbnail.prop("src",a).show():this.thumbnail.hide()}}),c.HeaderControl=c.Control.extend({ready:function(){this.btnRemove=b("#customize-control-header_image .actions .remove"),this.btnNew=b("#customize-control-header_image .actions .new"),_.bindAll(this,"openMedia","removeImage"),this.btnNew.on("click",this.openMedia),this.btnRemove.on("click",this.removeImage),c.HeaderTool.currentHeader=new c.HeaderTool.ImageModel,new c.HeaderTool.CurrentView({model:c.HeaderTool.currentHeader,el:".current .container"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.UploadsList=new c.HeaderTool.ChoiceList,el:".choices .uploaded .list"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.DefaultsList=new c.HeaderTool.DefaultsList,el:".choices .default .list"}),c.HeaderTool.combinedList=c.HeaderTool.CombinedList=new c.HeaderTool.CombinedList([c.HeaderTool.UploadsList,c.HeaderTool.DefaultsList])},calculateImageSelectOptions:function(a,b){var d,e,f,g,h,i,j=parseInt(_wpCustomizeHeader.data.width,10),k=parseInt(_wpCustomizeHeader.data.height,10),l=!!parseInt(_wpCustomizeHeader.data["flex-width"],10),m=!!parseInt(_wpCustomizeHeader.data["flex-height"],10);return h=a.get("width"),g=a.get("height"),this.headerImage=new c.HeaderTool.ImageModel,this.headerImage.set({themeWidth:j,themeHeight:k,themeFlexWidth:l,themeFlexHeight:m,imageWidth:h,imageHeight:g}),b.set("canSkipCrop",!this.headerImage.shouldBeCropped()),d=j/k,e=h,f=g,e/f>d?(k=f,j=k*d):(j=e,k=j/d),i={handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:h,imageHeight:g,x1:0,y1:0,x2:j,y2:k},m===!1&&l===!1&&(i.aspectRatio=j+":"+k),m===!1&&(i.maxHeight=k),l===!1&&(i.maxWidth=j),i},openMedia:function(a){var b=_wpMediaViewsL10n;a.preventDefault(),this.frame=wp.media({button:{text:b.selectAndCrop,close:!1},states:[new wp.media.controller.Library({title:b.chooseImage,library:wp.media.query({type:"image"}),multiple:!1,priority:20,suggestedWidth:_wpCustomizeHeader.data.width,suggestedHeight:_wpCustomizeHeader.data.height}),new wp.media.controller.Cropper({imgSelectOptions:this.calculateImageSelectOptions})]}),this.frame.on("select",this.onSelect,this),this.frame.on("cropped",this.onCropped,this),this.frame.on("skippedcrop",this.onSkippedCrop,this),this.frame.open()},onSelect:function(){this.frame.setState("cropper")},onCropped:function(a){var b=a.post_content,c=a.attachment_id,d=a.width,e=a.height;this.setImageFromURL(b,c,d,e)},onSkippedCrop:function(a){var b=a.get("url"),c=a.get("width"),d=a.get("height");this.setImageFromURL(b,a.id,c,d)},setImageFromURL:function(a,b,d,e){var f,g={};g.url=a,g.thumbnail_url=a,g.timestamp=_.now(),b&&(g.attachment_id=b),d&&(g.width=d),e&&(g.height=e),f=new c.HeaderTool.ImageModel({header:g,choice:a.split("/").pop()}),c.HeaderTool.UploadsList.add(f),c.HeaderTool.currentHeader.set(f.toJSON()),f.save(),f.importImage()},removeImage:function(){c.HeaderTool.currentHeader.trigger("hide"),c.HeaderTool.CombinedList.trigger("control:removeImage")}}),c.defaultConstructor=c.Setting,c.control=new c.Values({defaultConstructor:c.Control}),c.PreviewFrame=c.Messenger.extend({sensitivity:2e3,initialize:function(a,d){var e=b.Deferred();e.promise(this),this.container=a.container,this.signature=a.signature,b.extend(a,{channel:c.PreviewFrame.uuid()}),c.Messenger.prototype.initialize.call(this,a,d),this.add("previewUrl",a.previewUrl),this.query=b.extend(a.query||{},{customize_messenger_channel:this.channel()}),this.run(e)},run:function(a){var c=this,d=!1,e=!1;this._ready&&this.unbind("ready",this._ready),this._ready=function(){e=!0,d&&a.resolveWith(c)},this.bind("ready",this._ready),this.request=b.ajax(this.previewUrl(),{type:"POST",data:this.query,xhrFields:{withCredentials:!0}}),this.request.fail(function(){a.rejectWith(c,["request failure"])}),this.request.done(function(f){var g,h=c.request.getResponseHeader("Location"),i=c.signature;return h&&h!=c.previewUrl()?void a.rejectWith(c,["redirect",h]):"0"===f?void c.login(a):"-1"===f?void a.rejectWith(c,["cheatin"]):(g=f.lastIndexOf(i),-1===g||g"+c.l10n.cheatin+"
")}}),c.controlConstructor={color:c.ColorControl,upload:c.UploadControl,image:c.ImageControl,header:c.HeaderControl},b(function(){if(c.settings=window._wpCustomizeSettings,c.l10n=window._wpCustomizeControlsL10n,c.settings){if(!b.support.postMessage||!b.support.cors&&c.settings.isCrossDomain)return window.location=c.settings.url.fallback;var a,d,e,f=b(document.body),g=f.children(".wp-full-overlay"),h=b(".back"),i=b("#save");b("#customize-controls").on("keydown",function(a){var c=13===a.which,d=b(a.target);c&&(d.is("input:not([type=button])")||d.is("select"))&&a.preventDefault()}),a=new c.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:c.settings.url.preview,allowedUrls:c.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:c.settings.nonce,query:function(){return{wp_customize:"on",theme:c.settings.theme.stylesheet,customized:JSON.stringify(c.get()),nonce:this.nonce.preview}},save:function(){var a,d,e=this,g=b.extend(this.query(),{action:"customize_save",nonce:this.nonce.save}),h=c.state("processing");f.addClass("saving"),d=function(){var a=b.post(c.settings.url.ajax,g);c.trigger("save",a),a.always(function(){f.removeClass("saving")}),a.done(function(a){return"0"===a?(e.preview.iframe.hide(),void e.login().done(function(){e.save(),e.preview.iframe.show()})):"-1"===a?void e.cheatin():void c.trigger("saved")})},0===h()?d():(a=function(){0===h()&&(c.state.unbind("change",a),d())},c.state.bind("change",a))}}),a.bind("nonce",function(a){b.extend(this.nonce,a)}),b.each(c.settings.settings,function(b,d){c.create(b,b,d.value,{transport:d.transport,previewer:a})}),b.each(c.settings.controls,function(b,d){var e,f=c.controlConstructor[d.type]||c.Control;e=c.control.add(b,new f(b,{params:d,previewer:a}))}),a.previewUrl()?a.refresh():a.previewUrl(c.settings.url.home),function(){var a=new c.Values,b=a.create("saved"),d=a.create("activated"),e=a.create("processing");a.bind("change",function(){d()?b()?(i.val(c.l10n.saved).prop("disabled",!0),h.text(c.l10n.close)):(i.val(c.l10n.save).prop("disabled",!1),h.text(c.l10n.cancel)):(i.val(c.l10n.activate).prop("disabled",!1),h.text(c.l10n.cancel))}),b(!0),d(c.settings.theme.active),e(0),c.bind("change",function(){a("saved").set(!1)}),c.bind("saved",function(){a("saved").set(!0),a("activated").set(!0)}),d.bind(function(a){a&&c.trigger("activated")}),c.state=a}(),i.click(function(b){a.save(),b.preventDefault()}).keydown(function(b){9!==b.which&&(13===b.which&&a.save(),b.preventDefault())}),h.keydown(function(a){9!==a.which&&(13===a.which&&this.click(),a.preventDefault())}),b(".upload-dropzone a.upload").keydown(function(a){13===a.which&&this.click()}),b(".collapse-sidebar").on("click keydown",function(a){("keydown"!==a.type||13===a.which)&&(g.toggleClass("collapsed").toggleClass("expanded"),a.preventDefault())}),d=new c.Messenger({url:c.settings.url.parent,channel:"loader"}),d.bind("back",function(){h.on("click.back",function(a){a.preventDefault(),d.send("close")})}),b(window).on("beforeunload",function(){return c.state("saved")()?void 0:c.l10n.saveAlert}),b.each(["saved","change"],function(a,b){c.bind(b,function(){d.send(b)})}),c.bind("activated",function(){d.targetWindow()?d.send("activated",c.settings.url.activated):c.settings.url.activated&&(window.location=c.settings.url.activated)}),d.send("ready"),b.each({background_image:{controls:["background_repeat","background_position_x","background_attachment"],callback:function(a){return!!a}},show_on_front:{controls:["page_on_front","page_for_posts"],callback:function(a){return"page"===a}},header_textcolor:{controls:["header_textcolor"],callback:function(a){return"blank"!==a}}},function(a,d){c(a,function(a){b.each(d.controls,function(b,e){c.control(e,function(b){var c=function(a){b.container.toggle(d.callback(a))};c(a.get()),a.bind(c)})})})}),c.control("display_header_text",function(a){var b="";a.elements[0].unsync(c("header_textcolor")),a.element=new c.Element(a.container.find("input")),a.element.set("blank"!==a.setting()),a.element.bind(function(d){d||(b=c("header_textcolor").get()),a.setting.set(d?b:"blank")}),a.setting.bind(function(b){a.element.set("blank"!==b)})}),c.trigger("ready"),e=h,e.focus(),setTimeout(function(){e.focus()},200)}})}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/js/customize-loader.js b/wp-includes/js/customize-loader.js index cccf71acc8..98bb32f1eb 100644 --- a/wp-includes/js/customize-loader.js +++ b/wp-includes/js/customize-loader.js @@ -1,4 +1,4 @@ -/* global _wpCustomizeLoaderSettings */ +/* global _wpCustomizeLoaderSettings, confirm */ window.wp = window.wp || {}; (function( exports, $ ){ @@ -36,8 +36,9 @@ window.wp = window.wp || {}; }); // Add navigation listeners. - if ( $.support.history ) + if ( $.support.history ) { this.window.on( 'popstate', Loader.popstate ); + } if ( $.support.hashchange ) { this.window.on( 'hashchange', Loader.hashchange ); @@ -47,35 +48,48 @@ 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() { 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: 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; + } this.active = true; this.body.addClass('customize-loading'); + // Dirty state of customizer in iframe + this.saved = new api.Value( true ); + this.iframe = $( '', { src: src }).appendTo( this.element ); this.iframe.one( 'load', this.loaded ); @@ -92,44 +106,72 @@ window.wp = window.wp || {}; }); this.messenger.bind( 'close', function() { - if ( $.support.history ) + if ( $.support.history ) { history.back(); - else if ( $.support.hashchange ) + } else if ( $.support.hashchange ) { window.location.hash = ''; - else + } else { Loader.close(); - }); + } + } ); + + // Prompt AYS dialog when navigating away + $( window ).on( 'beforeunload', this.beforeunload ); this.messenger.bind( 'activated', function( location ) { - if ( location ) + if ( location ) { window.location = location; + } }); - hash = src.split('?')[1]; + this.messenger.bind( 'saved', function () { + Loader.saved( true ); + } ); + this.messenger.bind( 'change', function () { + Loader.saved( false ); + } ); - // Ensure we don't call pushState if the user hit the forward button. - if ( $.support.history && window.location.href !== src ) - history.pushState( { customize: src }, '', src ); - else if ( ! $.support.history && $.support.hashchange && hash ) - window.location.hash = 'wp_customize=on&' + hash; + this.pushState( src ); this.trigger( 'open' ); }, + pushState: function ( src ) { + var hash; + + // Ensure we don't call pushState if the user hit the forward button. + if ( $.support.history && window.location.href !== src ) { + history.pushState( { customize: src }, '', src ); + } else if ( ! $.support.history && $.support.hashchange && hash ) { + hash = src.split( '?' )[1]; + window.location.hash = 'wp_customize=on&' + hash; + } + }, + opened: function() { Loader.body.addClass( 'customize-active full-overlay-active' ); }, close: function() { - if ( ! this.active ) + if ( ! this.active ) { return; + } + + // Display AYS dialog if customizer is dirty + if ( ! this.saved() && ! confirm( Loader.settings.l10n.saveAlert ) ) { + // Go forward since Customizer is exited by history.back() + history.forward(); + return; + } + this.active = false; this.trigger( 'close' ); // Return focus to link that was originally clicked. - if ( this.link ) + if ( this.link ) { this.link.focus(); + } }, closed: function() { @@ -137,7 +179,9 @@ window.wp = window.wp || {}; Loader.messenger.destroy(); Loader.iframe = null; Loader.messenger = null; + Loader.saved = null; Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' ); + $( window ).off( 'beforeunload', Loader.beforeunload ); }, loaded: function() { diff --git a/wp-includes/js/customize-loader.min.js b/wp-includes/js/customize-loader.min.js index 1ece98489a..fc32b05b75 100644 --- a/wp-includes/js/customize-loader.min.js +++ b/wp-includes/js/customize-loader.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a,b){var c,d=wp.customize;b.extend(b.support,{history:!(!window.history||!history.pushState),hashchange:"onhashchange"in window&&(void 0===document.documentMode||document.documentMode>7)}),c=b.extend({},d.Events,{initialize:function(){this.body=b(document.body),c.settings&&b.support.postMessage&&(b.support.cors||!c.settings.isCrossDomain)&&(this.window=b(window),this.element=b('').appendTo(this.body),this.bind("open",this.overlay.show),this.bind("close",this.overlay.hide),b("#wpbody").on("click",".load-customize",function(a){a.preventDefault(),c.link=b(this),c.open(c.link.attr("href"))}),b.support.history&&this.window.on("popstate",c.popstate),b.support.hashchange&&(this.window.on("hashchange",c.hashchange),this.window.triggerHandler("hashchange")))},popstate:function(a){var b=a.originalEvent.state;b&&b.customize?c.open(b.customize):c.active&&c.close()},hashchange:function(){var a=window.location.toString().split("#")[1];a&&0===a.indexOf("wp_customize=on")&&c.open(c.settings.url+"?"+a),a||b.support.history||c.close()},open:function(a){var e;if(!this.active){if(c.settings.browser.mobile)return window.location=a;this.active=!0,this.body.addClass("customize-loading"),this.iframe=b("",{src:a}).appendTo(this.element),this.iframe.one("load",this.loaded),this.messenger=new d.Messenger({url:a,channel:"loader",targetWindow:this.iframe[0].contentWindow}),this.messenger.bind("ready",function(){c.messenger.send("back")}),this.messenger.bind("close",function(){b.support.history?history.back():b.support.hashchange?window.location.hash="":c.close()}),this.messenger.bind("activated",function(a){a&&(window.location=a)}),e=a.split("?")[1],b.support.history&&window.location.href!==a?history.pushState({customize:a},"",a):!b.support.history&&b.support.hashchange&&e&&(window.location.hash="wp_customize=on&"+e),this.trigger("open")}},opened:function(){c.body.addClass("customize-active full-overlay-active")},close:function(){this.active&&(this.active=!1,this.trigger("close"),this.link&&this.link.focus())},closed:function(){c.iframe.remove(),c.messenger.destroy(),c.iframe=null,c.messenger=null,c.body.removeClass("customize-active full-overlay-active").removeClass("customize-loading")},loaded:function(){c.body.removeClass("customize-loading")},overlay:{show:function(){this.element.fadeIn(200,c.opened)},hide:function(){this.element.fadeOut(200,c.closed)}}}),b(function(){c.settings=_wpCustomizeLoaderSettings,c.initialize()}),d.Loader=c}(wp,jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a,b){var c,d=wp.customize;b.extend(b.support,{history:!(!window.history||!history.pushState),hashchange:"onhashchange"in window&&(void 0===document.documentMode||document.documentMode>7)}),c=b.extend({},d.Events,{initialize:function(){this.body=b(document.body),c.settings&&b.support.postMessage&&(b.support.cors||!c.settings.isCrossDomain)&&(this.window=b(window),this.element=b('').appendTo(this.body),this.bind("open",this.overlay.show),this.bind("close",this.overlay.hide),b("#wpbody").on("click",".load-customize",function(a){a.preventDefault(),c.link=b(this),c.open(c.link.attr("href"))}),b.support.history&&this.window.on("popstate",c.popstate),b.support.hashchange&&(this.window.on("hashchange",c.hashchange),this.window.triggerHandler("hashchange")))},popstate:function(a){var b=a.originalEvent.state;b&&b.customize?c.open(b.customize):c.active&&c.close()},hashchange:function(){var a=window.location.toString().split("#")[1];a&&0===a.indexOf("wp_customize=on")&&c.open(c.settings.url+"?"+a),a||b.support.history||c.close()},beforeunload:function(){return c.saved()?void 0:c.settings.l10n.saveAlert},open:function(a){if(!this.active){if(c.settings.browser.mobile)return window.location=a;this.active=!0,this.body.addClass("customize-loading"),this.saved=new d.Value(!0),this.iframe=b("",{src:a}).appendTo(this.element),this.iframe.one("load",this.loaded),this.messenger=new d.Messenger({url:a,channel:"loader",targetWindow:this.iframe[0].contentWindow}),this.messenger.bind("ready",function(){c.messenger.send("back")}),this.messenger.bind("close",function(){b.support.history?history.back():b.support.hashchange?window.location.hash="":c.close()}),b(window).on("beforeunload",this.beforeunload),this.messenger.bind("activated",function(a){a&&(window.location=a)}),this.messenger.bind("saved",function(){c.saved(!0)}),this.messenger.bind("change",function(){c.saved(!1)}),this.pushState(a),this.trigger("open")}},pushState:function(a){var c;b.support.history&&window.location.href!==a?history.pushState({customize:a},"",a):!b.support.history&&b.support.hashchange&&c&&(c=a.split("?")[1],window.location.hash="wp_customize=on&"+c)},opened:function(){c.body.addClass("customize-active full-overlay-active")},close:function(){if(this.active){if(!this.saved()&&!confirm(c.settings.l10n.saveAlert))return void history.forward();this.active=!1,this.trigger("close"),this.link&&this.link.focus()}},closed:function(){c.iframe.remove(),c.messenger.destroy(),c.iframe=null,c.messenger=null,c.saved=null,c.body.removeClass("customize-active full-overlay-active").removeClass("customize-loading"),b(window).off("beforeunload",c.beforeunload)},loaded:function(){c.body.removeClass("customize-loading")},overlay:{show:function(){this.element.fadeIn(200,c.opened)},hide:function(){this.element.fadeOut(200,c.closed)}}}),b(function(){c.settings=_wpCustomizeLoaderSettings,c.initialize()}),d.Loader=c}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 3db15df13d..92c9bd5b12 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -382,6 +382,7 @@ function wp_default_scripts( &$scripts ) { did_action( 'init' ) && $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array( 'activate' => __( 'Save & Activate' ), 'save' => __( 'Save & Publish' ), + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), 'saved' => __( 'Saved' ), 'cancel' => __( 'Cancel' ), 'close' => __( 'Close' ), diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 9bab1fd624..5a8fbb1e57 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1874,6 +1874,9 @@ function _wp_customize_loader_settings() { 'url' => esc_url( admin_url( 'customize.php' ) ), 'isCrossDomain' => $cross_domain, 'browser' => $browser, + 'l10n' => array( + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + ), ); $script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';