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

Allow to change orientation on the fly #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions angular.rangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@
*/

var $slider = angular.element(element),
uiDefaults = {
pos: 'left',
posOpp: 'right',
orientation: 0
},
handles = [element.find('.ngrs-handle-min'), element.find('.ngrs-handle-max')],
values = [element.find('.ngrs-value-min'), element.find('.ngrs-value-max')],
join = element.find('.ngrs-join'),
pos = 'left',
posOpp = 'right',
orientation = 0,
pos = uiDefaults.pos,
posOpp = uiDefaults.posOpp,
orientation = uiDefaults.orientation,
allowedRange = [0, 0],
range = 0,
down = false;
Expand Down Expand Up @@ -209,6 +214,9 @@

useClass = classNames.join(' ');

// remove classes before adding to ensure that there are no left-overs, so changing the orientation on the fly will work.
$slider.removeClass('ngrs-horizontal ngrs-vertical ngrs-left ngrs-right');

// add class to element
$slider.addClass(useClass);

Expand All @@ -217,7 +225,14 @@
pos = 'top';
posOpp = 'bottom';
orientation = 1;
} else { // back to defaults
pos = uiDefaults.pos;
posOpp = uiDefaults.posOpp;
orientation = uiDefaults.orientation;
}

setMinMax();
setPinHandle( scopeOptions.pinHandle );
});

attrs.$observe('step', function(val) {
Expand Down Expand Up @@ -393,6 +408,13 @@
scope.filteredModelMax = scope.modelMax;
}

// Reset CSS before applying, so changing the orientation on the fly will work.
angular.element( handles[0] ).css( 'top', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'right', '' );
angular.element( handles[1] ).css( 'top', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'right', '' );
angular.element( values[0] ).css( 'top', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'right', '' );
angular.element( values[1] ).css( 'top', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'right', '' );
angular.element( join ).css( 'top', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'right', '' );

// check for no range
if (scope.min === scope.max && scope.modelMin == scope.modelMax) {

Expand Down