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

lock_to_ticks #744

Merged
merged 25 commits into from
Jan 4, 2019
Merged

lock_to_ticks #744

merged 25 commits into from
Jan 4, 2019

Conversation

heidarsaleh
Copy link
Contributor

Pull Requests

Please accompany all pull requests with the following (where appropriate):

  • unit tests (we use Jasmine 2.x.x)
  • JSFiddle (or an equivalent such as CodePen, Plunker, etc) or screenshot/GIF with new feature or bug-fix
  • Link to original Github issue (if this is a bug-fix)
  • documentation updates to README file
  • examples within /tpl/index.tpl (for new options being added)
  • Passes CI-server checks (runs automated tests, JS source-code linting, etc..). To run these on your local machine, type grunt test in your Terminal within the bootstrap-slider repository directory

@seiyria
Copy link
Owner

seiyria commented Apr 29, 2017

please:

  • make sure your code passes our CI
  • add unit tests
  • link to the issue this is referencing
  • update the documentation
  • add an example

@heidarsaleh
Copy link
Contributor Author

Issue: #737

@heidarsaleh
Copy link
Contributor Author

Adding lock_to_ticks: true will lock the selection to the values defined inside "ticks"
Example:

$("#id_size_select").slider({
                tooltip: 'always',
                tooltip_position: 'top',
                step: 10,
                ticks: [1, 10, 50, 200, 500, 1000, 5000, 10000],
                ticks_positions: [1, 14.28, 28.56, 42.84, 57.12, 71.4, 85.68, 100],
                ticks_snap_bounds: 5000,
                lock_to_ticks: true        //now user will only be able to select 1, 10, 50, 200, 500, 1000, 5000 or 10000
            });

@seiyria
Copy link
Owner

seiyria commented May 5, 2017

For the example, please add it to github pages branch.

@heidarsaleh
Copy link
Contributor Author

Example has been added to tpl/index.tpl. Should I add it anywhere else ?

@heidarsaleh
Copy link
Contributor Author

Ah, gh-pages branch. Will do it now

@heidarsaleh
Copy link
Contributor Author

heidarsaleh commented May 5, 2017

done. Please let me know If I'm missing something

Copy link
Collaborator

@rovolution rovolution left a 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

@@ -1,308 +0,0 @@
/*! =======================================================
VERSION 9.8.0
Copy link
Collaborator

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

this._state.value[1] = this.options.ticks[this._getClosestTickIndex(this._state.value[1])];
}
} catch(err) {
console.error(err);
Copy link
Collaborator

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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice refactoring!! 👍

@@ -1682,28 +1691,29 @@ const windowIsDefined = (typeof window === "object");

return false;
},
_setValues: function(index, val) {
var comp = index === 0 ? 0 : 100;
Copy link
Collaborator

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

@@ -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]);
Copy link
Collaborator

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?

_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) {
Copy link
Collaborator

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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice test btw!

Copy link
Collaborator

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?

Copy link
Contributor Author

@heidarsaleh heidarsaleh left a 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.

@heidarsaleh
Copy link
Contributor Author

I rolled back the dist folder. Now codeclimate detect duplicate between the src and the dist. We need to ignore this error I think.

@rovolution
Copy link
Collaborator

rovolution commented May 8, 2017

Now codeclimate detect duplicate between the src and the dist

Don't worry too much about the codeclimate check...I'm more concerned with the Travis CI check (which looks like its passing)

@heidarsaleh
Copy link
Contributor Author

jsfiddle: https://jsfiddle.net/vk2q7rxb/

@heidarsaleh
Copy link
Contributor Author

Yep. Can you merge it now? I'd also be happy to work on other issues or planned features :)

@@ -1682,28 +1687,34 @@ const windowIsDefined = (typeof window === "object");

return false;
},
_setValues: function(index, val) {
let comp;
if(0 === index) {
Copy link
Collaborator

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;

Copy link
Collaborator

@rovolution rovolution left a 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

@@ -5,6 +5,7 @@
&.slider-horizontal {
width: $slider-horizontal-width;
height: $slider-line-height;
margin: 0 0 010px;
Copy link
Collaborator

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");
Copy link
Collaborator

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?

Copy link
Contributor Author

@heidarsaleh heidarsaleh left a comment

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@rovolution rovolution left a 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:
image
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

@rovolution
Copy link
Collaborator

@heidarsaleh did you get a chance to see my feedback? other than that, it looks great!

@heidarsaleh
Copy link
Contributor Author

Sorry I wasn't available the past few days. I'll fix it this weekend.

@rovolution
Copy link
Collaborator

@heidarsaleh no rush! whenever you get a chance

@rovolution
Copy link
Collaborator

@heidarsaleh any chance to look at my feedback? I would love to merge this in!

@rovolution
Copy link
Collaborator

@heidarsaleh any chance to check this out?

@heidarsaleh
Copy link
Contributor Author

I've checked it Today.This feature will require a lot of changes in different places. I'll try to fix it soon.

@neslinesli93
Copy link

any update on this?

@rovolution
Copy link
Collaborator

@heidarsaleh i know its been a while, but did you even get a chance to look at this again?

jespirit and others added 21 commits December 21, 2018 11:12
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()`.
var val;
if (this.ticksAreValid && this.options.lock_to_ticks) {
var index;
try {
Copy link
Collaborator

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.

@jespirit
Copy link
Collaborator

jespirit commented Jan 4, 2019

I decided to replace the try/catch block with an simple if statement and also prints a console warning.

I've manually tested the API examples and everything seems to work

@rovolution
Copy link
Collaborator

@jespirit does the keyboard stuff I mentioned in this comment work as well?

@jespirit
Copy link
Collaborator

jespirit commented Jan 4, 2019

@jespirit does the keyboard stuff I mentioned in this comment work as well?

Sure does!

@jespirit jespirit merged commit ccf5122 into seiyria:master Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants