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

Feature : rtl mode (with options) #679

Merged
merged 7 commits into from
Jan 4, 2017
Merged

Conversation

Shnoulle
Copy link
Contributor

@Shnoulle Shnoulle commented Dec 30, 2016

Pull Requests

Feedback

  • rewrite using ES6 template string
  • refactor imbricated ternary test
  • RtlOptionsSpec unit test

- [x] Add a rtl option (default false)
- [x] Set inlined style according to this option
- [x] Add slider-rtl class to wrapper ( slider (slider-horizontal|slider-vertical)
- [x] Fix css file according top this class
- [x] Set rtl mode automatic according to dir="rtl"
[x] documentation updates to README file
[x] examples within [/tpl/index.tpl](https://github.com/seiyria/bootstrap-slider/blob/master/tpl/index.tpl)
@seiyria
Copy link
Owner

seiyria commented Dec 30, 2016

Definitely a good start, however:

  • It needs to pass our unit tests
  • You need to add some unit tests to this

@Shnoulle
Copy link
Contributor Author

OK, units test passed (and errors fixed)

2 questions

  1. About 'default' : rtl : bool|null : null (or not set) => default ?
  2. Unit test : only some ? Add one rtl (forced) everywhere ?

@seiyria
Copy link
Owner

seiyria commented Dec 30, 2016

not set is a fine default since it's falsy. as for unit tests, you'd have to ask @rovolution specifically on what he'd like to see with unit tests.

@@ -384,16 +384,23 @@ const windowIsDefined = (typeof window === "object");
this.options[optName] = val;
}

// Check options.rtl
if(this.options.rtl==='auto'){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternative

			if (this.options.rtl === null) {
				this.options.rtl = window.getComputedStyle(this.element).direction === 'rtl';
			}

@@ -829,6 +848,7 @@ const windowIsDefined = (typeof window === "object");
tooltip_split: false,
handle: 'round',
reversed: false,
rtl: 'auto',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alt : rtl: null,

@Shnoulle
Copy link
Contributor Author

Shnoulle commented Dec 30, 2016

About 'default' : currently bool|string => string==='default' use dir='rtl'.

But null!==false see 6dadef3#r94231462

Else, bout unit test : 2 solutions : add some rtl=true in some of existing tests, or add a new global test RtlOptionsSpec. Wait for @rovolution :)

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.

@Shnoulle Thanks for taking time to submit a PR! It looks great for the most part! I left some specific feedback in the code, so if you could take some time to incorporate that in, it would be much appreciated!

1) I would like to see some unit tests for this new option to validate that it effects the slider in the desired way based upon what value it is set to.

2) Go ahead and create a new spec file (something like RtlOptionsSpec) to contain the tests for this particular feature.

@@ -1196,7 +1216,11 @@ const windowIsDefined = (typeof window === "object");
this.rangeHighlightElements[i].style.top = `${currentRange.start}%`;
this.rangeHighlightElements[i].style.height = `${currentRange.size}%`;
} else {
this.rangeHighlightElements[i].style.left = `${currentRange.start}%`;
if(this.options.rtl){
this.rangeHighlightElements[i].style.right = currentRange.start + "%";
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 rewrite this using an ES6 template string?

this.rangeHighlightElements[i].style.right = `${currentRange.start}%`;

if(this.options.rtl){
this.rangeHighlightElements[i].style.right = currentRange.start + "%";
} else {
this.rangeHighlightElements[i].style.left = currentRange.start + "%";
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 rewrite this using an ES6 template string?

@@ -1209,7 +1233,7 @@ const windowIsDefined = (typeof window === "object");
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {

var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : (this.options.rtl ? 'marginRight' : 'marginLeft');
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of doing nested ternary (which is a little difficult to read), could you just re-write the assignment of this variable to use an if...else?

var styleMargin;

if (this.options.orientation === 'vertical') {
  styleMargin = 'marginTop';
}
else if (this.options.rtl) {
  styleMargin = 'marginRight';
}
else {
  styleMargin = 'marginLeft';
}

this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
if(this.options.rtl){
this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + 'px';
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 rewrite this using an ES6 template string?

if(this.options.rtl){
this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + 'px';
}else{
this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
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 rewrite this using an ES6 template string?

@@ -1299,15 +1327,15 @@ const windowIsDefined = (typeof window === "object");
if (this.options.orientation === 'vertical') {
this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
} else {
this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
this._css(this.tooltip_min, 'margin-'+this.stylePos, -this.tooltip_min.offsetWidth / 2 + 'px');
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 rewrite this using an ES6 template string?

`margin-${this.stylePos}`

}

if (this.options.orientation === 'vertical') {
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
} else {
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px');
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 rewrite this using an ES6 template string?

`margin-${this.stylePos}`

@@ -1279,13 +1307,13 @@ const windowIsDefined = (typeof window === "object");
if (this.options.orientation === 'vertical') {
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
} else {
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px');
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 rewrite this using an ES6 template string?

`margin-${this.stylePos}`

@@ -1317,7 +1345,7 @@ const windowIsDefined = (typeof window === "object");
if (this.options.orientation === 'vertical') {
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
} else {
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px');
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 rewrite this using an ES6 template string?

`margin-${this.stylePos}`

@@ -1804,7 +1851,7 @@ const windowIsDefined = (typeof window === "object");
_setTooltipPosition: function(){
var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
if (this.options.orientation === 'vertical'){
var tooltipPos = this.options.tooltip_position || 'right';
var tooltipPos = this.options.tooltip_position || (this.options.rtl ? 'left' : 'right');
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 refactor this to an if..else since the logic to determine the variable's value is a little more complex?

var tooltipPos;

if (this.options.tooltip_position) {
  tooltipPos = this.options.tooltip_position;
}
else if (this.options.rtl) {
  tooltipPos = 'left';  
}
else {
  tooltipPos = 'right';
}

@Shnoulle
Copy link
Contributor Author

Shnoulle commented Jan 3, 2017

@rovolution : thanks for reviewing :) 😃 . Maybe about RtlOptionsSpec i need your help after .

I hope to work on it before end of the week :).

And thanks a lot for this repo

- [x] rewrite using ES6 template string
- [x] refactor imbricated ternary test
- [x] RtlOptionsSpec unit test
@Shnoulle
Copy link
Contributor Author

Shnoulle commented Jan 4, 2017

  • rewrite using ES6 template string
  • refactor imbricated ternary test
  • RtlOptionsSpec unit test

Attention : using rtl : 'auto' by default update API (different behaviour in a rtl page) then can make it to false by default then don't break API

expect(dirIsRtl).toBeTruthy();
});

it("slider use inversed left and right inline style", function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

great tests!!!!

@rovolution
Copy link
Collaborator

Just pulled down and ran locally and everything works great! merging now. Thanks again for this awesome PR! Will be available in v9.6.0 once I merged/publish to NPM

@rovolution rovolution merged commit 38fd966 into seiyria:master Jan 4, 2017
@rovolution
Copy link
Collaborator

merged and published to NPM at v9.6.0

@Shnoulle
Copy link
Contributor Author

Shnoulle commented Jan 4, 2017

Thanks to you :)

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