Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
i20rzslider
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jedife
i20rzslider
Commits
1714aeae
Commit
1714aeae
authored
May 22, 2016
by
Valentin Hervieu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #333 from angular-slider/maxRange-option
feat(maxRange): Add a maxRange option
parents
2d346ff6
27645e44
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
221 additions
and
36 deletions
+221
-36
README.md
README.md
+6
-3
demo.js
demo/demo.js
+7
-6
index.html
demo/index.html
+4
-4
rzslider.js
dist/rzslider.js
+19
-11
rzslider.min.js
dist/rzslider.min.js
+1
-1
rzslider.js
src/rzslider.js
+19
-11
specific-test.js
tests/specs/keyboard-controls/specific-test.js
+96
-0
minMaxRange-noSwitching-range-slider-horizontal-test.js
...s/minMaxRange-noSwitching-range-slider-horizontal-test.js
+0
-0
minMaxRange-range-slider-horizontal-test.js
...ouse-controls/minMaxRange-range-slider-horizontal-test.js
+69
-0
No files found.
README.md
View file @
1714aeae
...
...
@@ -186,9 +186,10 @@ The default options are:
ceil
:
null
,
//defaults to rz-slider-model
step
:
1
,
precision
:
0
,
minRange
:
0
,
minLimit
:
null
,
maxLimit
:
null
,
minRange
:
null
,
maxRange
:
null
,
id
:
null
,
translate
:
null
,
getLegend
:
null
,
...
...
@@ -231,12 +232,14 @@ The default options are:
**precision** - _Number (defaults to 0)_: The precision to display values with. The `
toFixed()
` is used internally for this.
**minRange** - _Number (defaults to 0)_: The minimum range authorized on the slider. *Applies to range slider only.*
**minLimit** - _Number (defaults to null)_: The minimum value authorized on the slider.
**maxLimit** - _Number (defaults to null)_: The maximum value authorized on the slider.
**minRange** - _Number (defaults to null)_: The minimum range authorized on the slider. *Applies to range slider only.*
**maxRange** - _Number (defaults to null)_: The minimum range authorized on the slider. *Applies to range slider only.*
**translate** - _Function(value, sliderId, label)_: Custom translate function. Use this if you want to translate values displayed on the slider.
`
sliderId
` can be used to determine the slider for which we are translating the value. `
label
` is a string that can take the following values:
- *'model'*: the model label
...
...
demo/demo.js
View file @
1714aeae
...
...
@@ -17,7 +17,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
}
};
//Range slider with min
Range
config
//Range slider with min
Limit and maxLimit
config
$scope
.
minMaxLimitSlider
=
{
value
:
50
,
options
:
{
...
...
@@ -29,15 +29,16 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
}
};
//Range slider with minRange config
$scope
.
minRangeSlider
=
{
minValue
:
1
0
,
maxValue
:
9
0
,
//Range slider with minRange
and maxRange
config
$scope
.
min
Max
RangeSlider
=
{
minValue
:
4
0
,
maxValue
:
6
0
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
,
minRange
:
10
minRange
:
10
,
maxRange
:
50
}
};
...
...
demo/index.html
View file @
1714aeae
...
...
@@ -45,11 +45,11 @@
</article>
<article>
<h2>
Range slider with minimum range of 10
</h2>
<h2>
Range slider with minimum range of 10
and maximum of 50
</h2>
<rzslider
rz-slider-model=
"minRangeSlider.minValue"
rz-slider-high=
"minRangeSlider.maxValue"
rz-slider-options=
"minRangeSlider.options"
rz-slider-model=
"min
Max
RangeSlider.minValue"
rz-slider-high=
"min
Max
RangeSlider.maxValue"
rz-slider-options=
"min
Max
RangeSlider.options"
></rzslider>
</article>
...
...
dist/rzslider.js
View file @
1714aeae
...
...
@@ -31,7 +31,8 @@
ceil
:
null
,
//defaults to rz-slider-model
step
:
1
,
precision
:
0
,
minRange
:
0
,
minRange
:
null
,
maxRange
:
null
,
minLimit
:
null
,
maxLimit
:
null
,
id
:
null
,
...
...
@@ -1758,11 +1759,11 @@
newValue
=
this
.
applyMinMaxLimit
(
newValue
);
if
(
this
.
range
)
{
newValue
=
this
.
applyMinRange
(
newValue
);
newValue
=
this
.
applyMin
Max
Range
(
newValue
);
/* This is to check if we need to switch the min and max handles */
if
(
this
.
tracking
===
'rzSliderModel'
&&
newValue
>
this
.
scope
.
rzSliderHigh
)
{
if
(
this
.
options
.
noSwitching
&&
this
.
scope
.
rzSliderHigh
!==
this
.
minValue
)
{
newValue
=
this
.
applyMinRange
(
this
.
scope
.
rzSliderHigh
);
newValue
=
this
.
applyMin
Max
Range
(
this
.
scope
.
rzSliderHigh
);
}
else
{
this
.
scope
[
this
.
tracking
]
=
this
.
scope
.
rzSliderHigh
;
...
...
@@ -1777,7 +1778,7 @@
valueChanged
=
true
;
}
else
if
(
this
.
tracking
===
'rzSliderHigh'
&&
newValue
<
this
.
scope
.
rzSliderModel
)
{
if
(
this
.
options
.
noSwitching
&&
this
.
scope
.
rzSliderModel
!==
this
.
maxValue
)
{
newValue
=
this
.
applyMinRange
(
this
.
scope
.
rzSliderModel
);
newValue
=
this
.
applyMin
Max
Range
(
this
.
scope
.
rzSliderModel
);
}
else
{
this
.
scope
[
this
.
tracking
]
=
this
.
scope
.
rzSliderModel
;
...
...
@@ -1806,17 +1807,16 @@
applyMinMaxLimit
:
function
(
newValue
)
{
if
(
this
.
options
.
minLimit
!=
null
&&
newValue
<
this
.
options
.
minLimit
)
return
this
.
options
.
minLimit
return
this
.
options
.
minLimit
;
if
(
this
.
options
.
maxLimit
!=
null
&&
newValue
>
this
.
options
.
maxLimit
)
return
this
.
options
.
maxLimit
return
this
.
options
.
maxLimit
;
return
newValue
;
},
applyMinRange
:
function
(
newValue
)
{
if
(
this
.
options
.
minRange
!==
0
)
{
var
oppositeValue
=
this
.
tracking
===
'rzSliderModel'
?
this
.
scope
.
rzSliderHigh
:
this
.
scope
.
rzSliderModel
,
difference
=
Math
.
abs
(
newValue
-
oppositeValue
);
applyMinMaxRange
:
function
(
newValue
)
{
var
oppositeValue
=
this
.
tracking
===
'rzSliderModel'
?
this
.
scope
.
rzSliderHigh
:
this
.
scope
.
rzSliderModel
,
difference
=
Math
.
abs
(
newValue
-
oppositeValue
);
if
(
this
.
options
.
minRange
!=
null
)
{
if
(
difference
<
this
.
options
.
minRange
)
{
if
(
this
.
tracking
===
'rzSliderModel'
)
return
this
.
scope
.
rzSliderHigh
-
this
.
options
.
minRange
;
...
...
@@ -1824,6 +1824,14 @@
return
this
.
scope
.
rzSliderModel
+
this
.
options
.
minRange
;
}
}
if
(
this
.
options
.
maxRange
!=
null
)
{
if
(
difference
>
this
.
options
.
maxRange
)
{
if
(
this
.
tracking
===
'rzSliderModel'
)
return
this
.
scope
.
rzSliderHigh
-
this
.
options
.
maxRange
;
else
return
this
.
scope
.
rzSliderModel
+
this
.
options
.
maxRange
;
}
}
return
newValue
;
},
...
...
dist/rzslider.min.js
View file @
1714aeae
This diff is collapsed.
Click to expand it.
src/rzslider.js
View file @
1714aeae
...
...
@@ -35,7 +35,8 @@
ceil
:
null
,
//defaults to rz-slider-model
step
:
1
,
precision
:
0
,
minRange
:
0
,
minRange
:
null
,
maxRange
:
null
,
minLimit
:
null
,
maxLimit
:
null
,
id
:
null
,
...
...
@@ -1762,11 +1763,11 @@
newValue
=
this
.
applyMinMaxLimit
(
newValue
);
if
(
this
.
range
)
{
newValue
=
this
.
applyMinRange
(
newValue
);
newValue
=
this
.
applyMin
Max
Range
(
newValue
);
/* This is to check if we need to switch the min and max handles */
if
(
this
.
tracking
===
'rzSliderModel'
&&
newValue
>
this
.
scope
.
rzSliderHigh
)
{
if
(
this
.
options
.
noSwitching
&&
this
.
scope
.
rzSliderHigh
!==
this
.
minValue
)
{
newValue
=
this
.
applyMinRange
(
this
.
scope
.
rzSliderHigh
);
newValue
=
this
.
applyMin
Max
Range
(
this
.
scope
.
rzSliderHigh
);
}
else
{
this
.
scope
[
this
.
tracking
]
=
this
.
scope
.
rzSliderHigh
;
...
...
@@ -1781,7 +1782,7 @@
valueChanged
=
true
;
}
else
if
(
this
.
tracking
===
'rzSliderHigh'
&&
newValue
<
this
.
scope
.
rzSliderModel
)
{
if
(
this
.
options
.
noSwitching
&&
this
.
scope
.
rzSliderModel
!==
this
.
maxValue
)
{
newValue
=
this
.
applyMinRange
(
this
.
scope
.
rzSliderModel
);
newValue
=
this
.
applyMin
Max
Range
(
this
.
scope
.
rzSliderModel
);
}
else
{
this
.
scope
[
this
.
tracking
]
=
this
.
scope
.
rzSliderModel
;
...
...
@@ -1810,17 +1811,16 @@
applyMinMaxLimit
:
function
(
newValue
)
{
if
(
this
.
options
.
minLimit
!=
null
&&
newValue
<
this
.
options
.
minLimit
)
return
this
.
options
.
minLimit
return
this
.
options
.
minLimit
;
if
(
this
.
options
.
maxLimit
!=
null
&&
newValue
>
this
.
options
.
maxLimit
)
return
this
.
options
.
maxLimit
return
this
.
options
.
maxLimit
;
return
newValue
;
},
applyMinRange
:
function
(
newValue
)
{
if
(
this
.
options
.
minRange
!==
0
)
{
var
oppositeValue
=
this
.
tracking
===
'rzSliderModel'
?
this
.
scope
.
rzSliderHigh
:
this
.
scope
.
rzSliderModel
,
difference
=
Math
.
abs
(
newValue
-
oppositeValue
);
applyMinMaxRange
:
function
(
newValue
)
{
var
oppositeValue
=
this
.
tracking
===
'rzSliderModel'
?
this
.
scope
.
rzSliderHigh
:
this
.
scope
.
rzSliderModel
,
difference
=
Math
.
abs
(
newValue
-
oppositeValue
);
if
(
this
.
options
.
minRange
!=
null
)
{
if
(
difference
<
this
.
options
.
minRange
)
{
if
(
this
.
tracking
===
'rzSliderModel'
)
return
this
.
scope
.
rzSliderHigh
-
this
.
options
.
minRange
;
...
...
@@ -1828,6 +1828,14 @@
return
this
.
scope
.
rzSliderModel
+
this
.
options
.
minRange
;
}
}
if
(
this
.
options
.
maxRange
!=
null
)
{
if
(
difference
>
this
.
options
.
maxRange
)
{
if
(
this
.
tracking
===
'rzSliderModel'
)
return
this
.
scope
.
rzSliderHigh
-
this
.
options
.
maxRange
;
else
return
this
.
scope
.
rzSliderModel
+
this
.
options
.
maxRange
;
}
}
return
newValue
;
},
...
...
tests/specs/keyboard-controls/specific-test.js
View file @
1714aeae
...
...
@@ -127,6 +127,53 @@
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
56
);
});
it
(
'should not be modified by keyboard if new range is above maxRange'
,
function
()
{
var
sliderConf
=
{
min
:
45
,
max
:
55
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
,
maxRange
:
10
}
};
helper
.
createRangeSlider
(
sliderConf
);
//try to move minH left
helper
.
slider
.
minH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'LEFT'
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
45
);
//try to move maxH right
helper
.
slider
.
maxH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
maxH
,
'RIGHT'
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
55
);
});
it
(
'should be modified by keyboard if new range is below maxRange'
,
function
()
{
var
sliderConf
=
{
min
:
45
,
max
:
55
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
,
maxRange
:
10
}
};
helper
.
createRangeSlider
(
sliderConf
);
//try to move minH right
helper
.
slider
.
minH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'RIGHT'
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
46
);
//try to move maxH left
helper
.
slider
.
maxH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
maxH
,
'LEFT'
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
54
);
});
it
(
'should be modified by keyboard if new value is above minLimit'
,
function
()
{
var
sliderConf
=
{
value
:
10
,
...
...
@@ -327,6 +374,55 @@
helper
.
pressKeydown
(
helper
.
slider
.
maxH
,
'LEFT'
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
56
);
});
it
(
'should not be modified by keyboard if new range is above maxRange'
,
function
()
{
var
sliderConf
=
{
min
:
45
,
max
:
55
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
,
maxRange
:
10
,
rightToLeft
:
true
}
};
helper
.
createRangeSlider
(
sliderConf
);
//try to move minH right ( increase in rtl )
helper
.
slider
.
minH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'RIGHT'
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
45
);
//try to move maxH left (decrease in rtl )
helper
.
slider
.
maxH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
maxH
,
'LEFT'
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
55
);
});
it
(
'should be modified by keyboard if new range is below maxRange'
,
function
()
{
var
sliderConf
=
{
min
:
45
,
max
:
55
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
1
,
maxRange
:
10
,
rightToLeft
:
true
}
};
helper
.
createRangeSlider
(
sliderConf
);
//try to move minH LEFT
helper
.
slider
.
minH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
minH
,
'LEFT'
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
46
);
//try to move maxH RIGHT
helper
.
slider
.
maxH
.
triggerHandler
(
'focus'
);
helper
.
pressKeydown
(
helper
.
slider
.
maxH
,
'RIGHT'
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
54
);
});
});
}());
tests/specs/mouse-controls/minRange-noSwitching-range-slider-horizontal-test.js
→
tests/specs/mouse-controls/min
Max
Range-noSwitching-range-slider-horizontal-test.js
View file @
1714aeae
File moved
tests/specs/mouse-controls/minRange-range-slider-horizontal-test.js
→
tests/specs/mouse-controls/min
Max
Range-range-slider-horizontal-test.js
View file @
1714aeae
...
...
@@ -88,6 +88,75 @@
});
});
describe
(
'Mouse controls - maxRange!=0 Range Horizontal'
,
function
()
{
var
helper
,
RzSliderOptions
,
$rootScope
,
$timeout
;
beforeEach
(
module
(
'test-helper'
));
beforeEach
(
inject
(
function
(
TestHelper
,
_RzSliderOptions_
,
_$rootScope_
,
_$timeout_
)
{
helper
=
TestHelper
;
RzSliderOptions
=
_RzSliderOptions_
;
$rootScope
=
_$rootScope_
;
$timeout
=
_$timeout_
;
}));
afterEach
(
function
()
{
helper
.
clean
();
});
beforeEach
(
function
()
{
var
sliderConf
=
{
min
:
45
,
max
:
55
,
options
:
{
floor
:
0
,
ceil
:
100
,
maxRange
:
10
}
};
helper
.
createRangeSlider
(
sliderConf
);
});
afterEach
(
function
()
{
// to clean document listener
helper
.
fireMouseup
();
});
it
(
'should not modify any value if new range would be larger than maxRange when moving minH'
,
function
()
{
helper
.
fireMousedown
(
helper
.
slider
.
minH
,
0
);
var
expectedValue
=
30
,
offset
=
helper
.
slider
.
valueToOffset
(
expectedValue
)
+
helper
.
slider
.
handleHalfDim
+
helper
.
slider
.
sliderElem
.
rzsp
;
helper
.
fireMousemove
(
offset
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
45
);
});
it
(
'should not modify any value if new range would be larger than maxRange when moving maxH'
,
function
()
{
helper
.
fireMousedown
(
helper
.
slider
.
maxH
,
0
);
var
expectedValue
=
70
,
offset
=
helper
.
slider
.
valueToOffset
(
expectedValue
)
+
helper
.
slider
.
handleHalfDim
+
helper
.
slider
.
sliderElem
.
rzsp
;
helper
.
fireMousemove
(
offset
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
55
);
});
it
(
'should modify the min value if new range is smaller than maxRange when moving minH'
,
function
()
{
helper
.
fireMousedown
(
helper
.
slider
.
minH
,
0
);
var
expectedValue
=
50
,
offset
=
helper
.
slider
.
valueToOffset
(
expectedValue
)
+
helper
.
slider
.
handleHalfDim
+
helper
.
slider
.
sliderElem
.
rzsp
;
helper
.
fireMousemove
(
offset
);
expect
(
helper
.
scope
.
slider
.
min
).
to
.
equal
(
expectedValue
);
});
it
(
'should modify the max value if new range is smaller than than maxRange when moving maxH'
,
function
()
{
helper
.
fireMousedown
(
helper
.
slider
.
maxH
,
0
);
var
expectedValue
=
50
,
offset
=
helper
.
slider
.
valueToOffset
(
expectedValue
)
+
helper
.
slider
.
handleHalfDim
+
helper
.
slider
.
sliderElem
.
rzsp
;
helper
.
fireMousemove
(
offset
);
expect
(
helper
.
scope
.
slider
.
max
).
to
.
equal
(
expectedValue
);
});
});
describe
(
'Right to left Mouse controls - minRange!=0 Range Horizontal'
,
function
()
{
var
helper
,
RzSliderOptions
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment