paradoxxxzero_butterfly/coffees/ext/popup.coffee
Peter Cai 5bbe456496
term: remove redundant events of inputHelper and redundant contentEditable
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
2018-06-03 17:51:16 +08:00

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()