2013-07-10 18:20:10 +00:00
|
|
|
class Selector
|
|
|
|
constructor: (selector) ->
|
|
|
|
@input = $("#{selector}-input")
|
2013-07-10 19:16:26 +00:00
|
|
|
@dropdown = $("#{selector}-selector")
|
2013-07-10 18:20:10 +00:00
|
|
|
@placeholder = @dropdown.children 'span'
|
|
|
|
@prefix = @placeholder.text()
|
|
|
|
@options = @dropdown.find 'ul.dropdown > li'
|
|
|
|
this.initEvents()
|
|
|
|
|
|
|
|
initEvents: ->
|
|
|
|
self = this
|
|
|
|
|
|
|
|
@dropdown.on 'click', (e) ->
|
2013-07-12 07:34:38 +00:00
|
|
|
$(this).toggleClass('active') unless $(this).hasClass('disabled')
|
2013-07-10 18:20:10 +00:00
|
|
|
false
|
|
|
|
|
|
|
|
@options.on 'click', (e) ->
|
|
|
|
$el = $(this)
|
|
|
|
$el.siblings().removeClass 'selected'
|
|
|
|
$el.addClass 'selected'
|
|
|
|
self.placeholder.text "#{self.prefix}: #{$el.text()}"
|
|
|
|
self.setValue $el.data 'value'
|
2013-07-10 19:06:16 +00:00
|
|
|
$('textarea').focus()
|
2013-07-10 18:20:10 +00:00
|
|
|
|
|
|
|
@options.filter('.selected').click()
|
|
|
|
@dropdown.removeClass 'active'
|
|
|
|
|
|
|
|
setValue: (value) ->
|
|
|
|
@input.val value
|
|
|
|
|
|
|
|
$ ->
|
2013-07-10 19:16:26 +00:00
|
|
|
new Selector '#syntax'
|
2013-07-10 18:20:10 +00:00
|
|
|
$(document).on 'click', (e) ->
|
|
|
|
$('.wrapper-dropdown').removeClass 'active'
|