Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created November 30, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiemonk/58d2b0868c430e436372 to your computer and use it in GitHub Desktop.
Save veggiemonk/58d2b0868c430e436372 to your computer and use it in GitHub Desktop.
var Modal = {
controller: function() {
return {isVisible: false} //internal state
},
view: function() {
return m(".modal", {
class: ctrl.visible ? ".modal-visible" : "" //sets visibility via CSS
config: function(el, init) {
if (!init) {
//jQuery-exposed API
$(el).data("modal", {
toggle: function() {
m.startComputation()
ctrl.isVisible = !ctrl.isVisible
m.endComputation()
}
})
}
}
}, "modal!")
}
}
//render the component via Mithril
m.mount(document.body, Modal)
//access it from outside
$(".modal:eq(0)").data("modal").toggle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment