template polyfill
This commit is contained in:
parent
eaf39adc44
commit
b5cf1c9579
|
@ -1132,6 +1132,7 @@ Nuclear.Class.extend = function (prop) {
|
|||
document.head.appendChild(style);
|
||||
//先隐藏所有dom元素
|
||||
style.sheet.insertRule("body { visibility: hidden; }", 0);
|
||||
style.sheet.insertRule("template { display: none !important; }", 0);
|
||||
}
|
||||
|
||||
function scoper(css, prefix) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Nuclear</title>
|
||||
</head>
|
||||
<body>
|
||||
<template id="myTemplate">
|
||||
<style scoped>
|
||||
h3 { color:red; }
|
||||
button{ color:green;}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<h3>TODO</h3>
|
||||
<ul>{{#items}}<li>{{.}}</li>{{/items}}</ul>
|
||||
<form onsubmit="add(event)">
|
||||
<input nc-id="textBox" type="text">
|
||||
<button>Add #{{items.length}}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div id="todoListContainer"></div>
|
||||
<script src="http://alloyteam.github.io/Nuclear/js/nuclear.min.js"></script>
|
||||
|
||||
<script>
|
||||
var todoTpl = document.querySelector("#myTemplate").innerHTML;
|
||||
|
||||
var TodoApp = Nuclear.create({
|
||||
add: function (evt) {
|
||||
evt.preventDefault();
|
||||
this.option.items.push(this.textBox.value);
|
||||
},
|
||||
render: function () {
|
||||
return todoTpl;
|
||||
}
|
||||
});
|
||||
|
||||
new TodoApp({ items: [] }, "#todoListContainer");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -7,6 +7,7 @@
|
|||
document.head.appendChild(style);
|
||||
//先隐藏所有dom元素
|
||||
style.sheet.insertRule("body { visibility: hidden; }", 0);
|
||||
style.sheet.insertRule("template { display: none !important; }", 0);
|
||||
}
|
||||
|
||||
function scoper(css, prefix) {
|
||||
|
|
Loading…
Reference in New Issue