From f05f452dd63578f67b1d4e89e35568d55806c472 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 15 Mar 2012 13:32:33 -0400 Subject: [PATCH] continuing to fix some typos --- js/world/racket-impl.rkt | 2 +- web-world/geolocation.rkt | 22 ++++++++++++++-------- web-world/js-impl.js | 36 ++++++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/js/world/racket-impl.rkt b/js/world/racket-impl.rkt index 3262150..82cb1ff 100644 --- a/js/world/racket-impl.rkt +++ b/js/world/racket-impl.rkt @@ -1,6 +1,6 @@ #lang s-exp "../../lang/base.rkt" -(provide make-js-world-event) +(provide make-world-event-handler) (define (make-world-event-handler setup shutdown) (error 'make-world-event-handler "Must be run under a JavaScript context.")) diff --git a/web-world/geolocation.rkt b/web-world/geolocation.rkt index 4b6c94d..4b303aa 100644 --- a/web-world/geolocation.rkt +++ b/web-world/geolocation.rkt @@ -2,16 +2,22 @@ (require "../js/world.rkt" "../js.rkt") -;; Create a new event handler type -(define-values (on-geo-change locationCallback) - (make-js-event-type)) +(provide on-geo) -(define start-up-geo +(define setup-geo (js-function->procedure "function(locationCallback) { - navigator.geolocation.watchPosition( - function(evt) { locationCallback(evt.latitude, evt.longitude); })}")) + return navigator.geolocation.watchPosition( + function(evt) { locationCallback(plt.runtime.makeFloat(evt.latitude), + plt.runtime.makeFloat(evt.longitude)); })}")) + +(define shutdown-geo + (js-function->procedure + "function(watchId) { + navigator.geolocation.clearWatch(watchId); }")) + + +;; The new event handler type for geolocation: +(define on-geo (make-world-event-handler setup-geo shutdown-geo)) -;; TODO: adjust the FFI so we can start-up and shutdown this more easily. -(start-up-geo locationCallback) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index 2663578..d9dd7ab 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -939,10 +939,12 @@ */ var EventSource = function() {}; - EventSource.prototype.onStart = function(fireEvent) { + EventSource.prototype.onStart = function(fireEvent, k) { + k(); }; - EventSource.prototype.onStop = function() { + EventSource.prototype.onStop = function(k) { + k(); }; @@ -958,7 +960,7 @@ TickEventSource.prototype = plt.baselib.heir(EventSource.prototype); - TickEventSource.prototype.onStart = function(fireEvent) { + TickEventSource.prototype.onStart = function(fireEvent, k) { if (this.id === undefined) { this.id = setInterval( function(evt) { @@ -967,13 +969,15 @@ }, this.delay); } + k(); }; - TickEventSource.prototype.onStop = function() { + TickEventSource.prototype.onStop = function(k) { if (this.id !== undefined) { clearInterval(this.id); this.id = undefined; } + k(); }; @@ -985,7 +989,7 @@ this.elt = undefined; }; MockLocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); - MockLocationEventSource.prototype.onStart = function(fireEvent) { + MockLocationEventSource.prototype.onStart = function(fireEvent, k) { if (this.elt === undefined) { var mockLocationSetter = document.createElement("div"); @@ -1015,13 +1019,15 @@ this.elt = mockLocationSetter; } + k(); }; - MockLocationEventSource.prototype.onStop = function() { + MockLocationEventSource.prototype.onStop = function(k) { if (this.elt !== undefined) { document.body.removeChild(this.elt); this.elt = undefined; } + k(); }; @@ -1035,7 +1041,7 @@ LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); - LocationEventSource.prototype.onStart = function(fireEvent) { + LocationEventSource.prototype.onStart = function(fireEvent, k) { var that = this; if (this.id === undefined) { var success = function(position) { @@ -1070,13 +1076,15 @@ maximumAge : 10000}); } } + k(); }; - LocationEventSource.prototype.onStop = function() { + LocationEventSource.prototype.onStop = function(k) { if (this.id !== undefined) { navigator.geolocation.clearWatch(this.id); this.id = undefined; } + k(); }; @@ -1095,7 +1103,7 @@ DomEventSource.prototype = plt.baselib.heir(EventSource.prototype); - DomEventSource.prototype.onStart = function(fireEvent) { + DomEventSource.prototype.onStart = function(fireEvent, k) { var element = this.elementOrId; if (typeof(this.elementOrId) === 'string') { element = document.getElementById(this.elementOrId); @@ -1113,10 +1121,11 @@ } }; $(element).bind(this.type, this.handler); + k(); }; - DomEventSource.prototype.onStop = function() { + DomEventSource.prototype.onStop = function(k) { var element = this.elementOrId; if (typeof(this.elementOrId) === 'string') { element = document.getElementById(this.elementOrId); @@ -1128,6 +1137,7 @@ } this.handler = undefined; } + k(); }; @@ -1255,13 +1265,11 @@ 0); } }; - handler.eventSource.onStart(fireEvent); - k(); + handler.eventSource.onStart(fireEvent, k); }; stopEventHandler = function(handler, k) { - handler.eventSource.onStop(); - k(); + handler.eventSource.onStop(k); };