coffeescript-ui
Version:
Coffeescript User Interface System
135 lines (112 loc) • 3.14 kB
text/coffeescript
CUI.Template.loadTemplateText(require('./Slider.html'));
class CUI.Slider extends CUI.DataField
initOpts: ->
super()
value:
check: (v) ->
CUI.util.isInteger(v)
min:
mandatory: true
default: 0
check: (v) ->
CUI.util.isInteger(v)
max:
mandatory: true
default: 100
check: (v) ->
CUI.util.isInteger(v)
onDragstart:
check: Function
onDragging:
check: Function
onDrop:
check: Function
onUpdate:
check: Function
readOpts: ->
super()
= -
CUI.util.assert( > 1, 'new CUI.Slider', 'opts.min and opts.max need to be at least 2 apart.')
=
getTemplate: ->
= new CUI.Template
name: "slider"
map:
track: true
track_visual: true
handle: true
initDimensions: ->
= CUI.dom.getDimensions()
= CUI.dom.getDimensions()
=
width: .contentBoxWidth - (.borderBoxWidth / 2)
height: .contentBoxHeight - (.borderBoxHeight / 2)
render: ->
super()
= .map.handle
= .map.track
new CUI.Draggable
element:
helper: null
dragstart: (ev, gd) =>
= 0
=
?(@, )
dragstop: =>
?(@)
dragend: =>
?(@)
dragging: (ev, gd) =>
diff_x = gd.dragDiff.bare_x -
= gd.dragDiff.bare_x
precision = .width /
precision_factor = (gd.dragDiff.bare_y / 5)
if precision_factor > 1
use_precision = Math.min(1, precision * precision_factor)
else
use_precision = precision
# console.debug diff_x, precision, precision_factor, use_precision
?(@, )
CUI.Events.listen
type: 'click'
node: .map.track_visual
call: (ev) =>
track_clientX = .clientBoundingRect.left
click_clientX = ev.getNativeEvent().clientX
return
getValue: ->
if
super()
else
getHandle: ->
.map.handle
setValue: (_v, flags={}) ->
v = Math.round(Math.min(Math.max(, _v), ))
= v
if flags.no_trigger == undefined
flags.no_trigger = false
super(, flags)
@
getDefaultValue: ->
if == undefined
# Math.round(( - ) / 2)
else
displayValue: ->
percent = / * 100
CUI.dom.setStyle(, left: percent + '%')
?(@, )
checkValue: (v, flags) ->
if v < or v >
throw new CUI.CheckValueError('value needs to be between '++' and '+)
@