Chad has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/391854 )
Change subject: Revert "resources: Remove the deprecated 'jquery.badge' module" ...................................................................... Revert "resources: Remove the deprecated 'jquery.badge' module" This reverts commit caaae4e6db3b63985049a172060d5f9cbbe9afae. Change-Id: I2c0c8936103313ba4979c7c303e762947823650c --- M RELEASE-NOTES-1.31 M jsduck.json M resources/Resources.php A resources/src/jquery/jquery.badge.css A resources/src/jquery/jquery.badge.js 5 files changed, 130 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/54/391854/1 diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index d9da9ac..312912c 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -33,7 +33,6 @@ * … ==== Removed and replaced external libraries ==== -* (T17845) The deprecated 'jquery.badge' module was removed. * The deprecated 'jquery.autoEllipsis' module was removed. Use the CSS text-overflow property instead. * The deprecated 'jquery.placeholder' module was removed. diff --git a/jsduck.json b/jsduck.json index 0021f37..a580c6b 100644 --- a/jsduck.json +++ b/jsduck.json @@ -21,6 +21,7 @@ "resources/src/mediawiki.toolbar", "resources/src/mediawiki.widgets", "resources/src/jquery/jquery.accessKeyLabel.js", + "resources/src/jquery/jquery.badge.js", "resources/src/jquery/jquery.byteLength.js", "resources/src/jquery/jquery.byteLimit.js", "resources/src/jquery/jquery.checkboxShiftClick.js", diff --git a/resources/Resources.php b/resources/Resources.php index 34b0836..81e0f02 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -154,6 +154,12 @@ 'jquery.async' => [ 'scripts' => 'resources/lib/jquery/jquery.async.js', ], + 'jquery.badge' => [ + 'deprecated' => 'Please use Notifications instead.', + 'scripts' => 'resources/src/jquery/jquery.badge.js', + 'styles' => 'resources/src/jquery/jquery.badge.css', + 'dependencies' => 'mediawiki.language', + ], 'jquery.byteLength' => [ 'scripts' => 'resources/src/jquery/jquery.byteLength.js', 'targets' => [ 'desktop', 'mobile' ], diff --git a/resources/src/jquery/jquery.badge.css b/resources/src/jquery/jquery.badge.css new file mode 100644 index 0000000..1157c27 --- /dev/null +++ b/resources/src/jquery/jquery.badge.css @@ -0,0 +1,35 @@ +.mw-badge { + background-color: #72777d; + min-width: 7px; + border-radius: 2px; + padding: 1px 4px; + text-align: center; + font-size: 12px; + line-height: 12px; + cursor: pointer; +} + +.mw-badge-content { + font-weight: bold; + color: #fff; + vertical-align: baseline; +} + +.mw-badge-inline { + margin-left: 3px; + display: inline-block; + /* Hack for IE6 and IE7 (T49926) */ + zoom: 1; + *display: inline; /* stylelint-disable-line declaration-block-no-duplicate-properties */ + +} +.mw-badge-overlay { + position: absolute; + bottom: -1px; + right: -3px; + z-index: 50; +} + +.mw-badge-important { + background-color: #d33; +} diff --git a/resources/src/jquery/jquery.badge.js b/resources/src/jquery/jquery.badge.js new file mode 100644 index 0000000..40b3baf --- /dev/null +++ b/resources/src/jquery/jquery.badge.js @@ -0,0 +1,88 @@ +/*! + * jQuery Badge plugin + * + * @license MIT + * + * @author Ryan Kaldari <rkald...@wikimedia.org>, 2012 + * @author Andrew Garrett <agarr...@wikimedia.org>, 2012 + * @author Marius Hoch <h...@online.de>, 2012 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * This program is distributed WITHOUT ANY WARRANTY. + */ + +/** + * @class jQuery.plugin.badge + */ +( function ( $, mw ) { + /** + * Put a badge on an item on the page. The badge container will be appended to the selected element(s). + * + * $element.badge( text ); + * $element.badge( 5 ); + * $element.badge( '100+' ); + * $element.badge( text, inline ); + * $element.badge( 'New', true ); + * + * @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. + * @param {boolean} [inline=true] True if the badge should be displayed inline, false + * if the badge should overlay the parent element. + * @param {boolean} [displayZero=false] True if the number zero should be displayed, + * false if the number zero should result in the badge being hidden + * @return {jQuery} + * @chainable + */ + $.fn.badge = function ( text, inline, displayZero ) { + var $badge = this.find( '.mw-badge' ), + badgeStyleClass = 'mw-badge-' + ( inline ? 'inline' : 'overlay' ), + isImportant = true, + displayBadge = true; + + // If we're displaying zero, ensure style to be non-important + if ( mw.language.convertNumber( text, true ) === 0 ) { + isImportant = false; + if ( !displayZero ) { + displayBadge = false; + } + // If text is falsey (besides 0), hide the badge + } else if ( !text ) { + displayBadge = false; + } + + if ( displayBadge ) { + // If a badge already exists, reuse it + if ( $badge.length ) { + $badge + .toggleClass( 'mw-badge-important', isImportant ) + .find( '.mw-badge-content' ).text( text ); + } else { + // Otherwise, create a new badge with the specified text and style + $badge = $( '<div class="mw-badge"></div>' ) + .addClass( badgeStyleClass ) + .toggleClass( 'mw-badge-important', isImportant ) + .append( + $( '<span class="mw-badge-content"></span>' ).text( text ) + ) + .appendTo( this ); + } + } else { + $badge.remove(); + } + return this; + }; + + /** + * @class jQuery + * @mixins jQuery.plugin.badge + */ +}( jQuery, mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/391854 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2c0c8936103313ba4979c7c303e762947823650c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: wmf/1.31.0-wmf.8 Gerrit-Owner: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits