From c055021d1ea256401a96fbae96e88745f29d68a3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 21 Jan 2016 06:08:27 +0000 Subject: [PATCH] Customizer: Fix `click.preview` event handler for jump links and shift+clicks in preview. * Prevent following jump links (starting with `#`), but instead scroll that element into view. * Prevent following links clicked in the Customizer if shift key is pressed when clicking; this fixes an issue when trying to shift-click on a widget or nav menu item (#32681) to just focus on the control in the Customizer. Fixes #26005. Built from https://develop.svn.wordpress.org/trunk@36371 git-svn-id: http://core.svn.wordpress.org/trunk@36338 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/customize-preview.js | 23 +++++++++++++++++++++-- wp-includes/js/customize-preview.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/wp-includes/js/customize-preview.js b/wp-includes/js/customize-preview.js index cfda0edf98..4bf625eb50 100644 --- a/wp-includes/js/customize-preview.js +++ b/wp-includes/js/customize-preview.js @@ -33,7 +33,8 @@ */ api.Preview = api.Messenger.extend({ /** - * @param {string} url The URL of preview frame + * @param {object} params - Parameters to configure the messenger. + * @param {object} options - Extend any instance parameter or method with this object. */ initialize: function( params, options ) { var self = this; @@ -42,9 +43,27 @@ this.body = $( document.body ); this.body.on( 'click.preview', 'a', function( event ) { + var link, isInternalJumpLink; + link = $( this ); + isInternalJumpLink = ( '#' === link.attr( 'href' ).substr( 0, 1 ) ); event.preventDefault(); + + if ( isInternalJumpLink && '#' !== link.attr( 'href' ) ) { + $( link.attr( 'href' ) ).each( function() { + this.scrollIntoView(); + } ); + } + + /* + * Note the shift key is checked so shift+click on widgets or + * nav menu items can just result on focusing on the corresponding + * control instead of also navigating to the URL linked to. + */ + if ( event.shiftKey || isInternalJumpLink ) { + return; + } self.send( 'scroll', 0 ); - self.send( 'url', $(this).prop('href') ); + self.send( 'url', link.prop( 'href' ) ); }); // You cannot submit forms. diff --git a/wp-includes/js/customize-preview.min.js b/wp-includes/js/customize-preview.min.js index de5f15f8ac..821fd21df1 100644 --- a/wp-includes/js/customize-preview.min.js +++ b/wp-includes/js/customize-preview.min.js @@ -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){a.preventDefault(),f.send("scroll",0),f.send("url",b(this).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(){if(d.settings=window._wpCustomizeSettings,d.settings){var a;d.preview=new d.Preview({url:window.location.href,channel:d.settings.channel}),d.preview.bind("settings",function(a){b.each(a,function(a,b){d.has(a)?d(a).set(b):d.create(a,b)})}),d.preview.trigger("settings",d.settings.values),d.preview.bind("setting",function(a){var b;a=a.slice(),(b=d(a.shift()))&&b.set.apply(b,a)}),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.settings.nonce&&d.preview.send("nonce",d.settings.nonce),d.preview.send("documentTitle",document.title)}),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('").appendTo(i)},b.each(arguments,function(){this.bind(g)})}),d.trigger("preview-ready")}})}(wp,jQuery); \ No newline at end of file +!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(){if(d.settings=window._wpCustomizeSettings,d.settings){var a;d.preview=new d.Preview({url:window.location.href,channel:d.settings.channel}),d.preview.bind("settings",function(a){b.each(a,function(a,b){d.has(a)?d(a).set(b):d.create(a,b)})}),d.preview.trigger("settings",d.settings.values),d.preview.bind("setting",function(a){var b;a=a.slice(),(b=d(a.shift()))&&b.set.apply(b,a)}),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.settings.nonce&&d.preview.send("nonce",d.settings.nonce),d.preview.send("documentTitle",document.title)}),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('").appendTo(i)},b.each(arguments,function(){this.bind(g)})}),d.trigger("preview-ready")}})}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 592364f3b6..77c4883202 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36370'; +$wp_version = '4.5-alpha-36371'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.