jenkins-bot has submitted this change and it was merged.

Change subject: jquery.badge: Treat non-Latin variants of zero as zero as well.
......................................................................


jquery.badge: Treat non-Latin variants of zero as zero as well.

Bug: 45143
Change-Id: Ib8a36913df1ec4ae966551d1d5b8de712c34b96c
---
M RELEASE-NOTES-1.21
M resources/Resources.php
M resources/jquery/jquery.badge.js
3 files changed, 18 insertions(+), 11 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21
index 3ee0704..e7e718d 100644
--- a/RELEASE-NOTES-1.21
+++ b/RELEASE-NOTES-1.21
@@ -202,6 +202,7 @@
 * (bug 42430) Calling numRows on MySQL no longer propagates unrelated errors.
 * (bug 44719) Removed mention of non-existing maintenance/migrateCurStubs.php
   script in includes/DefaultSettings.php
+* (bug 45143) jquery.badge: Treat non-Latin variants of zero as zero as well.
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat.
diff --git a/resources/Resources.php b/resources/Resources.php
index 1a11cd4..f5a31fd 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -149,6 +149,7 @@
        'jquery.badge' => array(
                'scripts' => 'resources/jquery/jquery.badge.js',
                'styles' => 'resources/jquery/jquery.badge.css',
+               'dependencies' => 'mediawiki.language',
        ),
        'jquery.byteLength' => array(
                'scripts' => 'resources/jquery/jquery.byteLength.js',
diff --git a/resources/jquery/jquery.badge.js b/resources/jquery/jquery.badge.js
index 16e7196..9404e81 100644
--- a/resources/jquery/jquery.badge.js
+++ b/resources/jquery/jquery.badge.js
@@ -21,32 +21,37 @@
  *
  * This program is distributed WITHOUT ANY WARRANTY.
  */
-( function ( $ ) {
+( function ( $, mw ) {
        /**
         * Allows you to put a "badge" on an item on the page. The badge 
container
         * will be appended to the selected element(s).
         * See mediawiki.org/wiki/ResourceLoader/Default_modules#jQuery.badge
         *
         * @param {number|string} text The value to display in the badge. If 
the value is falsey (0,
-        *   null, false, '', etc.), any existing badge will be removed.
+        *  null, false, '', etc.), any existing badge will be removed.
         * @param {boolean} inline True if the badge should be displayed 
inline, false
-        *   if the badge should overlay the parent element (default is inline)
+        *  if the badge should overlay the parent element (default is inline)
         * @param {boolean} displayZero True if the number zero should be 
displayed,
-        *   false if the number zero should result in the badge being hidden
-        *   (default is zero will result in the badge being hidden)
+        *  false if the number zero should result in the badge being hidden
+        *  (default is zero will result in the badge being hidden)
         */
        $.fn.badge = function ( text, inline, displayZero ) {
                var $badge = this.find( '.mw-badge' ),
                        badgeStyleClass = 'mw-badge-' + ( inline ? 'inline' : 
'overlay' ),
-                       isImportant = true;
+                       isImportant = true, displayBadge = true;
 
                // If we're displaying zero, ensure style to be non-important
-               if ( text === 0 && displayZero ) {
+               if ( mw.language.convertNumber( text, true ) === 0 ) {
                        isImportant = false;
-                       text = '0';
+                       if ( !displayZero ) {
+                               displayBadge = false;
+                       }
+               // If text is falsey (besides 0), hide the badge
+               } else if ( !text ) {
+                       displayBadge = false;
                }
 
-               if ( text ) {
+               if ( displayBadge ) {
                        // If a badge already exists, reuse it
                        if ( $badge.length ) {
                                $badge
@@ -59,7 +64,7 @@
                                        .addClass( badgeStyleClass )
                                        .toggleClass( 'mw-badge-important', 
isImportant )
                                        .append(
-                                               $( '<span 
class="mw-badge-content"></span>' ).text ( text )
+                                               $( '<span 
class="mw-badge-content"></span>' ).text( text )
                                        )
                                        .appendTo( this );
                        }
@@ -68,4 +73,4 @@
                }
                return this;
        };
-}( jQuery ) );
+}( jQuery, mediaWiki ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/49820
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib8a36913df1ec4ae966551d1d5b8de712c34b96c
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to