luda
Version:
A library helps to build cross-framework UI components.
88 lines (67 loc) • 1.78 kB
text/coffeescript
import '../kernel/index.coffee'
import '../mixins/toggleable.coffee'
luda.component 'toggle', '[data-toggle-target]'
.protect
cls:
toggleable:
active: 'toggle-active'
data:
target: 'data-toggle-target'
for: 'data-toggle-for'
auto: 'data-toggle-auto-deactivate'
toggleable:
interruption: 'data-toggle_interruption'
trigger: 'data-toggleable'
default:
autoDuration: 3000
evt:
toggleable:
activate: 'luda:toggle:activate'
activated: 'luda:toggle:activated'
deactivate: 'luda:toggle:deactivate'
deactivated: 'luda:toggle:deactivated'
.include
activate: ->
return unless
deactivate: ->
return unless
toggle: (force) ->
return unless force
.protect luda.mixin('toggleable').all()
.protect
toggleAutoState: ->
return unless .hasData .auto
if
= setTimeout =>
delete
, .data( .auto) or .autoDuration
else
clearTimeout
delete
toggleOnEvent: (e) ->
return unless
.help
find: ->
create: ->
destroy: ->
'auto' of this and clearTimeout
listen: ->
self = this
[
['click', ]
['click', "[#{@data.for}]", (e) ->
name = luda(this).data self.data.for
self.con.each (ins) ->
return unless ins.root.data(self.data.target) is name
ins.toggleOnEvent(e)
true
]
]