travis-web/app/components/travis-switch.coffee
2015-03-24 15:01:18 +01:00

26 lines
683 B
CoffeeScript

`import Ember from 'ember'`
Component = Ember.Component.extend
tagName: 'a'
classNames: ['travis-switch', 'switch']
classNameBindings: ['_active:active']
# TODO: how to handle overriding properties to
# avoid naming it _action?
_active: (->
@get('target.active') || @get('active')
).property('target.active', 'active')
click: ->
target = @get('target')
if @get('toggleAutomatically') != 'false'
if target
@set('target.active', !@get('target.active'))
else
@set('active', !@get('active'))
# allow for bindings to propagate
Ember.run.next this, ->
@sendAction('action', target)
`export default Component`