luda
Version:
A library helps to build cross-framework UI components.
71 lines (49 loc) • 1.51 kB
text/coffeescript
import '../kernel/index.coffee'
import '../mixins/resetable.coffee'
luda.component 'fmFile'
.protect
selector:
root: '.fm-file'
file: 'input[type=file]'
simulator: 'input:not([type=file])'
evt:
changed: 'luda:fmFile:changed'
splitor: ' '
.protect
placeholder: -> .attr 'placeholder'
value: -> .attr 'value'
multiple: -> .prop 'multiple'
.protect
files: -> Array.from .prop('files')
insertSimulator: ->
return if .length
luda('<input>').prop('tabIndex', -1)
.attr('placeholder', )
.insertAfter( )
updateSimulatorValue: ->
values = .map (f) -> f.name
value = values.join( ) or or ''
.val value
updateValue: ->
oldFile =
=
return if not oldFile or luda.arrayEqual( , oldFile)
val = if then else [0]
.trigger .changed, val
tryReset: (target, oldVal) ->
return unless is ''
return if oldVal is ''
.prop('value', '').attr('value', oldVal or '')
.help
find: ->
file: .file
simulator: .simulator
watch: ->
attr: [['value', .file, , ]]
create: ->
listen: ->
luda.mixin('resetable').get('listen').call this,
[['change', .file, ]]