Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion dist/rangeslider.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
height: 100%;
}

.rangeslider__rtl {
direction: rtl;
}

.rangeslider__ttb {
top: 0;
}

.rangeslider--disabled {
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40);
opacity: 0.4;
Expand Down Expand Up @@ -109,4 +117,4 @@ input[type="range"]:focus + .rangeslider .rangeslider__handle {
-moz-box-shadow: 0 0 8px rgba(255, 0, 255, 0.9);
-webkit-box-shadow: 0 0 8px rgba(255, 0, 255, 0.9);
box-shadow: 0 0 8px rgba(255, 0, 255, 0.9);
}
}
36 changes: 27 additions & 9 deletions dist/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
activeClass: 'rangeslider--active',
horizontalClass: 'rangeslider--horizontal',
verticalClass: 'rangeslider--vertical',
dirRTLClass:'rangeslider__rtl',
dirTTBClass:'rangeslider__ttb',
fillClass: 'rangeslider__fill',
handleClass: 'rangeslider__handle',
startEvent: ['mousedown', 'touchstart', 'pointerdown'],
Expand All @@ -52,14 +54,14 @@
orientation: {
horizontal: {
dimension: 'width',
direction: 'left',
directionStyle: 'left',
direction: { ltr: 'left', rtl: 'right'},
directionStyle: { ltr: 'left', rtl: 'right' },
coordinate: 'x'
},
vertical: {
dimension: 'height',
direction: 'top',
directionStyle: 'bottom',
direction: { btt:'top', ttb:'bottom' },
directionStyle: { btt:'bottom', ttb:'top' },
coordinate: 'y'
}
}
Expand Down Expand Up @@ -209,6 +211,21 @@
return str.charAt(0).toUpperCase() + str.substr(1);
}

/**
* return direction rtl,ltr,btt,ttb
* @param {String} element
* @param {String} orientation
*/
function getDirection(element, orientation){
var direction = element[0].getAttribute('data-direction') || (orientation === 'vertical' ? 'btt' : 'ltr');

if (constants.orientation[orientation].direction[direction]) {
return direction;
} else {
return orientation === 'vertical' ? 'btt' : 'ltr';
}
}

/**
* Plugin
* @param {String} element
Expand All @@ -221,12 +238,13 @@
this.options = $.extend( {}, defaults, options );
this.polyfill = this.options.polyfill;
this.orientation = this.$element[0].getAttribute('data-orientation') || this.options.orientation;
this.dir = getDirection(this.$element,this.orientation);
this.onInit = this.options.onInit;
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 = constants.orientation[this.orientation].direction[this.dir];
this.DIRECTION_STYLE = constants.orientation[this.orientation].directionStyle[this.dir];
this.COORDINATE = constants.orientation[this.orientation].coordinate;

// Plugin should only be used as a polyfill
Expand All @@ -240,9 +258,9 @@
this.moveEvent = this.options.moveEvent.join('.' + this.identifier + ' ') + '.' + this.identifier;
this.endEvent = this.options.endEvent.join('.' + this.identifier + ' ') + '.' + this.identifier;
this.toFixed = (this.step + '').replace('.', '').length - 1;
this.$fill = $('<div class="' + this.options.fillClass + '" />');
this.$fill = $('<div class="' + this.options.fillClass +' '+(this.dir==='ttb'&&this.orientation==='vertical'? this.options.dirTTBClass: '') +'" />');
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.dir==='rtl'&&this.orientation==='horizontal'? this.options.dirRTLClass: '') + ' ' + 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 @@ -428,7 +446,7 @@
pageCoordinate = e.currentPoint[this.COORDINATE];
}

return pageCoordinate - rangePos;
return (this.dir==='rtl'||this.dir==='ttb') ? rangePos - pageCoordinate:pageCoordinate - rangePos;
};

Plugin.prototype.getPositionFromValue = function(value) {
Expand Down
36 changes: 27 additions & 9 deletions src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
activeClass: 'rangeslider--active',
horizontalClass: 'rangeslider--horizontal',
verticalClass: 'rangeslider--vertical',
dirRTLClass: 'rangeslider__rtl',
dirTTBClass: 'rangeslider__ttb',
fillClass: 'rangeslider__fill',
handleClass: 'rangeslider__handle',
startEvent: ['mousedown', 'touchstart', 'pointerdown'],
Expand All @@ -51,14 +53,14 @@
orientation: {
horizontal: {
dimension: 'width',
direction: 'left',
directionStyle: 'left',
direction: { ltr: 'left', rtl: 'right'},
directionStyle: { ltr: 'left', rtl: 'right' },
coordinate: 'x'
},
vertical: {
dimension: 'height',
direction: 'top',
directionStyle: 'bottom',
direction: { btt:'top', ttb:'bottom' },
directionStyle: { btt:'bottom', ttb:'top' },
coordinate: 'y'
}
}
Expand Down Expand Up @@ -208,6 +210,21 @@
return str.charAt(0).toUpperCase() + str.substr(1);
}

/**
* return direction rtl,ltr,btt,ttb
* @param {String} element
* @param {String} orientation
*/
function getDirection(element,orientation){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you follow the rest of the file's formatting style for new code you've written? Namely, please have spaces between symbols, commas, and other delimiters. Example for this function:

function getDirection(element, orientation) {
  var direction = element[0].getAttribute('data-direction') || (orientation === 'vertical' ? 'btt' : 'ltr');

  if (constants.orientation[orientation].direction[direction]) {
    return direction;
  } else {
    return orientation === 'vertical' ? 'btt' : 'ltr';
  }
}

var direction = element[0].getAttribute('data-direction') || (orientation === 'vertical' ? 'btt' : 'ltr');

if (constants.orientation[orientation].direction[direction]) {
return direction;
} else {
return orientation === 'vertical' ? 'btt' : 'ltr';
}
}

