Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

57 lines (52 sloc) 1.719 kB
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Sample App</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<script src="deps/underscore-1.3.3.min.js"></script>
<script src="deps/jquery-1.8.1.min.js"></script>
<script src="dombuilder.js"></script>
<script>
// Clean body just for fun
document.body.innerText = "";
// Render our new body
var $ = {};
var template = [
[".profile",
[".left.column",
["#date", new Date().toString() ],
["#address", "Sunnyvale, California" ]
],
[".right.column", {onclick:function () {alert("Foo");}},
["#email", "tim@creationix.com" ],
["#bio", "Cool Guy" ]
]
],
[".form",
["input$inputField"],
["button", {onclick: function () { alert($.inputField.value); }}, "Click Me"]
],
["hr", {css: {width:"100px",height:"50px"},$: function (hr) { console.log(hr); }}],
["p", "Inspect the source (not view source) to see how clean this dom is!"]
];
console.log("template", template);
var root = domBuilder(template, $);
console.log("$", $);
document.body.appendChild(root);
console.log("Checking input field in $ hash...");
if (document.querySelector("input") !== $.inputField) {
throw new Error("input didn't match $.inputField");
}
console.log("Checking text content of paragraph...");
if (document.querySelector("p").textContent !== template[template.length - 1][1]) {
throw new Error("paragraph didn't have the right contents")
}
console.log("Checking css property of hr element");
if (document.querySelector('hr').style.width !== "100px") {
throw new Error("Failed to set 100px width to hr");
}
</script></body>
</html>
Jump to Line
Something went wrong with that request. Please try again.