luda
Version:
A library helps to build cross-framework UI components.
118 lines (91 loc) • 2.64 kB
text/coffeescript
import '../kernel/index.coffee'
import '../mixins/tabable.coffee'
luda.component 'carousel'
.protect
cls:
tabable:
active: 'carousel-item-active'
indicatorActive: 'btn-active'
prev: 'carousel-item-prev'
next: 'carousel-item-next'
data:
interval: 'carousel-interval'
tabable:
interruption: 'data-carousel_interruption'
wrap: 'data-carousel-wrap'
default:
interval: 5000
tabable:
activeIndex: 0
wrap: true
evt:
tabable:
activate: 'luda:carousel:activate'
activated: 'luda:carousel:activated'
deactivate: 'luda:carousel:deactivate'
deactivated: 'luda:carousel:deactivated'
selector:
tabable:
targets: '.carousel-item'
indicators: '.carousel-indicators .btn'
prevCtrl: '.carousel-prev'
nextCtrl: '.carousel-next'
.protect
interval: ->
duration = .data .interval
return false if duration is false
Math.abs(parseInt duration, 10) or .interval
.include luda.mixin('tabable').alias(
activate: 'tabableActivate'
next: 'tabableNext'
prev: 'tabablePrev'
)
.include
pause: ->
return unless 'intervaling' of this
clearTimeout
delete
-= Date.now() -
= undefined if <= 10
=
play: ->
return if 'intervaling' of this
return unless
= Date.now()
= unless is
handler = =>
= Date.now()
=
= setTimeout handler,
= setTimeout handler,
.protect luda.mixin('tabable').all()
.protect
togglePath: (path, action) ->
targets = path.filter (el) => .contains el
.create(targets).forEach (ins) -> ins[action]()
pauseOnEvt: (e) -> e.eventPath(), 'pause'
playOnEvt: (e) -> e.eventPath(), 'play'
playOnTouchend: (e) ->
path = e.eventPath()
setTimeout => path, 'play'
.help
find: ->
create: ->
destroy: ->
watch: ->
watches =
watches.attr.push [ .interval, , ]
watches
listen: ->
.concat [
['swipeleft', ]
['swiperight', ]
['touchstart mouseover', ]
['mouseout', ]
['touchend', ]
]