From b170b56f09d1ec5ab5e34e997447546239e008fd Mon Sep 17 00:00:00 2001 From: Kaldari Date: Tue, 11 Dec 2012 17:09:47 -0800 Subject: [PATCH] Adding ability of jQuery badge to display the number zero if requested. This is needed by Echo extension. Change-Id: Id5e7cbb1aacbad1624474a6d9fac9b95cd1bc275 --- resources/jquery/jquery.badge.css | 9 +++++++-- resources/jquery/jquery.badge.js | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/resources/jquery/jquery.badge.css b/resources/jquery/jquery.badge.css index 7dd2198e62..9f446285ac 100644 --- a/resources/jquery/jquery.badge.css +++ b/resources/jquery/jquery.badge.css @@ -6,7 +6,6 @@ -moz-box-shadow: 0px 1px 4px #ccc; -webkit-box-shadow: 0px 1px 4px #ccc; box-shadow: 0px 1px 4px #ccc; - background-color: #cc0000; padding: 0 3px; text-align: center; font-size: 12px; @@ -24,10 +23,16 @@ display: inline-block; margin-left: 3px; } - .mw-badge-overlay { position: absolute; bottom: -1px; right: -3px; z-index: 50; } + +.mw-badge-red { + background-color: #cc0000; +} +.mw-badge-grey { + background-color: #d2d2d2; +} diff --git a/resources/jquery/jquery.badge.js b/resources/jquery/jquery.badge.js index c8073d1756..8a1f2988eb 100644 --- a/resources/jquery/jquery.badge.js +++ b/resources/jquery/jquery.badge.js @@ -31,17 +31,30 @@ * 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) + * @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) */ - $.fn.badge = function ( text, inline ) { - var $badge = this.find( '.mw-badge' ); + $.fn.badge = function ( text, inline, displayZero ) { + var $badge = this.find( '.mw-badge' ), + badgeStyleClass = 'mw-badge-' + ( inline ? 'inline' : 'overlay' ), + badgeColorClass = 'mw-badge-red'; // default color is red + // If we're displaying zero, change the color to grey + if ( displayZero && text === 0 ) { + badgeColorClass = 'mw-badge-grey'; + // Change zero to string so that it will be displayed + text = '0'; + } if ( text ) { // If a badge already exists, reuse it if ( $badge.length ) { $badge.find( '.mw-badge-content' ).text( text ); } else { // Otherwise, create a new badge with the specified text and style - $badge = $( '
' ) + $badge = $( '
' ) + .addClass( badgeStyleClass ) + .addClass( badgeColorClass ) .append( $( '' ).text ( text ) ) .appendTo( this ); } -- 2.20.1