-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
lock_to_ticks #744
lock_to_ticks #744
Conversation
please:
|
Issue: #737 |
Adding lock_to_ticks: true will lock the selection to the values defined inside "ticks"
|
For the example, please add it to github pages branch. |
Example has been added to tpl/index.tpl. Should I add it anywhere else ? |
Ah, gh-pages branch. Will do it now |
done. Please let me know If I'm missing something |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heidarmostafa looks solid! could you post a JSFiddle or codepen with the changes just so we can get a quick glance as to what this functionality provides?
I also left some comments in the PR
dist/css/bootstrap-slider.css
Outdated
@@ -1,308 +0,0 @@ | |||
/*! ======================================================= | |||
VERSION 9.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove any changes to the dist directory from this PR? this are compiled files that get generated when we publish a new version
src/js/bootstrap-slider.js
Outdated
this._state.value[1] = this.options.ticks[this._getClosestTickIndex(this._state.value[1])]; | ||
} | ||
} catch(err) { | ||
console.error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this code block throw an error?
@@ -1078,12 +1089,10 @@ const windowIsDefined = (typeof window === "object"); | |||
this.ticksCallbackMap = null; | |||
|
|||
if (this.showTooltip) { | |||
this.handle1.removeEventListener("focus", this.showTooltip, false); | |||
this.handle2.removeEventListener("focus", this.showTooltip, false); | |||
this._removeTooltipListener("focus"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice refactoring!! 👍
src/js/bootstrap-slider.js
Outdated
@@ -1682,28 +1691,29 @@ const windowIsDefined = (typeof window === "object"); | |||
|
|||
return false; | |||
}, | |||
_setValues: function(index, val) { | |||
var comp = index === 0 ? 0 : 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use an ES6 const
declaration instead of var
? also, wrap the conditional in parenthesis to make it stand out more easily
src/js/bootstrap-slider.js
Outdated
@@ -1907,6 +1917,18 @@ const windowIsDefined = (typeof window === "object"); | |||
tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px'; | |||
}.bind(this)); | |||
} | |||
}, | |||
_getClosestTickIndex: function(val) { | |||
var difference = Math.abs(val - this.options.ticks[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you declare these vars as let
instead of var
?
src/js/bootstrap-slider.js
Outdated
_getClosestTickIndex: function(val) { | ||
var difference = Math.abs(val - this.options.ticks[0]); | ||
var index = 0; | ||
for (var i = 0; i < this.options.ticks.length; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare the i
as let
instead of var
testSlider.slider("setValue", [4, 102]); | ||
|
||
//getting the actual values. They should be the closest values from ticks (which are 1 and 50 on this case) | ||
var values = testSlider.slider("getValue"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice test btw!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also add a test case for a vertical slider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Please have a final review and let me know if something is missing. Thanks.
I rolled back the dist folder. Now codeclimate detect duplicate between the src and the dist. We need to ignore this error I think. |
Don't worry too much about the codeclimate check...I'm more concerned with the Travis CI check (which looks like its passing) |
jsfiddle: https://jsfiddle.net/vk2q7rxb/ |
Yep. Can you merge it now? I'd also be happy to work on other issues or planned features :) |
src/js/bootstrap-slider.js
Outdated
@@ -1682,28 +1687,34 @@ const windowIsDefined = (typeof window === "object"); | |||
|
|||
return false; | |||
}, | |||
_setValues: function(index, val) { | |||
let comp; | |||
if(0 === index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep this as a ternary, but just declare it as a const
const comp = (0 === index) ? 0 : 100;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heidarmostafa left some other minor feedback
src/sass/_rules.scss
Outdated
@@ -5,6 +5,7 @@ | |||
&.slider-horizontal { | |||
width: $slider-horizontal-width; | |||
height: $slider-line-height; | |||
margin: 0 0 010px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you fix this?
testSlider.slider("setValue", [4, 102]); | ||
|
||
//getting the actual values. They should be the closest values from ticks (which are 1 and 50 on this case) | ||
var values = testSlider.slider("getValue"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also add a test case for a vertical slider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heidarmostafa I just cloned down your branch and ran it locally and it looks great!
I found one final thing during QA...If I use the Tab key to get the focus on one of the handles, and then try to move the handle with my arrow keys, it does not move to the next tick.
Steps to Replicate:
1) Load up a page with the slider configured with the lock_to_ticks
option.
2) Use the Tab key to get the focus onto the handle. A handle with focus has a blue outline, and should look like this in Chrome:
3) Press arrow keys to move the slider.
Expected behavior: handle snaps to nearest tick based on arrow key press
current behavior: handle remains in place
@heidarsaleh did you get a chance to see my feedback? other than that, it looks great! |
Sorry I wasn't available the past few days. I'll fix it this weekend. |
@heidarsaleh no rush! whenever you get a chance |
@heidarsaleh any chance to look at my feedback? I would love to merge this in! |
@heidarsaleh any chance to check this out? |
I've checked it Today.This feature will require a lot of changes in different places. I'll try to fix it soon. |
any update on this? |
@heidarsaleh i know its been a while, but did you even get a chance to look at this again? |
Merged changes from: seiyria#873
Added `tickIndex` to slider state which is an array of which ticks the slider handle(s) are set (can be -1). The array is computed in the `_setTickIndex()` function. This can be useful for setting the value(s) of the slider based on `options.ticks[]`.
Test for cases when `ticks[]` is not defined and when `setAttribute()` may be called during runtime.
Also added comments to help explain the mouse navigation tests.
Also added comments to help explain keyboard navigation tests
This fix is related to seiyria#896 which calls `setValue()` in `_mouseup()`.
src/js/bootstrap-slider.js
Outdated
var val; | ||
if (this.ticksAreValid && this.options.lock_to_ticks) { | ||
var index; | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rovolution I use a try-catch block but there is no "real" exception occuring. I just check index === -1
which shouldn't happen and fallback to setting index
to 0
. I can change this to a regular if-else check.
I decided to replace the I've manually tested the API examples and everything seems to work |
@jespirit does the keyboard stuff I mentioned in this comment work as well? |
Sure does! |
Pull Requests
Please accompany all pull requests with the following (where appropriate):
grunt test
in your Terminal within the bootstrap-slider repository directory