Created
November 30, 2015 16:38
-
-
Save veggiemonk/58d2b0868c430e436372 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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