mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2025-01-03 08:58:32 +00:00
5bbe456496
We do not need to listen for keydown and keypress for inputHelper because these events will propagate through the parent. Listening them will be redundant and will cause some shortcut key combinations to stop working. Since we now have a hidden `textarea`, there is no longer need to set anything to contentEditable
37 lines
875 B
CoffeeScript
37 lines
875 B
CoffeeScript
|
|
class Popup
|
|
constructor: ->
|
|
@el = document.getElementById('popup')
|
|
@bound_click_maybe_close = @click_maybe_close.bind(@)
|
|
@bound_key_maybe_close = @key_maybe_close.bind(@)
|
|
|
|
open: (html) ->
|
|
@el.innerHTML = html
|
|
@el.classList.remove 'hidden'
|
|
|
|
addEventListener 'click', @bound_click_maybe_close
|
|
addEventListener 'keydown', @bound_key_maybe_close
|
|
|
|
close: ->
|
|
removeEventListener 'click', @bound_click_maybe_close
|
|
removeEventListener 'keydown', @bound_key_maybe_close
|
|
|
|
@el.classList.add 'hidden'
|
|
@el.innerHTML = ''
|
|
|
|
click_maybe_close: (e) ->
|
|
t = e.target
|
|
while t.parentElement
|
|
return true if Array.prototype.slice.call(@el.children).indexOf(t) > -1
|
|
t = t.parentElement
|
|
@close()
|
|
cancel e
|
|
|
|
key_maybe_close: (e) ->
|
|
return true unless e.keyCode is 27
|
|
@close()
|
|
cancel e
|
|
|
|
popup = new Popup()
|
|
|