You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/list/list_select.coffee

43 lines
923 B

class app.views.ListSelect extends app.View
@activeClass: 'active'
@events:
click: 'onClick'
constructor: (@el) -> super
deactivate: ->
@deselect() if super
return
select: (el) ->
@deselect()
if el
el.classList.add @constructor.activeClass
$.trigger el, 'select'
return
deselect: ->
if selection = @getSelection()
selection.classList.remove @constructor.activeClass
$.trigger selection, 'deselect'
return
selectByHref: (href) ->
unless @getSelection()?.getAttribute('href') is href
@select @find("a[href='#{href}']")
return
selectCurrent: ->
@selectByHref location.pathname + location.hash
return
getSelection: ->
@findByClass @constructor.activeClass
onClick: (event) =>
return if event.which isnt 1 or event.metaKey or event.ctrlKey
if event.target.tagName is 'A'
@select event.target
return