Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315731

Change subject: Avoid parseInt
......................................................................

Avoid parseInt

Where we know the number contains only numerals, just cast
straight to a number using '+' operator. When getting computed
css from jQuery, use more suitable position methods instead.

Change-Id: Ia58b41a4522a1ef5a1516852821573c47e8dc9c9
---
M modules/ext.RevisionSlider.RevisionListView.js
M modules/ext.RevisionSlider.SliderView.js
2 files changed, 8 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RevisionSlider 
refs/changes/31/315731/1

diff --git a/modules/ext.RevisionSlider.RevisionListView.js 
b/modules/ext.RevisionSlider.RevisionListView.js
index e7fce2a..58d1947 100644
--- a/modules/ext.RevisionSlider.RevisionListView.js
+++ b/modules/ext.RevisionSlider.RevisionListView.js
@@ -132,9 +132,9 @@
                 * @param {jQuery} $rev
                 */
                showTooltip: function ( $rev ) {
-                       var pos = parseInt( $rev.find( '.mw-revslider-revision' 
).attr( 'data-pos' ), 10 ),
-                               revId = parseInt( $rev.find( 
'.mw-revslider-revision' ).attr( 'data-revid' ), 10 ),
-                               revision =  this.getRevisionWithId( revId ),
+                       var pos = +$rev.find( '.mw-revslider-revision' ).attr( 
'data-pos' ),
+                               revId = +$rev.find( '.mw-revslider-revision' 
).attr( 'data-revid' ),
+                               revision = this.getRevisionWithId( revId ),
                                tooltip;
                        if ( revision === null ) {
                                return;
diff --git a/modules/ext.RevisionSlider.SliderView.js 
b/modules/ext.RevisionSlider.SliderView.js
index 5b49fe8..88acf9b 100644
--- a/modules/ext.RevisionSlider.SliderView.js
+++ b/modules/ext.RevisionSlider.SliderView.js
@@ -206,10 +206,11 @@
                                stop: function () {
                                        var $p = $( this ),
                                                pointer = self.whichPointer( $p 
),
-                                               pos = parseInt( $p.css( 'left' 
), 10 ),
+                                               pos = $p.position().left,
                                                adjustedPos = self.dir === 
'rtl' ? pointer.getView().getAdjustedLeftPositionWhenRtl( pos ) : pos,
                                                relativeIndex = Math.ceil( ( 
adjustedPos + self.revisionWidth / 2 ) / self.revisionWidth ),
                                                revId1, revId2;
+
                                        mw.track( 
'counter.MediaWiki.RevisionSlider.event.pointerMove' );
                                        pointer.setPosition( 
self.slider.getFirstVisibleRevisionIndex() + relativeIndex );
                                        
self.resetPointerStylesBasedOnPosition();
@@ -312,14 +313,14 @@
                                pNew = view.getNewRevPointer();
 
                        if ( hasClickedTop ) {
-                               pNew.setPosition( parseInt( $clickedRev.attr( 
'data-pos' ), 10 ) );
+                               pNew.setPosition( +$clickedRev.attr( 'data-pos' 
) );
                                view.updatePointerPositionAttributes();
                                view.refreshRevisions(
                                        view.getRevElementAtPosition( 
$revisions, pOld.getPosition() ).data( 'revid' ),
                                        $clickedRev.data( 'revid' )
                                );
                        } else {
-                               pOld.setPosition( parseInt( $clickedRev.attr( 
'data-pos' ), 10 ) );
+                               pOld.setPosition( +$clickedRev.attr( 'data-pos' 
) );
                                view.updatePointerPositionAttributes();
                                view.refreshRevisions(
                                        $clickedRev.data( 'revid' ),
@@ -809,7 +810,7 @@
                 * @return {boolean}
                 */
                shouldExpandSlider: function ( $slider ) {
-                       var sliderWidth = parseInt( $slider.css( 'width' ), 10 
),
+                       var sliderWidth = $slider.width(),
                                maxAvailableWidth = 
this.calculateSliderContainerWidth() + this.containerMargin;
 
                        return !( this.noMoreNewerRevisions && 
this.noMoreOlderRevisions ) && sliderWidth < maxAvailableWidth;

-- 
To view, visit https://gerrit.wikimedia.org/r/315731
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia58b41a4522a1ef5a1516852821573c47e8dc9c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RevisionSlider
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to