/**
* Plugin
* @param {String} element
Expand All @@ -220,12 +237,13 @@
this.options = $.extend( {}, defaults, options );
this.polyfill = this.options.polyfill;
this.orientation = this.$element[0].getAttribute('data-orientation') || this.options.orientation;
this.dir = getDirection(this.$element,this.orientation);
this.onInit = this.options.onInit;
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 = constants.orientation[this.orientation].direction[this.dir];
this.DIRECTION_STYLE = constants.orientation[this.orientation].directionStyle[this.dir];
this.COORDINATE = constants.orientation[this.orientation].coordinate;

// Plugin should only be used as a polyfill
Expand All @@ -239,9 +257,9 @@
this.moveEvent = this.options.moveEvent.join('.' + this.identifier + ' ') + '.' + this.identifier;
this.endEvent = this.options.endEvent.join('.' + this.identifier + ' ') + '.' + this.identifier;
this.toFixed = (this.step + '').replace('.', '').length - 1;
this.$fill = $('<div class="' + this.options.fillClass + '" />');
this.$fill = $('<div class="' + this.options.fillClass + ' ' +(this.dir === 'ttb' && this.orientation === 'vertical' ? this.options.dirTTBClass : '') +'" />');
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.dir === 'rtl' && this.orientation === 'horizontal' ? this.options.dirRTLClass : '') + ' ' + 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 @@ -427,7 +445,7 @@
pageCoordinate = e.currentPoint[this.COORDINATE];
}

return pageCoordinate - rangePos;
return (this.dir === 'rtl' || this.dir === 'ttb') ? rangePos - pageCoordinate : pageCoordinate - rangePos;
};

Plugin.prototype.getPositionFromValue = function(value) {
Expand Down
10 changes: 10 additions & 0 deletions src/rangeslider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $rangeslider--disabled: ".rangeslider--disabled";
$rangeslider--active: ".rangeslider--active";
$rangeslider__fill: ".rangeslider__fill";
$rangeslider__handle: ".rangeslider__handle";
$rangeslider__rtl: ".rangeslider__rtl";
$rangeslider__ttb: ".rangeslider__ttb";

#{$rangeslider},
#{$rangeslider__fill} {
Expand All @@ -32,6 +34,14 @@ $rangeslider__handle: ".rangeslider__handle";
height: 100%;
}

#{$rangeslider__rtl} {
direction: rtl;
}

#{$rangeslider__ttb} {
top: 0;
}

#{$rangeslider--disabled} {
@include opacity(.4);
}
Expand Down