Clean up badger.{css,js} from PageTriage, generalise it and move it into core.
Change-Id: I0f5e754146359448eb125456e240cf5768d4f541
This commit is contained in:
parent
0c1471c594
commit
f239fb3905
3 changed files with 120 additions and 0 deletions
|
|
@ -106,6 +106,10 @@ return array(
|
|||
'scripts' => 'resources/jquery/jquery.autoEllipsis.js',
|
||||
'dependencies' => 'jquery.highlightText',
|
||||
),
|
||||
'jquery.badge' => array(
|
||||
'scripts' => 'resources/jquery/jquery.badge.js',
|
||||
'styles' => 'resources/jquery/jquery.badge.css',
|
||||
),
|
||||
'jquery.byteLength' => array(
|
||||
'scripts' => 'resources/jquery/jquery.byteLength.js',
|
||||
),
|
||||
|
|
|
|||
38
resources/jquery/jquery.badge.css
Normal file
38
resources/jquery/jquery.badge.css
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
.mw-badge {
|
||||
min-width: 8px;
|
||||
height: 14px;
|
||||
border: 1px solid white;
|
||||
border-radius: 8px;
|
||||
-moz-border-radius: 8px;
|
||||
-webkit-border-radius: 8px;
|
||||
box-shadow: 0px 1px 4px #ccc;
|
||||
-moz-box-shadow: 0px 1px 4px #ccc;
|
||||
-webkit-box-shadow: 0px 1px 4px #ccc;
|
||||
background-color: #b60a00;
|
||||
background-image: linear-gradient(bottom, #a70802 0%, #cf0e00 100%);
|
||||
background-image: -o-linear-gradient(bottom, #a70802 0%, #cf0e00 100%);
|
||||
background-image: -moz-linear-gradient(bottom, #a70802 0%, #cf0e00 100%);
|
||||
background-image: -webkit-linear-gradient(bottom, #a70802 0%, #cf0e00 100%);
|
||||
background-image: -ms-linear-gradient(bottom, #a70802 0%, #cf0e00 100%);
|
||||
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #a70802), color-stop(1, #cf0e00));
|
||||
padding: 0 3px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mw-badge-content {
|
||||
font-size: 12px;
|
||||
line-height: 14px;
|
||||
color: white;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.mw-badge-inline {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.mw-badge-overlay {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
right: -3px;
|
||||
z-index: 50;
|
||||
}
|
||||
78
resources/jquery/jquery.badge.js
Normal file
78
resources/jquery/jquery.badge.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// Badger v1.0 by Daniel Raftery
|
||||
// http://thrivingkings.com/badger
|
||||
// http://twitter.com/ThrivingKings
|
||||
// Modified by Ryan Kaldari <rkaldari@wikimedia.org>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
(function( $ ) {
|
||||
$.fn.badge = function( badge, options ) {
|
||||
var existingBadge = this.find( '.mw-badge' );
|
||||
options = $.extend( {}, options );
|
||||
|
||||
badge = String(badge);
|
||||
if ( badge.charAt(0) === '+' ) {
|
||||
if ( existingBadge.length > 0 ) {
|
||||
oldBadge = existingBadge.text();
|
||||
badge = Math.round( Number( oldBadge ) + Number( badge.substr(1) ) );
|
||||
} else {
|
||||
badge = badge.substr(1);
|
||||
}
|
||||
} else if ( badge.charAt(0) === '-' ) {
|
||||
if ( existingBadge.length > 0 ) {
|
||||
oldBadge = existingBadge.text();
|
||||
badge = Math.round( Number( oldBadge ) - Number( badge.substr(1) ) );
|
||||
} else {
|
||||
badge = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Number(badge) <= 0 ) {
|
||||
// Clear any existing badge
|
||||
existingBadge.remove();
|
||||
} else {
|
||||
// Don't add duplicates
|
||||
var $badge = existingBadge;
|
||||
if ( existingBadge.length > 0 ) {
|
||||
this.find( '.mw-badge-content' ).text( badge );
|
||||
} else {
|
||||
$badge = $('<div/>')
|
||||
.addClass('mw-badge')
|
||||
.addClass('mw-badge-overlay')
|
||||
.append(
|
||||
$('<span/>')
|
||||
.addClass('mw-badge-content')
|
||||
.text(badge)
|
||||
);
|
||||
this.append($badge);
|
||||
}
|
||||
|
||||
if ( options.type ) {
|
||||
if ( options.type == 'inline' ) {
|
||||
$badge.removeClass('mw-badge-overlay')
|
||||
.addClass('mw-badge-inline');
|
||||
} else if ( options.type == 'overlay' ) {
|
||||
$badge.removeClass('mw-badge-inline')
|
||||
.addClass('mw-badge-overlay');
|
||||
}
|
||||
}
|
||||
|
||||
// If a callback was specified, call it with the badge number
|
||||
if ( options.callback ) {
|
||||
options.callback( badge );
|
||||
}
|
||||
}
|
||||
};
|
||||
} ) ( jQuery );
|
||||
Loading…
Reference in a new issue