@@ -16,9 +16,8 @@ gap = (element1, element2) ->
1616 offsetLeft (element2) - offsetLeft (element1) - width (element1)
1717
1818contain = (value ) ->
19- if value % 1 is 0
20- Math .min Math .max (0 , value), 100
21- else value
19+ return value if isNaN value
20+ Math .min Math .max (0 , value), 100
2221
2322roundStep = (value , precision , step , floor = 0 ) ->
2423 step ?= 1 / Math .pow (10 , precision)
@@ -31,7 +30,7 @@ roundStep = (value, precision, step, floor = 0) ->
3130 roundedValue = steppedValue * decimals / decimals
3231 parseFloat roundedValue .toFixed precision
3332
34- inputEvents =
33+ events =
3534 mouse :
3635 start : ' mousedown'
3736 move : ' mousemove'
@@ -90,7 +89,7 @@ sliderDirective = ($timeout) ->
9089 scope .local [low] = scope[low]
9190 scope .local [high] = scope[high]
9291
93- boundToInputs = false
92+ bound = false
9493 ngDocument = angularize document
9594 handleHalfWidth = barWidth = minOffset = maxOffset = minValue = maxValue = valueRange = offsetRange = undefined
9695
@@ -129,28 +128,28 @@ sliderDirective = ($timeout) ->
129128 # Translation functions
130129 percentOffset = (offset ) -> contain ((offset - minOffset) / offsetRange) * 100
131130 percentValue = (value ) -> contain ((value - minValue) / valueRange) * 100
132- percentToOffset = (percent ) -> contain pixelize percent * offsetRange / 100
131+ pixelsToOffset = (percent ) -> pixelize percent * offsetRange / 100
133132
134133 setPointers = ->
135134 offset ceilBub, pixelize (barWidth - width (ceilBub))
136135 newLowValue = percentValue scope .local [low]
137- offset minPtr, percentToOffset newLowValue
136+ offset minPtr, pixelsToOffset newLowValue
138137 offset lowBub, pixelize (offsetLeft (minPtr) - (halfWidth lowBub) + handleHalfWidth)
139138 offset selection, pixelize (offsetLeft (minPtr) + handleHalfWidth)
140139
141140 switch true
142141 when range
143142 newHighValue = percentValue scope .local [high]
144- offset maxPtr, percentToOffset newHighValue
143+ offset maxPtr, pixelsToOffset newHighValue
145144 offset highBub, pixelize (offsetLeft (maxPtr) - (halfWidth highBub) + handleHalfWidth)
146- selection .css width : percentToOffset newHighValue - newLowValue
145+ selection .css width : pixelsToOffset newHighValue - newLowValue
147146 when attributes .highlight is ' right'
148- selection .css width : percentToOffset 110 - newLowValue
147+ selection .css width : pixelsToOffset 110 - newLowValue
149148 when attributes .highlight is ' left'
150- selection .css width : percentToOffset newLowValue
149+ selection .css width : pixelsToOffset newLowValue
151150 offset selection, 0
152151
153- bindToInputEvents = (handle , bubble , ref , events ) ->
152+ bind = (handle , bubble , ref , events ) ->
154153 currentRef = ref
155154 onEnd = ->
156155 bubble .removeClass ' active'
@@ -163,7 +162,7 @@ sliderDirective = ($timeout) ->
163162 currentRef = ref
164163 scope .$apply ()
165164 onMove = (event ) ->
166- eventX = event .clientX || event .touches ? [0 ]? .clientX || 0
165+ eventX = event .clientX or event .touches ? [0 ]? .clientX or 0
167166 newOffset = eventX - element[0 ].getBoundingClientRect ().left - handleHalfWidth
168167 newOffset = Math .max (Math .min (newOffset, maxOffset), minOffset)
169168 newPercent = percentOffset newOffset
@@ -211,13 +210,12 @@ sliderDirective = ($timeout) ->
211210 handle .bind events .start , onStart
212211
213212 setBindings = ->
214- boundToInputs = true
215- bind = (method ) ->
216- bindToInputEvents minPtr, lowBub, low, inputEvents[method]
217- bindToInputEvents maxPtr, highBub, high, inputEvents[method]
218- bind (inputMethod) for inputMethod in [' touch' , ' mouse' ]
213+ for method in [' touch' , ' mouse' ]
214+ bind minPtr, lowBub, low, events[method]
215+ bind maxPtr, highBub, high, events[method]
216+ bound = true
219217
220- setBindings () unless boundToInputs
218+ setBindings () unless bound
221219 setPointers ()
222220
223221 $timeout updateDOM
0 commit comments