mediawiki-extensions-Revisi.../modules/ext.RevisionSlider.SectionLegend.js
Jakob Warkotsch 139368093e Adds the missing first revision to the slider.
The first revision was previously not included because revision size was
calculated by subtracting the size in bytes of a revision from the size
of the previous revision which lead to a problem with the first
revision. The first revision's relative size is now equal to its actual
size.

Bug: T135003
Change-Id: I71441ed33673b06407be0fc566c96c3955dddbf9
2016-05-12 15:25:37 +00:00

47 lines
1.2 KiB
JavaScript

( function ( mw, $ ) {
var SectionLegend = function ( revisionList ) {
this.revisionList = revisionList;
};
$.extend( SectionLegend.prototype, {
/**
* @type {RevisionList}
*/
revisionList: null,
getSectionColorMap: function () {
var sectionMap = [],
revisions = this.revisionList.getRevisions(),
section, i;
for ( i = 0; i < revisions.length; i++ ) {
section = revisions[ i ].getSection();
if ( section.length > 0 && !( section in sectionMap ) ) {
sectionMap[ section ] = '';
}
}
i = 0;
for ( section in sectionMap ) {
sectionMap[ section ] = mw.libs.revisionSlider.rainbow( Object.keys( sectionMap ).length, i );
i++;
}
return sectionMap;
},
getHtml: function () {
var sectionMap = this.getSectionColorMap(),
html = '<div class="revisions-legend">',
sectionName;
for ( sectionName in sectionMap ) {
html += '<span class="rvslider-legend-box" style="color:' + sectionMap[ sectionName ] + ';"> ■</span>' + sectionName;
}
return html + '</div>';
}
} );
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
mw.libs.revisionSlider.SectionLegend = SectionLegend;
}( mediaWiki, jQuery ) );