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
This commit is contained in:
Dominik Schilling 2020-07-01 19:30:02 +00:00
parent 45d19872fc
commit d686fa266b
4 changed files with 5 additions and 14 deletions

View File

@ -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 = $('<a class="close" href="#">' + close + '</a>');
var button = $('<a class="close" href="#"></a>').text( wp.i18n.__( 'Dismiss' ) );
return button.bind( 'click.pointer', function(e) {
e.preventDefault();

View File

@ -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('<a class="close" href="#">'+e+"</a>").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('<div class="wp-pointer-content"></div>'),this.arrow=s('<div class="wp-pointer-arrow"><div class="wp-pointer-arrow-inner"></div></div>'),t="absolute",this.element.parents().add(this.element).filter(function(){return"fixed"===s(this).css("position")}).length&&(t="fixed"),this.pointer=s("<div />").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('<div class="wp-pointer-buttons" />').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);
!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('<a class="close" href="#"></a>').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('<div class="wp-pointer-content"></div>'),this.arrow=s('<div class="wp-pointer-arrow"><div class="wp-pointer-arrow-inner"></div></div>'),t="absolute",this.element.parents().add(this.element).filter(function(){return"fixed"===s(this).css("position")}).length&&(t="fixed"),this.pointer=s("<div />").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('<div class="wp-pointer-buttons" />').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);

View File

@ -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 );

View File

@ -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.