todomvc: Follow HTML template and file layout more closely; use new locationHash
This commit is contained in:
parent
eafcff8f75
commit
a7ad6355f5
|
@ -1,14 +1,14 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Syndicate: TodoMVC</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<link href="todomvc/base.css" rel="stylesheet">
|
||||
<link href="todomvc/index.css" rel="stylesheet">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Syndicate • TodoMVC</title>
|
||||
<link rel="stylesheet" href="node_modules/todomvc-common/base.css">
|
||||
<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
|
||||
<link rel="stylesheet" href="css/app.css">
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script>
|
||||
<script src="../../third-party/jquery-2.2.0.min.js"></script>
|
||||
<script src="../../dist/syndicatecompiler.js"></script>
|
||||
<script src="../../dist/syndicate.js"></script>
|
||||
<script type="text/syndicate-js" src="index.js"></script>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<section class="main">
|
||||
<input class="toggle-all" type="checkbox">
|
||||
<label for="toggle-all">Mark all as complete</label>
|
||||
<ul class="todo-list" id="todo-list">
|
||||
<ul class="todo-list">
|
||||
<template id="todo-list-item-view-template">
|
||||
<li data-id="{{id}}" class="{{hidden_class}} {{completed_class}}">
|
||||
<div class="view">
|
||||
|
@ -40,10 +40,10 @@
|
|||
</ul>
|
||||
</section>
|
||||
<footer class="footer">
|
||||
<span class="todo-count"></span>
|
||||
<span class="todo-count"><strong>0</strong> item left</span>
|
||||
<ul class="filters">
|
||||
<li>
|
||||
<a href="#/" class="selected">All</a>
|
||||
<a class="selected" href="#/">All</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#/active">Active</a>
|
||||
|
@ -55,13 +55,10 @@
|
|||
<button class="clear-completed">Clear completed</button>
|
||||
</footer>
|
||||
</section>
|
||||
|
||||
<footer class="info">
|
||||
<p>Double-click to edit a todo</p>
|
||||
<p>Created by <a href="http://twitter.com/oscargodson">Oscar Godson</a></p>
|
||||
<p>Refactored by <a href="https://github.com/cburgmer">Christoph Burgmer</a></p>
|
||||
<p>Ported to Syndicate/js by <a href="http://twitter.com/leastfixedpoint">Tony Garnock-Jones</a></p>
|
||||
<p>HTML structure and CSS taken from <a href="http://todomvc.com">TodoMVC</a></p>
|
||||
<p>Created by <a href="http://twitter.com/leastfixedpoint">Tony Garnock-Jones</a></p>
|
||||
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
|
||||
</footer>
|
||||
|
||||
<hr>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
assertion type todo(id, title, completed);
|
||||
message type deleteTodo(id);
|
||||
assertion type show(completed);
|
||||
assertion type currentLocationHash(hash);
|
||||
|
||||
/*
|
||||
To Do (ho ho ho)
|
||||
|
@ -27,6 +26,10 @@ assertion type currentLocationHash(hash);
|
|||
var ESCAPE_KEY_CODE = 27;
|
||||
var ENTER_KEY_CODE = 13;
|
||||
|
||||
function getTemplate(id) {
|
||||
return document.getElementById(id).innerHTML;
|
||||
}
|
||||
|
||||
var nextId = 0;
|
||||
function addTodo(title) {
|
||||
title = title.trim();
|
||||
|
@ -48,10 +51,10 @@ function addTodo(title) {
|
|||
finally { this.visible = false; }
|
||||
}
|
||||
|
||||
assert this.ui.html('#todo-list',
|
||||
Mustache.render($(this.editing
|
||||
? '#todo-list-item-edit-template'
|
||||
: '#todo-list-item-view-template').html(),
|
||||
assert this.ui.html('.todo-list',
|
||||
Mustache.render(getTemplate(this.editing
|
||||
? 'todo-list-item-edit-template'
|
||||
: 'todo-list-item-view-template'),
|
||||
{
|
||||
completed_class: this.completed ? "completed" : "",
|
||||
hidden_class: this.visible ? "" : "hidden",
|
||||
|
@ -115,22 +118,8 @@ ground dataspace G {
|
|||
}
|
||||
|
||||
actor {
|
||||
this.hash = hashFrom(document.location.toString());
|
||||
function hashFrom(u) {
|
||||
var i = u.indexOf('#');
|
||||
return (i !== -1) ? u.slice(i + 1) : '/';
|
||||
}
|
||||
react {
|
||||
assert currentLocationHash(this.hash);
|
||||
on message Syndicate.UI.windowEvent('hashchange', $e) {
|
||||
this.hash = hashFrom(e.newURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actor {
|
||||
react {
|
||||
on asserted currentLocationHash($hash) {
|
||||
on asserted Syndicate.UI.locationHash($hash) {
|
||||
// TODO this is a bit icky too
|
||||
var ns = document.querySelectorAll('ul.filters > li > a');
|
||||
for (var i = 0; i < ns.length; i++) { ns[i].className = ''; }
|
||||
|
@ -138,14 +127,14 @@ ground dataspace G {
|
|||
n.className = 'selected';
|
||||
}
|
||||
|
||||
during currentLocationHash('/') {
|
||||
during Syndicate.UI.locationHash('/') {
|
||||
assert show(true);
|
||||
assert show(false);
|
||||
}
|
||||
during currentLocationHash('/active') {
|
||||
during Syndicate.UI.locationHash('/active') {
|
||||
assert show(false);
|
||||
}
|
||||
during currentLocationHash('/completed') {
|
||||
during Syndicate.UI.locationHash('/completed') {
|
||||
assert show(true);
|
||||
}
|
||||
}
|
||||
|
@ -157,5 +146,5 @@ ground dataspace G {
|
|||
}
|
||||
|
||||
G.dataspace.setOnStateChange(function (mux, patch) {
|
||||
$("#ds-state").text(Syndicate.prettyTrie(mux.routingTable));
|
||||
document.getElementById("ds-state").innerText = Syndicate.prettyTrie(mux.routingTable);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue