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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Mithril experiment</title> | |
<meta name="description" content="mithriljs: Mithril template"> | |
<meta charset="utf-8"> | |
<script> | |
window.log = function(){ | |
log.history = log.history || []; // store logs to an array for reference |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Mithril experiment</title> | |
<meta name="description" content="mithriljs: Mithril template from Github"> | |
<meta charset="utf-8"> | |
<script> | |
window.log = function(){ | |
log.history = log.history || []; // store logs to an array for reference |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Mithril experiment</title> | |
<meta name="description" content="mithriljs: Mithril template"> | |
<meta charset="utf-8"> | |
<script> | |
window.log = function(){ | |
log.history = log.history || []; // store logs to an array for reference |
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
//helpers | |
var target | |
function tenant(id, module) { | |
return { | |
controller: module.controller, | |
view: function(ctrl) { | |
return target == id ? module.view(ctrl) : {subtree: "retain"} | |
} | |
} | |
} |
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
var DropDownExample = { | |
controller: function () { | |
var ctrl = this | |
ctrl.data = m.prop([{ name: 'alice', id: 1}, { name: 'bob', id: 2 }]) | |
ctrl.selectedId = m.prop() | |
}, | |
view: function (ctrl) { | |
return m('select', { onchange: m.withAttr('value', ctrl.selectedId) }, [ | |
ctrl.data().map(function(person) { | |
return m('option', { value: person.id }, person.name) |
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
var LoadingExample = { | |
controller: function () { | |
var ctrl = this | |
// `background: true` is important here. | |
// Otherwise Mithril will wait for the AJAX request to complete before rendering the view. | |
ctrl.users = m.request({ url: 'users', method: 'GET', background: true }) | |
}, | |
view: function (ctrl) { | |
return m('.users', [ | |
m('h3', "All Users"), |
####Unicode needs no extra escaping when in a view template string
m('div', "あなたは友人である場合は、パスワードを話す、とドアが開きます")
m.render(document.body, "hello 世界")
####Whitespace can be achieved a few different ways:
css
m("div[style='white-space:pre']", "LIST:\n\titem 1\n\titem 2")
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
m.initComponent = function (component, options, content) { | |
var controller = new component.controller(options) | |
controller.render = function (options2, content2) { | |
return component.view(controller, options2 || options, content2 || content) | |
} | |
return controller | |
} |
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
function state (namespace) { | |
if (!namespace) return internalState[internalState.length - 1] | |
internalState.push([namespace, options]) | |
m.redirect(namespace, options) | |
} | |
function goto (namespace, options) { | |
return function (e) { | |
e.preventDefault() | |
e.stopPropagation() |
NewerOlder