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

Slider: bugfix and improving implements #4678

Merged
merged 15 commits into from
Jan 12, 2017
Merged

Conversation

flytreeleft
Copy link

@flytreeleft flytreeleft commented Oct 22, 2016

There are following changes:

  • Code cleaning and format;
  • Add slider container padding when locating labels;
  • Use css function calc() to locate thumb, track fill and labels, so no need to listen resize event or observe element changes;
  • Extra parameter thumbVal, secondThumbVal for listener onChange() and onMove();
  • Exactly updating global variables value, module.thumbVal, module.secondThumbVal, position and secondPos;
  • Set or update value to min or max when mouse is moving out slider;

@flytreeleft flytreeleft mentioned this pull request Oct 22, 2016
@bdaunton
Copy link
Contributor

bdaunton commented Oct 22, 2016

Found a bit of an issue when I set the min to something other then 0
untitled

:
module.is.reversed() ? 'right' : 'left'
$label = $('<li class="label">' + module.get.label(i) + '</li>'),
ratio = i / (len + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't quite right. If I have a max of 10 and a min of 0, I am going to have 8 labels. So this would be 1/9 not 1/10 as it should be.

With the change to module.get.numLables(): i / (len + 1) -> i / len

$labels = $module.append('<ul class="auto labels"></ul>').find('.labels');
for(var i = 0; i <= module.get.numLabels(); i++) {
}
for(var i = 1, len = module.get.numLabels(); i <= len; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i <= len -> i < len to go along with the change in module.get.numLables():

var value = Math.round((module.get.max() - module.get.min()) / module.get.step()) - 2;

should now be

var value = Math.round((module.get.max() - module.get.min()) / module.get.step());

;
$children.each(function(index) {
var
$child = $(this),
$child = $(this),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need for more whitespace

@flytreeleft
Copy link
Author

@gdaunton Thanks, all known issues are already fixed. :)

@bdaunton
Copy link
Contributor

bdaunton commented Nov 2, 2016

Found an issue with the double handle:
i1rjll3hrc

It works fine after I grab the second handle.

This is not an issue on the vertical variant for some reason.

@bdaunton
Copy link
Contributor

bdaunton commented Nov 2, 2016

Really love the calc solution on this 👍 .

I think it is a tiny bit slower, but it does get rid of the positioning issues when the slider width changes.

Thanks for the help!

Copy link
Contributor

@bdaunton bdaunton left a comment

Choose a reason for hiding this comment

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

A few things that need to be removed thanks to the awesome calc solution. Other then that LGTM! 🎉

@@ -122,7 +122,7 @@ $.fn.slider = function(parameters) {
module.unbind.events();
module.unbind.slidingEvents();
$module.removeData(moduleNamespace);
module.disconnect.sliderObserver();
// module.disconnect.sliderObserver();
Copy link
Contributor

Choose a reason for hiding this comment

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

Go ahead and remove this line and function if it is no longer used

Copy link
Contributor

Choose a reason for hiding this comment

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

Also you can probably remove the resize listener

@@ -244,7 +243,7 @@ $.fn.slider = function(parameters) {
bind: {
events: function() {
module.bind.globalKeyboardEvents();
module.bind.resizeListener();
// module.bind.resizeListener();
Copy link
Contributor

Choose a reason for hiding this comment

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

🔪

@@ -309,7 +308,7 @@ $.fn.slider = function(parameters) {
$module.off('touchstart' + eventNamespace);
$module.off('keydown' + eventNamespace);
$module.off('focusout' + eventNamespace);
$(window).off('resize' + eventNamespace);
// $(window).off('resize' + eventNamespace);
Copy link
Contributor

Choose a reason for hiding this comment

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

🔪

@@ -103,9 +103,9 @@ $.fn.slider = function(parameters) {
module.read.metadata();
module.read.settings();

module.observeChanges();
// module.observeChanges();
Copy link
Contributor

Choose a reason for hiding this comment

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

🔪

@@ -138,6 +138,9 @@ $.fn.slider = function(parameters) {
slider: function() {
sliderObserver.observe($module[0], {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to have an observer? I can't think of anything in the class or style that would change where we would need to re-sync everything as all the positioning is percentage based.

transform: translateX(-50%);
}

.ui.labeled.vertical.slider > .labels .label {
transform: translate(-100%, -@labelWidth);
transform: translate(-100%, -50%); // translate(-100%, -@labelWidth);
Copy link
Contributor

Choose a reason for hiding this comment

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

you can 🔪 the comment

@flytreeleft
Copy link
Author

@gdaunton The commented codes are all removed.

And, I create a demo which can be used to test new changes. The issue you mentioned should already be fixed in previous submits :)

@jlukic jlukic merged commit 5ab148c into Semantic-Org:slider Jan 12, 2017
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.

3 participants