Skip to content

Instantly share code, notes, and snippets.

@HendrikRoth
Created May 13, 2015 18:18
Show Gist options
  • Save HendrikRoth/a75ecf95363cc5286b24 to your computer and use it in GitHub Desktop.
Save HendrikRoth/a75ecf95363cc5286b24 to your computer and use it in GitHub Desktop.
'use strict'
function createView(ctrl, opts, children) {
opts = opts || {}
opts.shadow = opts.shadow || true
return m('.modal[layout][horizontal][center-center]', {
active: ctrl.active(),
shadow: opts.shadow,
config: function(element, isInitialized, context) {
if (isInitialized) return
var handleKey = function(e) {
// 27 == ESC
if (e.keyCode == 27) {
m.redraw()
}
}
document.body.appendChild(element)
document.body.addEventListener('keyup', handleKey)
context.onunload = function() {
document.body.removeChild(element)
document.body.removeEventListener('keyup', handleKey)
}
}
}, [
m('.dialog[flex][self-center]', [
m('.content', [
opts.header ? m('.header', opts.header) : null,
children
]),
m('.bottom', opts.bottom)
])
])
}
function controller() {
return {
view: m.prop(),
active: m.prop(false)
}
}
function view(ctrl, opts, children) {
var view = ctrl.view()
if (!view || opts.refresh) {
view = createView(ctrl, opts, children)
ctrl.view(view)
}
return view
}
module.exports = {
controller: controller,
view: view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment