1 // Badger v1.0 by Daniel Raftery
2 // http://thrivingkings.com/badger
3 // http://twitter.com/ThrivingKings
4 // Modified by Ryan Kaldari <rkaldari@wikimedia.org>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * This program is distributed WITHOUT ANY WARRANTY.
21 $.fn
.badge = function( badge
, options
) {
22 var existingBadge
= this.find( '.mw-badge' );
23 options
= $.extend( {}, options
);
25 badge
= String(badge
);
26 if ( badge
.charAt(0) === '+' ) {
27 if ( existingBadge
.length
> 0 ) {
28 oldBadge
= existingBadge
.text();
29 badge
= Math
.round( Number( oldBadge
) + Number( badge
.substr(1) ) );
31 badge
= badge
.substr(1);
33 } else if ( badge
.charAt(0) === '-' ) {
34 if ( existingBadge
.length
> 0 ) {
35 oldBadge
= existingBadge
.text();
36 badge
= Math
.round( Number( oldBadge
) - Number( badge
.substr(1) ) );
42 if ( Number(badge
) <= 0 ) {
43 // Clear any existing badge
44 existingBadge
.remove();
46 // Don't add duplicates
47 var $badge
= existingBadge
;
48 if ( existingBadge
.length
> 0 ) {
49 this.find( '.mw-badge-content' ).text( badge
);
53 .addClass('mw-badge-overlay')
56 .addClass('mw-badge-content')
63 if ( options
.type
== 'inline' ) {
64 $badge
.removeClass('mw-badge-overlay')
65 .addClass('mw-badge-inline');
66 } else if ( options
.type
== 'overlay' ) {
67 $badge
.removeClass('mw-badge-inline')
68 .addClass('mw-badge-overlay');
72 // If a callback was specified, call it with the badge number
73 if ( options
.callback
) {
74 options
.callback( badge
);