From 53ac6a79a40540c17d13fb204c944fd667aca5e2 Mon Sep 17 00:00:00 2001 From: moloko Date: Wed, 22 Feb 2017 16:53:11 +0000 Subject: [PATCH 1/5] properly scope jquery selector (https://github.com/adaptlearning/adapt_framework/issues/1433) --- js/adapt-contrib-slider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/adapt-contrib-slider.js b/js/adapt-contrib-slider.js index a3795f5..96ece08 100644 --- a/js/adapt-contrib-slider.js +++ b/js/adapt-contrib-slider.js @@ -391,7 +391,7 @@ define([ var $markers = this.$('.slider-markers'); for (var i = 0, count = this.model.get('_items').length; i < count; i++) { $markers.append("
"); - $('.slider-line', $markers).eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'}); + this.$('.slider-line', $markers).eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'}); } var scaleWidth = $scaler.width(), $numbers = this.$('.slider-scale-number'); From a02e0607372aef6f1080722c209f30ed5579fccd Mon Sep 17 00:00:00 2001 From: moloko Date: Wed, 22 Feb 2017 17:00:21 +0000 Subject: [PATCH 2/5] switch to more terse & readable version of ternary statement --- js/adapt-contrib-slider.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/adapt-contrib-slider.js b/js/adapt-contrib-slider.js index 96ece08..2f51de0 100644 --- a/js/adapt-contrib-slider.js +++ b/js/adapt-contrib-slider.js @@ -1,7 +1,7 @@ define([ - 'coreViews/questionView', - 'coreJS/adapt', - 'libraries/rangeslider' + 'core/js/views/questionView', + 'core/js/adapt', + 'libraries/rangeslider' ], function(QuestionView, Adapt, Rangeslider) { var Slider = QuestionView.extend({ @@ -383,9 +383,9 @@ define([ this.$('.slider-markers').empty(); if (this.model.get('_showScale') === false) { this.$('.slider-markers').eq(0).css({display: 'none'}); - this.model.get('_showScaleIndicator') - ? this.$('.slider-scale-numbers').eq(0).css({visibility: 'hidden'}) - : this.$('.slider-scale-numbers').eq(0).css({display: 'none'}); + this.$('.slider-scale-numbers').eq(0).css( + this.model.get('_showScaleIndicator') ? {visibility: 'hidden'} : {display: 'none'} + ); } else { var $scaler = this.$('.slider-scaler'); var $markers = this.$('.slider-markers'); From 3f5ba1ac381a69930b538722f96255eba84b390d Mon Sep 17 00:00:00 2001 From: moloko Date: Thu, 23 Feb 2017 11:52:19 +0000 Subject: [PATCH 3/5] slight change to make intent clearer --- js/adapt-contrib-slider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/adapt-contrib-slider.js b/js/adapt-contrib-slider.js index 2f51de0..835aca5 100644 --- a/js/adapt-contrib-slider.js +++ b/js/adapt-contrib-slider.js @@ -391,7 +391,7 @@ define([ var $markers = this.$('.slider-markers'); for (var i = 0, count = this.model.get('_items').length; i < count; i++) { $markers.append("
"); - this.$('.slider-line', $markers).eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'}); + $markers.find('.slider-line').eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'}); } var scaleWidth = $scaler.width(), $numbers = this.$('.slider-scale-number'); From 76ee7a421409ec4fb06fa3bea7e21986ed329ff4 Mon Sep 17 00:00:00 2001 From: moloko Date: Thu, 23 Feb 2017 12:18:34 +0000 Subject: [PATCH 4/5] sort out indentation, spacing; declare variables separately as per our style guide; rename variables i and count to j and len to as to avoid variable redefinition. --- js/adapt-contrib-slider.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/js/adapt-contrib-slider.js b/js/adapt-contrib-slider.js index 835aca5..2b99849 100644 --- a/js/adapt-contrib-slider.js +++ b/js/adapt-contrib-slider.js @@ -393,16 +393,16 @@ define([ $markers.append("
"); $markers.find('.slider-line').eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'}); } - var scaleWidth = $scaler.width(), - $numbers = this.$('.slider-scale-number'); - for (var i = 0, count = this.model.get('_items').length; i < count; i++) { - var $number = $numbers.eq(i), - newLeft = Math.round($number.data('normalisedPosition') * scaleWidth); - if($('html').hasClass('ie9') && this.model.get('_marginDir')=='right'){ - $number.css({right: newLeft}); - } - else{ - $number.css({left: newLeft}); + var scaleWidth = $scaler.width(); + var $numbers = this.$('.slider-scale-number'); + for (var j = 0, len = this.model.get('_items').length; j < len; j++) { + var $number = $numbers.eq(j); + var newLeft = Math.round($number.data('normalisedPosition') * scaleWidth); + if($('html').hasClass('ie9') && this.model.get('_marginDir') === 'right') { + $number.css({right: newLeft}); + } + else{ + $number.css({left: newLeft}); } } } From 7b6d36f0a787cc8936c9038c09184e2f25081c79 Mon Sep 17 00:00:00 2001 From: moloko Date: Mon, 27 Feb 2017 17:07:26 +0000 Subject: [PATCH 5/5] cache .slider-markers selector as per suggestion by @tomgreenfield --- js/adapt-contrib-slider.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/adapt-contrib-slider.js b/js/adapt-contrib-slider.js index 2b99849..a6fffd7 100644 --- a/js/adapt-contrib-slider.js +++ b/js/adapt-contrib-slider.js @@ -380,15 +380,14 @@ define([ }, showScale: function () { - this.$('.slider-markers').empty(); + var $markers = this.$('.slider-markers').empty(); if (this.model.get('_showScale') === false) { - this.$('.slider-markers').eq(0).css({display: 'none'}); + $markers.eq(0).css({display: 'none'}); this.$('.slider-scale-numbers').eq(0).css( this.model.get('_showScaleIndicator') ? {visibility: 'hidden'} : {display: 'none'} ); } else { var $scaler = this.$('.slider-scaler'); - var $markers = this.$('.slider-markers'); for (var i = 0, count = this.model.get('_items').length; i < count; i++) { $markers.append("
"); $markers.find('.slider-line').eq(i).css({left: this.mapIndexToPixels(i, $scaler) + 'px'});