Update textfield example for fastrouting

This commit is contained in:
Tony Garnock-Jones 2014-05-26 23:29:29 -04:00
parent 336b4f36ac
commit 424a00c675
2 changed files with 15 additions and 14 deletions

View File

@ -9,6 +9,7 @@
<link href="style.css" rel="stylesheet">
<script src="../../third-party/jquery-2.0.3.min.js"></script>
<script src="../../route.js"></script>
<script src="../../marketplace.js"></script>
<script src="../../spy.js"></script>
<script src="../../dom-driver.js"></script>
@ -18,7 +19,6 @@
<script src="../../jquery-driver.js"></script>
<script src="../../wake-detector.js"></script>
<script src="../../websocket-driver.js"></script>
<script src="index.js"></script>
</head>
<body>

View File

@ -16,19 +16,21 @@ function spawnGui() {
sub(["fieldContents", __, __], 0, 1),
sub(["highlight", __], 0, 1)]);
},
fieldContentsSpec: route.compileProjection(["fieldContents", _$, _$]),
highlightSpec: route.compileProjection(["highlight", _$]),
handleEvent: function (e) {
switch (e.type) {
case "routes":
var text = "", pos = 0, highlight = false;
// BUG: escape text!
for (var i = 0; i < e.routes.length; i++) {
var r = e.routes[i];
if (r.pattern[0] === "fieldContents") {
text = r.pattern[1];
pos = r.pattern[2];
} else if (r.pattern[0] === "highlight") {
highlight = r.pattern[1];
}
var fc = route.matcherKeys(e.gestalt.project(this.fieldContentsSpec, true));
if (fc.length > 0) {
text = fc[0][0];
pos = fc[0][1];
}
var hl = route.matcherKeys(e.gestalt.project(this.highlightSpec, true));
if (hl.length > 0) {
highlight = hl[0][0];
}
$("#fieldContents")[0].innerHTML = highlight
? piece(text, pos, 0, highlight[0], "normal") +
@ -110,6 +112,7 @@ function spawnSearch() {
World.spawn({
fieldContents: "",
highlight: false,
fieldContentsSpec: route.compileProjection(["fieldContents", _$, _$]),
boot: function () {
World.updateRoutes(this.subscriptions());
},
@ -134,11 +137,9 @@ function spawnSearch() {
handleEvent: function (e) {
switch (e.type) {
case "routes":
for (var i = 0; i < e.routes.length; i++) {
var r = e.routes[i];
if (r.pattern[0] === "fieldContents") {
this.fieldContents = r.pattern[1];
}
var fc = route.matcherKeys(e.gestalt.project(this.fieldContentsSpec, true));
if (fc.length > 0) {
this.fieldContents = fc[0][0];
}
this.search();
break;