Introduce RevisionsListView element

This will avoid several jQuery calls.

Change-Id: I1934bcfde97415ca0c01465037f34d2555b6daa4
This commit is contained in:
WMDE-Fisch 2017-04-13 17:01:02 +02:00
parent de86ba0a3e
commit 624b4786ec
2 changed files with 24 additions and 7 deletions

View file

@ -30,14 +30,18 @@
*/
dir: null,
/**
* @type {jQuery}
*/
html: null,
/**
* @param {number} revisionTickWidth
* @param {number} positionOffset
* @return {jQuery}
*/
render: function ( revisionTickWidth, positionOffset ) {
var $html = $( '<div>' ).addClass( 'mw-revslider-revisions' ),
revs = this.revisionList.getRevisions(),
var revs = this.revisionList.getRevisions(),
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
self = this,
i, diffSize, relativeChangeSize,
@ -51,11 +55,13 @@
positionOffset = positionOffset || 0;
this.revisionWidth = revisionTickWidth;
this.$html = $( '<div>' ).addClass( 'mw-revslider-revisions' );
for ( i = 0; i < revs.length; i++ ) {
diffSize = revs[ i ].getRelativeSize();
relativeChangeSize = diffSize !== 0 ? Math.ceil( 65.0 * Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) + 5 : 0;
$html
this.$html
.append( $( '<div>' )
.addClass( 'mw-revslider-revision-wrapper' )
.width( this.revisionWidth )
@ -79,7 +85,7 @@
this.keepTooltipsOnHover();
this.closeTooltipsOnClick();
return $html;
return this.$html;
},
/**
@ -348,6 +354,13 @@
*/
setDir: function ( dir ) {
this.dir = dir;
},
/**
* @return {jQuery}
*/
getElement: function() {
return this.$html;
}
} );

View file

@ -108,7 +108,7 @@
return pos;
}
$revisions = $( '.mw-revslider-revisions' );
$revisions = this.getRevisionsElement();
$hoveredRevisionWrapper = this.getRevElementAtPosition( $revisions, pos ).parent();
this.slider.getRevisions().getView().showTooltip( $hoveredRevisionWrapper );
@ -151,7 +151,7 @@
return;
}
$revisions = this.$element.find( '.mw-revslider-revisions' );
$revisions = this.getRevisionsElement();
$clickedRev = this.getRevElementAtPosition( $revisions, pos );
pointerMoved.setPosition( pos );
@ -165,7 +165,7 @@
},
getRevisionPositionFromLeftOffset: function( leftOffset ) {
var $revisions = $( '.mw-revslider-revisions' ),
var $revisions = this.getRevisionsElement(),
revisionsX = $revisions.offset().left,
pos = Math.ceil( Math.abs( leftOffset - revisionsX ) / this.revisionWidth );
@ -241,6 +241,10 @@
return this.pointerNewer.getPosition() - this.pointerOlder.getPosition();
},
getRevisionsElement: function() {
return this.slider.getRevisions().getView().getElement();
},
revisionWrapperClickHandler: function() {
}
} );