Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Created November 20, 2014 18:34
Show Gist options
  • Select an option

  • Save pier-oliviert/f03d3cc6c491b4dd7e5a to your computer and use it in GitHub Desktop.

Select an option

Save pier-oliviert/f03d3cc6c491b4dd7e5a to your computer and use it in GitHub Desktop.
e.HTML = "<%= j content_tag(:div, render('list', posts: @posts), class: %w(popup)) %>".toHTML()
<%= link_to "Drafts", admin_posts_path(type: :draft), class: %w(drafts), remote: true, as: 'Posts.Popup' %>
class Popup
loaded: =>
@on 'posts:index', @show
show: (e) =>
document.body.appendChild(e.HTML)
@on 'keyup', document, @escaped
@on 'click', document, @clicked
clicked: (e) =>
el = e.target
while el && !el.classList.contains('popup')
el = el.parentElement
unless el?
@remove()
escaped: (e) =>
if e.keyCode == 27
@remove()
remove: (e) =>
document.removeEventListener('keyup')
document.removeEventListener('click')
popup = document.body.querySelector('.popup')
if popup?
popup.remove()
Ethereal.Models.add Popup, 'Posts.Popup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment