-
-
Save Raynos/2386775 to your computer and use it in GitHub Desktop.
To-do application to-do item view implementation
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
| /* | |
| I herd u liek bloat and useless frameworks. | |
| Just write JavaScript already | |
| Uses [DelegateListener][1] and [fragment][2] | |
| [1]: https://github.com/termi/DelegateListener | |
| [2]: https://github.com/Raynos/fragment | |
| */ | |
| CheckIt.TodoController = { | |
| model: CheckIt.TodoModel, | |
| view: CheckIt.ToDoView, | |
| start: function () { | |
| document.addEventListener( | |
| 'click', | |
| new DelegateListener('.done', this.handleClickDone.bind(this)) | |
| ); | |
| this.view.render() | |
| }, | |
| handleClickDone: function (evt) { | |
| this.view.update(this.model) | |
| } | |
| } | |
| CheckIt.TodoView = { | |
| render: function () { | |
| var rootEl = this.rootEl = document.createElement('li'); | |
| rootEl.className = 'Todo' | |
| rootEl.appendChild( | |
| fragment('<input type="checkbox" class="done">' + | |
| '<span class="description"></span>') | |
| ); | |
| this.textWrapper = rootEl.querySelector('span'); | |
| }, | |
| update: function (model) { | |
| this.textWrapper.textContent = model.description | |
| this.textWrapper.className = 'description ' + model.status | |
| } | |
| } | |
| CheckIt.Model = { | |
| description: "bar", | |
| status: "foo" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment