Customize: Rely on selective refresh exclusively for previewing custom logo changes.

Eliminates JS logic (from [36698]) which attempted to do pure JS update while waiting for the selective refresh response to return. The duplicate JS logic lacked a re-implementation of the `image_downsize()` functionality available in PHP, and so the JS preview logic would fail to properly preview images that didn't have the exact theme image size generated. To keep the code DRY and to eliminate the momentary display of an improperly-sized image, the duplicated JS logic is now removed.

See #27355.
See #33755.
Fixes #36096.

Built from https://develop.svn.wordpress.org/trunk@36990


git-svn-id: http://core.svn.wordpress.org/trunk@36957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-03-14 19:17:28 +00:00
parent 036e63c31a
commit 783aa8b4fa
3 changed files with 6 additions and 48 deletions

View File

@ -226,57 +226,15 @@
/**
* Custom Logo
*
* The custom logo setting only contains the attachment ID. To avoid having to send an AJAX request to get more
* data, we send a separate message with the attachment data we get from the Customizer's media modal.
* Therefore first callback handles only the event of a new logo being selected.
*
* We don't need any information about a removed logo, so the second callback only handles that.
* Toggle the wp-custom-logo body class when a logo is added or removed.
*
* @since 4.5.0
*/
api.preview.bind( 'custom_logo-attachment-data', function( attachment ) {
var $logo = $( '.custom-logo' ),
size = $logo.data( 'size' ),
srcset = [];
// If the source was smaller than the size required by the theme, give the biggest we've got.
if ( ! attachment.sizes[ size ] ) {
size = 'full';
}
_.each( attachment.sizes, function( size ) {
srcset.push( size.url + ' ' + size.width + 'w' );
} );
$logo.attr( {
height: attachment.sizes[ size ].height,
width: attachment.sizes[ size ].width,
src: attachment.sizes[ size ].url,
srcset: srcset
} );
$( '.custom-logo-link' ).show();
$( 'body' ).addClass( 'wp-custom-logo' );
} );
api( 'custom_logo', function( setting ) {
setting.bind( function( newValue ) {
if ( ! newValue ) {
$( '.custom-logo-link' ).hide();
$( 'body' ).removeClass( 'wp-custom-logo' );
}
$( 'body' ).toggleClass( 'wp-custom-logo', !! setting.get() );
setting.bind( function( attachmentId ) {
$( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId );
} );
// Focus on the control when the logo is clicked, if there is no custom_logo partial.
if ( ! api.selectiveRefresh || ! api.selectiveRefresh.partial.has( 'custom_logo' ) ) {
$( document.body ).on( 'click', '.custom-logo-link', function( e ) {
if ( ! e.shiftKey ) {
return;
}
api.preview.send( 'focus-control-for-setting', 'custom_logo' );
} );
$( '.custom-logo-link' ).attr( 'title', api.settings.l10n.shiftClickToEdit );
}
} );
api.trigger( 'preview-ready' );

View File

@ -1 +1 @@
!function(a,b){var c,d=wp.customize;c=function(a,b,c){var d;return function(){var e=arguments;c=c||this,clearTimeout(d),d=setTimeout(function(){d=null,a.apply(c,e)},b)}},d.Preview=d.Messenger.extend({initialize:function(a,e){var f=this;d.Messenger.prototype.initialize.call(this,a,e),this.body=b(document.body),this.body.on("click.preview","a",function(a){var c,d;c=b(this),d="#"===c.attr("href").substr(0,1),a.preventDefault(),d&&"#"!==c.attr("href")&&b(c.attr("href")).each(function(){this.scrollIntoView()}),a.shiftKey||d||(f.send("scroll",0),f.send("url",c.prop("href")))}),this.body.on("submit.preview","form",function(a){a.preventDefault()}),this.window=b(window),this.window.on("scroll.preview",c(function(){f.send("scroll",f.window.scrollTop())},200)),this.bind("scroll",function(a){f.window.scrollTop(a)})}}),b(function(){var a,c;d.settings=window._wpCustomizeSettings,d.settings&&(d.preview=new d.Preview({url:window.location.href,channel:d.settings.channel}),c=function(a,b,c){var e=d(a);e?e.set(b):(c=c||!1,e=d.create(a,b,{id:a}),c&&(e._dirty=!0))},d.preview.bind("settings",function(a){b.each(a,c)}),d.preview.trigger("settings",d.settings.values),b.each(d.settings._dirty,function(a,b){var c=d(b);c&&(c._dirty=!0)}),d.preview.bind("setting",function(a){var b=!0;c.apply(null,a.concat(b))}),d.preview.bind("sync",function(a){b.each(a,function(a,b){d.preview.trigger(a,b)}),d.preview.send("synced")}),d.preview.bind("active",function(){d.preview.send("nonce",d.settings.nonce),d.preview.send("documentTitle",document.title)}),d.preview.bind("saved",function(a){d.trigger("saved",a)}),d.bind("saved",function(){d.each(function(a){a._dirty=!1})}),d.preview.bind("nonce-refresh",function(a){b.extend(d.settings.nonce,a)}),d.preview.send("ready",{activePanels:d.settings.activePanels,activeSections:d.settings.activeSections,activeControls:d.settings.activeControls}),d.preview.bind("loading-initiated",function(){b("body").addClass("wp-customizer-unloading")}),d.preview.bind("loading-failed",function(){b("body").removeClass("wp-customizer-unloading")}),a=b.map(["color","image","position_x","repeat","attachment"],function(a){return"background_"+a}),d.when.apply(d,a).done(function(a,c,d,e,f){var g,h=b(document.body),i=b("head"),j=b("#custom-background-css");g=function(){var g="";h.toggleClass("custom-background",!(!a()&&!c())),a()&&(g+="background-color: "+a()+";"),c()&&(g+='background-image: url("'+c()+'");',g+="background-position: top "+d()+";",g+="background-repeat: "+e()+";",g+="background-attachment: "+f()+";"),j.remove(),j=b('<style type="text/css" id="custom-background-css">body.custom-background { '+g+" }</style>").appendTo(i)},b.each(arguments,function(){this.bind(g)})}),d.preview.bind("custom_logo-attachment-data",function(a){var c=b(".custom-logo"),d=c.data("size"),e=[];a.sizes[d]||(d="full"),_.each(a.sizes,function(a){e.push(a.url+" "+a.width+"w")}),c.attr({height:a.sizes[d].height,width:a.sizes[d].width,src:a.sizes[d].url,srcset:e}),b(".custom-logo-link").show(),b("body").addClass("wp-custom-logo")}),d("custom_logo",function(a){a.bind(function(a){a||(b(".custom-logo-link").hide(),b("body").removeClass("wp-custom-logo"))}),d.selectiveRefresh&&d.selectiveRefresh.partial.has("custom_logo")||(b(document.body).on("click",".custom-logo-link",function(a){a.shiftKey&&d.preview.send("focus-control-for-setting","custom_logo")}),b(".custom-logo-link").attr("title",d.settings.l10n.shiftClickToEdit))}),d.trigger("preview-ready"))})}(wp,jQuery);
!function(a,b){var c,d=wp.customize;c=function(a,b,c){var d;return function(){var e=arguments;c=c||this,clearTimeout(d),d=setTimeout(function(){d=null,a.apply(c,e)},b)}},d.Preview=d.Messenger.extend({initialize:function(a,e){var f=this;d.Messenger.prototype.initialize.call(this,a,e),this.body=b(document.body),this.body.on("click.preview","a",function(a){var c,d;c=b(this),d="#"===c.attr("href").substr(0,1),a.preventDefault(),d&&"#"!==c.attr("href")&&b(c.attr("href")).each(function(){this.scrollIntoView()}),a.shiftKey||d||(f.send("scroll",0),f.send("url",c.prop("href")))}),this.body.on("submit.preview","form",function(a){a.preventDefault()}),this.window=b(window),this.window.on("scroll.preview",c(function(){f.send("scroll",f.window.scrollTop())},200)),this.bind("scroll",function(a){f.window.scrollTop(a)})}}),b(function(){var a,c;d.settings=window._wpCustomizeSettings,d.settings&&(d.preview=new d.Preview({url:window.location.href,channel:d.settings.channel}),c=function(a,b,c){var e=d(a);e?e.set(b):(c=c||!1,e=d.create(a,b,{id:a}),c&&(e._dirty=!0))},d.preview.bind("settings",function(a){b.each(a,c)}),d.preview.trigger("settings",d.settings.values),b.each(d.settings._dirty,function(a,b){var c=d(b);c&&(c._dirty=!0)}),d.preview.bind("setting",function(a){var b=!0;c.apply(null,a.concat(b))}),d.preview.bind("sync",function(a){b.each(a,function(a,b){d.preview.trigger(a,b)}),d.preview.send("synced")}),d.preview.bind("active",function(){d.preview.send("nonce",d.settings.nonce),d.preview.send("documentTitle",document.title)}),d.preview.bind("saved",function(a){d.trigger("saved",a)}),d.bind("saved",function(){d.each(function(a){a._dirty=!1})}),d.preview.bind("nonce-refresh",function(a){b.extend(d.settings.nonce,a)}),d.preview.send("ready",{activePanels:d.settings.activePanels,activeSections:d.settings.activeSections,activeControls:d.settings.activeControls}),d.preview.bind("loading-initiated",function(){b("body").addClass("wp-customizer-unloading")}),d.preview.bind("loading-failed",function(){b("body").removeClass("wp-customizer-unloading")}),a=b.map(["color","image","position_x","repeat","attachment"],function(a){return"background_"+a}),d.when.apply(d,a).done(function(a,c,d,e,f){var g,h=b(document.body),i=b("head"),j=b("#custom-background-css");g=function(){var g="";h.toggleClass("custom-background",!(!a()&&!c())),a()&&(g+="background-color: "+a()+";"),c()&&(g+='background-image: url("'+c()+'");',g+="background-position: top "+d()+";",g+="background-repeat: "+e()+";",g+="background-attachment: "+f()+";"),j.remove(),j=b('<style type="text/css" id="custom-background-css">body.custom-background { '+g+" }</style>").appendTo(i)},b.each(arguments,function(){this.bind(g)})}),d("custom_logo",function(a){b("body").toggleClass("wp-custom-logo",!!a.get()),a.bind(function(a){b("body").toggleClass("wp-custom-logo",!!a)})}),d.trigger("preview-ready"))})}(wp,jQuery);

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-beta3-36989';
$wp_version = '4.5-beta3-36990';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.