From d686fa266b20ba0668cdf9c676bd1672e2fb127d Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 1 Jul 2020 19:30:02 +0000 Subject: [PATCH] I18N: Use `wp.i18n` for translatable strings in `wp-includes/js/wp-pointer.js`. This removes the usage of `wp_localize_script()` for passing translations to the script and instead adds the translatable strings in the script directly through the use of `wp.i18n` and its utilities. Props swissspidy, ocean90. See #20491. Fixes #50525. Built from https://develop.svn.wordpress.org/trunk@48266 git-svn-id: http://core.svn.wordpress.org/trunk@48035 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wp-pointer.js | 5 +---- wp-includes/js/wp-pointer.min.js | 2 +- wp-includes/script-loader.php | 10 ++-------- wp-includes/version.php | 2 +- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/wp-includes/js/wp-pointer.js b/wp-includes/js/wp-pointer.js index 52524922c1..15849bc6ed 100644 --- a/wp-includes/js/wp-pointer.js +++ b/wp-includes/js/wp-pointer.js @@ -2,8 +2,6 @@ * @output wp-includes/js/wp-pointer.js */ -/* global wpPointerL10n */ - /** * Initializes the wp-pointer widget using jQuery UI Widget Factory. */ @@ -19,8 +17,7 @@ return $(this).text(); }, buttons: function( event, t ) { - var close = ( wpPointerL10n ) ? wpPointerL10n.dismiss : 'Dismiss', - button = $('' + close + ''); + var button = $('').text( wp.i18n.__( 'Dismiss' ) ); return button.bind( 'click.pointer', function(e) { e.preventDefault(); diff --git a/wp-includes/js/wp-pointer.min.js b/wp-includes/js/wp-pointer.min.js index 073f8b7b97..6aca957770 100644 --- a/wp-includes/js/wp-pointer.min.js +++ b/wp-includes/js/wp-pointer.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(s){var i=0,e=9999;s.widget("wp.pointer",{options:{pointerClass:"wp-pointer",pointerWidth:320,content:function(){return s(this).text()},buttons:function(t,i){var e=wpPointerL10n?wpPointerL10n.dismiss:"Dismiss";return s(''+e+"").bind("click.pointer",function(t){t.preventDefault(),i.element.pointer("close")})},position:"top",show:function(t,i){i.pointer.show(),i.opened()},hide:function(t,i){i.pointer.hide(),i.closed()},document:document},_create:function(){var t;this.content=s('
'),this.arrow=s('
'),t="absolute",this.element.parents().add(this.element).filter(function(){return"fixed"===s(this).css("position")}).length&&(t="fixed"),this.pointer=s("
").append(this.content).append(this.arrow).attr("id","wp-pointer-"+i++).addClass(this.options.pointerClass).css({position:t,width:this.options.pointerWidth+"px",display:"none"}).appendTo(this.options.document.body)},_setOption:function(t,i){var e=this.options,n=this.pointer;"document"===t&&i!==e.document?n.detach().appendTo(i.body):"pointerClass"===t&&n.removeClass(e.pointerClass).addClass(i),s.Widget.prototype._setOption.apply(this,arguments),"position"===t?this.reposition():"content"===t&&this.active&&this.update()},destroy:function(){this.pointer.remove(),s.Widget.prototype.destroy.call(this)},widget:function(){return this.pointer},update:function(i){var t,e=this,n=this.options,o=s.Deferred();if(!n.disabled)return o.done(function(t){e._update(i,t)}),(t="string"==typeof n.content?n.content:n.content.call(this.element[0],o.resolve,i,this._handoff()))&&o.resolve(t),o.promise()},_update:function(t,i){var e,n=this.options;i&&(this.pointer.stop(),this.content.html(i),(e=n.buttons.call(this.element[0],t,this._handoff()))&&e.wrap('
').parent().appendTo(this.content),this.reposition())},reposition:function(){var t;this.options.disabled||(t=this._processPosition(this.options.position),this.pointer.css({top:0,left:0,zIndex:e++}).show().position(s.extend({of:this.element,collision:"fit none"},t)),this.repoint())},repoint:function(){var t,i=this.options;i.disabled||(t="string"==typeof i.position?i.position:i.position.edge,this.pointer[0].className=this.pointer[0].className.replace(/wp-pointer-[^\s'"]*/,""),this.pointer.addClass("wp-pointer-"+t))},_processPosition:function(t){var i,e={top:"bottom",bottom:"top",left:"right",right:"left"};return(i="string"==typeof t?{edge:t+""}:s.extend({},t)).edge&&("top"==i.edge||"bottom"==i.edge?(i.align=i.align||"left",i.at=i.at||i.align+" "+e[i.edge],i.my=i.my||i.align+" "+i.edge):(i.align=i.align||"top",i.at=i.at||e[i.edge]+" "+i.align,i.my=i.my||i.edge+" "+i.align)),i},open:function(t){var i=this,e=this.options;this.active||e.disabled||this.element.is(":hidden")||this.update().done(function(){i._open(t)})},_open:function(t){var i=this,e=this.options;this.active||e.disabled||this.element.is(":hidden")||(this.active=!0,this._trigger("open",t,this._handoff()),this._trigger("show",t,this._handoff({opened:function(){i._trigger("opened",t,i._handoff())}})))},close:function(t){if(this.active&&!this.options.disabled){var i=this;this.active=!1,this._trigger("close",t,this._handoff()),this._trigger("hide",t,this._handoff({closed:function(){i._trigger("closed",t,i._handoff())}}))}},sendToTop:function(){this.active&&this.pointer.css("z-index",e++)},toggle:function(t){this.pointer.is(":hidden")?this.open(t):this.close(t)},_handoff:function(t){return s.extend({pointer:this.pointer,element:this.element},t)}})}(jQuery); \ No newline at end of file +!function(s){var i=0,e=9999;s.widget("wp.pointer",{options:{pointerClass:"wp-pointer",pointerWidth:320,content:function(){return s(this).text()},buttons:function(t,i){return s('').text(wp.i18n.__("Dismiss")).bind("click.pointer",function(t){t.preventDefault(),i.element.pointer("close")})},position:"top",show:function(t,i){i.pointer.show(),i.opened()},hide:function(t,i){i.pointer.hide(),i.closed()},document:document},_create:function(){var t;this.content=s('
'),this.arrow=s('
'),t="absolute",this.element.parents().add(this.element).filter(function(){return"fixed"===s(this).css("position")}).length&&(t="fixed"),this.pointer=s("
").append(this.content).append(this.arrow).attr("id","wp-pointer-"+i++).addClass(this.options.pointerClass).css({position:t,width:this.options.pointerWidth+"px",display:"none"}).appendTo(this.options.document.body)},_setOption:function(t,i){var e=this.options,n=this.pointer;"document"===t&&i!==e.document?n.detach().appendTo(i.body):"pointerClass"===t&&n.removeClass(e.pointerClass).addClass(i),s.Widget.prototype._setOption.apply(this,arguments),"position"===t?this.reposition():"content"===t&&this.active&&this.update()},destroy:function(){this.pointer.remove(),s.Widget.prototype.destroy.call(this)},widget:function(){return this.pointer},update:function(i){var t,e=this,n=this.options,o=s.Deferred();if(!n.disabled)return o.done(function(t){e._update(i,t)}),(t="string"==typeof n.content?n.content:n.content.call(this.element[0],o.resolve,i,this._handoff()))&&o.resolve(t),o.promise()},_update:function(t,i){var e,n=this.options;i&&(this.pointer.stop(),this.content.html(i),(e=n.buttons.call(this.element[0],t,this._handoff()))&&e.wrap('
').parent().appendTo(this.content),this.reposition())},reposition:function(){var t;this.options.disabled||(t=this._processPosition(this.options.position),this.pointer.css({top:0,left:0,zIndex:e++}).show().position(s.extend({of:this.element,collision:"fit none"},t)),this.repoint())},repoint:function(){var t,i=this.options;i.disabled||(t="string"==typeof i.position?i.position:i.position.edge,this.pointer[0].className=this.pointer[0].className.replace(/wp-pointer-[^\s'"]*/,""),this.pointer.addClass("wp-pointer-"+t))},_processPosition:function(t){var i,e={top:"bottom",bottom:"top",left:"right",right:"left"};return(i="string"==typeof t?{edge:t+""}:s.extend({},t)).edge&&("top"==i.edge||"bottom"==i.edge?(i.align=i.align||"left",i.at=i.at||i.align+" "+e[i.edge],i.my=i.my||i.align+" "+i.edge):(i.align=i.align||"top",i.at=i.at||e[i.edge]+" "+i.align,i.my=i.my||i.edge+" "+i.align)),i},open:function(t){var i=this,e=this.options;this.active||e.disabled||this.element.is(":hidden")||this.update().done(function(){i._open(t)})},_open:function(t){var i=this,e=this.options;this.active||e.disabled||this.element.is(":hidden")||(this.active=!0,this._trigger("open",t,this._handoff()),this._trigger("show",t,this._handoff({opened:function(){i._trigger("opened",t,i._handoff())}})))},close:function(t){if(this.active&&!this.options.disabled){var i=this;this.active=!1,this._trigger("close",t,this._handoff()),this._trigger("hide",t,this._handoff({closed:function(){i._trigger("closed",t,i._handoff())}}))}},sendToTop:function(){this.active&&this.pointer.css("z-index",e++)},toggle:function(t){this.pointer.is(":hidden")?this.open(t):this.close(t)},_handoff:function(t){return s.extend({pointer:this.pointer,element:this.element},t)}})}(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 8ad7adec8c..35b5823104 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -688,14 +688,8 @@ function wp_default_scripts( $scripts ) { ) ); - $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20111129a', 1 ); - did_action( 'init' ) && $scripts->localize( - 'wp-pointer', - 'wpPointerL10n', - array( - 'dismiss' => __( 'Dismiss' ), - ) - ); + $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), false, 1 ); + $scripts->set_translations( 'wp-pointer' ); $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array( 'heartbeat' ), false, 1 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 30fbe75ff7..ddd97acf0e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48265'; +$wp_version = '5.5-alpha-48266'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.