diff --git a/scribblings/cs19.scrbl b/scribblings/cs19.scrbl index 15060a3..79d7912 100644 --- a/scribblings/cs19.scrbl +++ b/scribblings/cs19.scrbl @@ -165,7 +165,7 @@ Write a file called @filepath{tick-tock.rkt} with the following content. ;; draw: world view -> view (define (draw world dom) - (update-view-text (view-focus dom "#counter") world)) + (update-view-text (view-focus dom "counter") world)) ;; tick: world view -> world @@ -333,7 +333,7 @@ function will be called every time an event occurs. ;; draw: world view -> view (define (draw world dom) - (update-view-text (view-focus dom "#name-span") + (update-view-text (view-focus dom "name-span") (world-name world))) ... (big-bang ... @@ -359,19 +359,13 @@ Common values for @racket[x] include @tech{resource}s. -@defproc[(view-focus? [v view] [selector String]) boolean]{ -Return true if the view can be focused using the given selector. - -Selectors are currently restricted to @litchar{#id} selectors for the -moment. +@defproc[(view-focus? [v view] [id String]) boolean]{ +Return true if the view can be focused using the given id. } -@defproc[(view-focus [v view] [selector String]) view]{ -Focuses the view on an element, given the @racket[selector]. The view +@defproc[(view-focus [v view] [id String]) view]{ +Focuses the view on an element, given the @racket[id]. The view will be searched starting from the toplevelmost node. - -Selectors are currently restricted to @litchar{#id} selectors for the -moment. } diff --git a/scribblings/manual.scrbl b/scribblings/manual.scrbl index 925c1a9..cea2183 100644 --- a/scribblings/manual.scrbl +++ b/scribblings/manual.scrbl @@ -561,7 +561,7 @@ Write a file called @filepath{tick-tock.rkt} with the following content. ;; draw: world view -> view (define (draw world dom) - (update-view-text (view-focus dom "#counter") world)) + (update-view-text (view-focus dom "counter") world)) ;; tick: world view -> world @@ -709,7 +709,7 @@ function will be called every time an event occurs. ;; draw: world view -> view (define (draw world dom) - (update-view-text (view-focus dom "#name-span") + (update-view-text (view-focus dom "name-span") (world-name world))) ... (big-bang ... @@ -734,12 +734,14 @@ Common values for @racket[x] include @tech{resource}s. } -@defproc[(view-focus [v view] [selector String]) view]{ -Focuses the view on an element, given the @racket[selector]. The view -will be searched starting from the toplevelmost node. +@defproc[(view-focus? [v view] [id String]) boolean]{ +Return true if the view can be focused using the given id. +} -Selectors are currently restricted to @litchar{#id} selectors for the -moment. + +@defproc[(view-focus [v view] [id String]) view]{ +Focuses the view on an element, given the @racket[id]. The view +will be searched starting from the toplevelmost node. } diff --git a/tests/more-tests/sharing.rkt b/tests/more-tests/sharing.rkt index 7973de8..55ebb7a 100644 --- a/tests/more-tests/sharing.rkt +++ b/tests/more-tests/sharing.rkt @@ -59,7 +59,7 @@ -(define-struct person (name friends) #:mutable) +(define-struct person (name friends)) (let-values ([(a b c) (shared ([a (make-person "jill" (list b c))] [b (make-person "jack" (list a c))] diff --git a/web-world/examples/attr-animation/attr-animation.rkt b/web-world/examples/attr-animation/attr-animation.rkt index 9e4e1bd..4e8463b 100644 --- a/web-world/examples/attr-animation/attr-animation.rkt +++ b/web-world/examples/attr-animation/attr-animation.rkt @@ -10,10 +10,10 @@ (modulo (add1 w) 10)) -;; pick-block: world view -> view +;; pick-block: view number -> view ;; Focus the view on block i. (define (pick-block v i) - (view-focus v (format "#~a" i))) + (view-focus v (format "~a" i))) (define (draw w v) diff --git a/web-world/examples/attr-animation/index.html b/web-world/examples/attr-animation/index.html index 14cf68a..b10f59b 100644 --- a/web-world/examples/attr-animation/index.html +++ b/web-world/examples/attr-animation/index.html @@ -39,7 +39,7 @@ The program for this is: ;; pick-block: world view -> view ;; Focus the view on block i. (define (pick-block v i) - (view-focus v (format "#~a" i))) + (view-focus v (format "~a" i))) (define (draw w v) diff --git a/web-world/examples/dwarves-with-remove/dwarves-with-remove.rkt b/web-world/examples/dwarves-with-remove/dwarves-with-remove.rkt index 89fcc00..941e137 100644 --- a/web-world/examples/dwarves-with-remove/dwarves-with-remove.rkt +++ b/web-world/examples/dwarves-with-remove/dwarves-with-remove.rkt @@ -26,8 +26,8 @@ ;; until we're all done. (define (draw w dom-view) (foldl (lambda (name view) - (cond [(view-focus? view (format "#~a" name)) - (define focused (view-focus view (format "#~a" name))) + (cond [(view-focus? view name) + (define focused (view-focus view name)) (cond [(member name w) view] @@ -44,7 +44,7 @@ ;; to each name here. (define my-view (foldl (lambda (name view) - (view-bind (view-focus view (format "#~a" name)) + (view-bind (view-focus view name) "click" hide-on-click)) (->view index.html) diff --git a/web-world/examples/dwarves/dwarves.rkt b/web-world/examples/dwarves/dwarves.rkt index 29675c9..f02f65b 100644 --- a/web-world/examples/dwarves/dwarves.rkt +++ b/web-world/examples/dwarves/dwarves.rkt @@ -26,7 +26,7 @@ ;; until we're all done. (define (draw w dom-view) (foldl (lambda (name view) - (define focused (view-focus view (format "#~a" name))) + (define focused (view-focus view name)) (cond [(member name w) (view-show focused)] @@ -41,7 +41,7 @@ ;; to each name here. (define my-view (foldl (lambda (name view) - (view-bind (view-focus view (format "#~a" name)) + (view-bind (view-focus view name) "click" hide-on-click)) (->view index.html) diff --git a/web-world/examples/field/field.rkt b/web-world/examples/field/field.rkt index 973d60b..023bf3e 100644 --- a/web-world/examples/field/field.rkt +++ b/web-world/examples/field/field.rkt @@ -11,18 +11,18 @@ ;; When the user clicks on the button, grab at the text of the ;; text-field. (define (on-click w button-view) - (view-form-value (view-focus button-view "#text-field"))) + (view-form-value (view-focus button-view "text-field"))) ;; draw: world view -> view ;; Take the view, and replace the template with the world value. (define (draw w dom) - (update-view-text (view-focus dom "#template") + (update-view-text (view-focus dom "template") w)) (define my-view (view-bind (view-focus (->view index.html) - "#button") + "button") "click" on-click)) diff --git a/web-world/examples/redirected/redirected.rkt b/web-world/examples/redirected/redirected.rkt index 51101f3..4dc7b81 100644 --- a/web-world/examples/redirected/redirected.rkt +++ b/web-world/examples/redirected/redirected.rkt @@ -9,7 +9,7 @@ ;; draw: world view -> view (define (draw w v) - (update-view-text (view-focus v "#counter") w)) + (update-view-text (view-focus v "counter") w)) diff --git a/web-world/examples/tick-tock/tick-tock.rkt b/web-world/examples/tick-tock/tick-tock.rkt index bb67aeb..f042530 100644 --- a/web-world/examples/tick-tock/tick-tock.rkt +++ b/web-world/examples/tick-tock/tick-tock.rkt @@ -7,7 +7,7 @@ ;; draw: world view -> view (define (draw w v) - (update-view-text (view-focus v "#counter") w)) + (update-view-text (view-focus v "counter") w)) diff --git a/web-world/examples/todo/todo.rkt b/web-world/examples/todo/todo.rkt index ec94700..3e5b8ca 100644 --- a/web-world/examples/todo/todo.rkt +++ b/web-world/examples/todo/todo.rkt @@ -36,7 +36,7 @@ ;; world view -> world (define (on-add world view) - (local [(define text (view-form-value (view-focus view "#next-item")))] + (local [(define text (view-form-value (view-focus view "next-item")))] (cons (new-item text) world))) @@ -50,8 +50,8 @@ ;; refresh-item-in-view: item view -> view (define (refresh-item-in-view item view) (cond - [(view-focus? view (format "#~a" (item-id item))) - (update-view-css (view-focus view (format "#~a" (item-id item))) + [(view-focus? view (item-id item)) + (update-view-css (view-focus view (item-id item)) "text-decoration" (cond [(item-finished? item) "line-through"] @@ -59,7 +59,7 @@ "none"]))] [else (view-bind - (view-append-child (view-focus view "#items") + (view-append-child (view-focus view "items") (xexp->dom `(li (@ (id ,(item-id item))) ,(item-content item)))) "click" @@ -74,7 +74,7 @@ (define the-view - (view-bind (view-focus (->view index.html) "#add-button") + (view-bind (view-focus (->view index.html) "add-button") "click" on-add)) diff --git a/web-world/examples/where-am-i/where-am-i.rkt b/web-world/examples/where-am-i/where-am-i.rkt index f0db836..7f551ea 100644 --- a/web-world/examples/where-am-i/where-am-i.rkt +++ b/web-world/examples/where-am-i/where-am-i.rkt @@ -23,13 +23,13 @@ (define (draw world dom) (define v1 (if (coord? (world-real world)) - (update-view-text (view-focus dom "#real-location") + (update-view-text (view-focus dom "real-location") (format "lat=~a, lng=~a" (coord-lat (world-real world)) (coord-lng (world-real world)))) dom)) (define v2 (if (coord? (world-mock world)) - (update-view-text (view-focus v1 "#mock-location") + (update-view-text (view-focus v1 "mock-location") (format "lat=~a, lng=~a" (coord-lat (world-mock world)) (coord-lng (world-mock world)))) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index 1274cc5..c98ee57 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -72,14 +72,11 @@ // For the moment, we only support selection by id. - var idRegexp = new RegExp("^#"); var selectorMatches = function(selector, node) { - if (selector.match(idRegexp)) { - if (node.nodeType === 1) { - return node.getAttribute('id') === selector.substring(1); - } else { - return false; - } + if (node.nodeType === 1) { + return node.getAttribute('id') === selector; + } else { + return false; } return false; }; @@ -107,6 +104,7 @@ this.nonce); }; + MockView.prototype.updateFocus = function(selector) { selector = selector.toString(); return this.act( @@ -125,7 +123,7 @@ }, function(eventHandlers) { return eventHandlers; }, function(view) { - view.focus = view.top.find(selector); + view.focus = $(document.getElementById(selector)); } ); };