Created
May 13, 2015 18:18
-
-
Save HendrikRoth/a75ecf95363cc5286b24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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