Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest version of rangeslider.js and fix various RTL issues #119

Merged
merged 7 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions js/adapt-contrib-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ define([

this.$slider.rangeslider({
polyfill: false,
isRTL:this.model.get('_marginDir') == 'right',
onSlide: _.bind(this.handleSlide, this)
});
this.oldValue = 0;
Expand All @@ -53,23 +54,12 @@ define([
},

handleSlide: function (position, value) {
if(this.$('.rangeslider').hasClass('rangeslider--disabled')&&value==this.model.get('_scaleEnd')){
this.$('.rangeslider__fill').width("100%");
}
if (this.oldValue === value) {
return;
}
if(this.model.get('_marginDir') == 'right'){
if(this.tempValue && (this.model.get('_userAnswer') == undefined)){
value = this.model.get('_items').length - value + 1;
this.tempValue = false;
var tempPixels = this.mapIndexToPixels(value);
var rangeSliderWidth = this.$('.rangeslider').width();
var handleLeft = parseInt(this.$('.rangeslider__handle').css('left'));
var sliderWidth = this.$('.rangeslider__fill').width();
handleLeft = rangeSliderWidth - handleLeft -this.$('.rangeslider__handle').width();
sliderWidth = rangeSliderWidth - sliderWidth;
this.$('.rangeslider__handle').css('left',handleLeft);
this.$('.rangeslider__fill').width(sliderWidth);
}
}
var itemIndex = this.getIndexFromValue(value);
var pixels = this.mapIndexToPixels(itemIndex);
this.selectItem(itemIndex, false);
Expand Down Expand Up @@ -407,13 +397,6 @@ define([
this.$('.slider-handle').css({left: left + 'px'});
this.$('.slider-scale-marker').css({left: left + 'px'});
this.$('.slider-bar').width(left);
//updated position of rangeslider bar on window resize for RTL
if (this.model.get('_marginDir') == 'right') {
_.delay(function() {
this.$('.rangeslider__handle').css('left', left);
this.$('.rangeslider__fill').css('width', left + (this.$('.rangeslider__handle').width() / 2));
}, 300, this);
}
},

onScreenSizeChanged: function() {
Expand Down
4 changes: 3 additions & 1 deletion less/rangeslider.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40);
opacity: 0.4;
}

.rangeslider-rtl{
direction: rtl;
}
.rangeslider__fill {
background: #00ff00;
position: absolute;
Expand Down
8 changes: 0 additions & 8 deletions less/slider.less
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@
}
.rangeslider {
background-color: @background-color;
.dir-rtl & {
transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
/*IE9 does not support 3D transform*/
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
}
}
.rangeslider--disabled {
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
Expand Down
32 changes: 21 additions & 11 deletions libraries/rangeslider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! rangeslider.js - v2.1.1 | (c) 2016 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
/*! rangeslider.js - 2.3.0 | (c) 2016 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
(function(factory) {
'use strict';

Expand Down Expand Up @@ -37,8 +37,10 @@
defaults = {
polyfill: true,
orientation: 'horizontal',
isRTL:false,//RTL
rangeClass: 'rangeslider',
disabledClass: 'rangeslider--disabled',
activeClass: 'rangeslider--active',
horizontalClass: 'rangeslider--horizontal',
verticalClass: 'rangeslider--vertical',
fillClass: 'rangeslider__fill',
Expand Down Expand Up @@ -224,8 +226,8 @@
this.onSlide = this.options.onSlide;
this.onSlideEnd = this.options.onSlideEnd;
this.DIMENSION = constants.orientation[this.orientation].dimension;
this.DIRECTION = constants.orientation[this.orientation].direction;
this.DIRECTION_STYLE = constants.orientation[this.orientation].directionStyle;
this.DIRECTION = this.options.isRTL ? 'right' : 'left';
this.DIRECTION_STYLE = this.options.isRTL ? 'right' : 'left';
this.COORDINATE = constants.orientation[this.orientation].coordinate;

// Plugin should only be used as a polyfill
Expand All @@ -241,7 +243,7 @@
this.toFixed = (this.step + '').replace('.', '').length - 1;
this.$fill = $('<div class="' + this.options.fillClass + '" />');
this.$handle = $('<div class="' + this.options.handleClass + '" />');
this.$range = $('<div class="' + this.options.rangeClass + ' ' + this.options[this.orientation + 'Class'] + '" id="' + this.identifier + '" />').insertAfter(this.$element).prepend(this.$fill, this.$handle);
this.$range = $('<div class="' + this.options.rangeClass + (this.options.isRTL?' rangeslider-rtl ':'')+' '+ this.options[this.orientation + 'Class'] + '" id="' + this.identifier + '" />').insertAfter(this.$element).prepend(this.$fill, this.$handle);

// visually hide the input
this.$element.css({
Expand Down Expand Up @@ -315,9 +317,14 @@
};

Plugin.prototype.handleDown = function(e) {
e.preventDefault();
this.$document.on(this.moveEvent, this.handleMove);
this.$document.on(this.endEvent, this.handleEnd);

// add active class because Firefox is ignoring
// the handle:active pseudo selector because of `e.preventDefault();`
this.$range.addClass(this.options.activeClass);

// If we click on the handle don't set the new position
if ((' ' + e.target.className + ' ').replace(/[\n\t]/g, ' ').indexOf(this.options.handleClass) > -1) {
return;
Expand Down Expand Up @@ -347,6 +354,8 @@
this.$document.off(this.moveEvent, this.handleMove);
this.$document.off(this.endEvent, this.handleEnd);

this.$range.removeClass(this.options.activeClass);

// Ok we're done fire the change event
this.$element.trigger('change', { origin: this.identifier });

Expand All @@ -373,7 +382,7 @@
newPos = this.getPositionFromValue(value);

// Update ui
this.$fill[0].style[this.DIMENSION] = value == this.max ? '100%' : (newPos + this.grabPos) + 'px';
this.$fill[0].style[this.DIMENSION] = (newPos + this.grabPos) + 'px';
this.$handle[0].style[this.DIRECTION_STYLE] = newPos + 'px';
this.setValue(value);

Expand Down Expand Up @@ -402,20 +411,21 @@
rangePos = this.$range[0].getBoundingClientRect()[this.DIRECTION],
pageCoordinate = 0;

if (typeof e['page' + ucCoordinate] !== 'undefined') {
pageCoordinate = e['client' + ucCoordinate];
}
else if (typeof e.originalEvent['client' + ucCoordinate] !== 'undefined') {
if (typeof e.originalEvent['client' + ucCoordinate] !== 'undefined') {
pageCoordinate = e.originalEvent['client' + ucCoordinate];
}
else if (e.originalEvent.touches && e.originalEvent.touches[0] && typeof e.originalEvent.touches[0]['client' + ucCoordinate] !== 'undefined') {
else if (
e.originalEvent.touches &&
e.originalEvent.touches[0] &&
typeof e.originalEvent.touches[0]['client' + ucCoordinate] !== 'undefined'
) {
pageCoordinate = e.originalEvent.touches[0]['client' + ucCoordinate];
}
else if(e.currentPoint && typeof e.currentPoint[this.COORDINATE] !== 'undefined') {
pageCoordinate = e.currentPoint[this.COORDINATE];
}

return pageCoordinate - rangePos;
return this.options.isRTL?rangePos-pageCoordinate:pageCoordinate-rangePos;
};

Plugin.prototype.getPositionFromValue = function(value) {
Expand Down