Fix broken tests
This commit is contained in:
parent
505bd1337a
commit
6d4d0f104f
2 changed files with 84 additions and 10 deletions
23
mithril.js
23
mithril.js
|
|
@ -1081,18 +1081,21 @@
|
||||||
//
|
//
|
||||||
// #348 don't set the value if not needed - otherwise, cursor
|
// #348 don't set the value if not needed - otherwise, cursor
|
||||||
// placement breaks in Chrome
|
// placement breaks in Chrome
|
||||||
// #1195 do not update attribute value if not changed
|
try {
|
||||||
if (node[attrName] !== dataAttr) {
|
if (tag !== "input" || node[attrName] !== dataAttr) {
|
||||||
try {
|
node[attrName] = dataAttr
|
||||||
if (tag !== "input" || node[attrName] !== dataAttr) {
|
|
||||||
node[attrName] = dataAttr
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
node.setAttribute(attrName, dataAttr)
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
node.setAttribute(attrName, dataAttr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
node.setAttribute(attrName, dataAttr)
|
||||||
|
} catch (e) {
|
||||||
|
// IE8 doesn't allow change input attributes and throws
|
||||||
|
// an exception. Unfortunately it cannot be handled, because
|
||||||
|
// error code is not informative.
|
||||||
}
|
}
|
||||||
} else if (node[attrName] !== dataAttr) {
|
|
||||||
node.setAttribute(attrName, dataAttr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
71
tets.html
Normal file
71
tets.html
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
<!doctype html>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.js"></script>
|
||||||
|
<script src="mithril.js"></script>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
//this application only has one component: todo
|
||||||
|
var todo = {};
|
||||||
|
|
||||||
|
//for simplicity, we use this component to namespace the model classes
|
||||||
|
|
||||||
|
//the Todo class has two properties
|
||||||
|
todo.Todo = function(data) {
|
||||||
|
this.description = m.prop(data.description);
|
||||||
|
this.done = m.prop(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
//the TodoList class is a list of Todo's
|
||||||
|
todo.TodoList = Array;
|
||||||
|
|
||||||
|
//the view-model tracks a running list of todos,
|
||||||
|
//stores a description for new todos before they are created
|
||||||
|
//and takes care of the logic surrounding when adding is permitted
|
||||||
|
//and clearing the input after adding a todo to the list
|
||||||
|
todo.vm = (function() {
|
||||||
|
var vm = {}
|
||||||
|
vm.init = function() {
|
||||||
|
//a running list of todos
|
||||||
|
vm.list = new todo.TodoList();
|
||||||
|
|
||||||
|
//a slot to store the name of a new todo before it is created
|
||||||
|
vm.description = m.prop("");
|
||||||
|
|
||||||
|
//adds a todo to the list, and clears the description field for user convenience
|
||||||
|
vm.add = function() {
|
||||||
|
if (vm.description()) {
|
||||||
|
vm.list.push(new todo.Todo({description: vm.description()}));
|
||||||
|
vm.description("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return vm
|
||||||
|
}())
|
||||||
|
|
||||||
|
//the controller defines what part of the model is relevant for the current page
|
||||||
|
//in our case, there's only one view-model that handles everything
|
||||||
|
todo.controller = function() {
|
||||||
|
todo.vm.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
//here's the view
|
||||||
|
todo.view = function() {
|
||||||
|
return [
|
||||||
|
m("input", {onchange: m.withAttr("value", todo.vm.description), value: todo.vm.description()}),
|
||||||
|
m("button", {onclick: todo.vm.add}, "Add"),
|
||||||
|
m("table", [
|
||||||
|
todo.vm.list.map(function(task, index) {
|
||||||
|
return m("tr", [
|
||||||
|
m("td", [
|
||||||
|
m("input[type=checkbox]", {onclick: m.withAttr("checked", task.done), checked: task.done()})
|
||||||
|
]),
|
||||||
|
m("td", {style: {textDecoration: task.done() ? "line-through" : "none"}}, task.description()),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
])
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
//initialize the application
|
||||||
|
m.mount(document.body, {controller: todo.controller, view: todo.view});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue