continuing to fix some typos

This commit is contained in:
Danny Yoo 2012-03-15 13:32:33 -04:00
parent 4e8b8a64cd
commit f05f452dd6
3 changed files with 37 additions and 23 deletions

View File

@ -1,6 +1,6 @@
#lang s-exp "../../lang/base.rkt" #lang s-exp "../../lang/base.rkt"
(provide make-js-world-event) (provide make-world-event-handler)
(define (make-world-event-handler setup shutdown) (define (make-world-event-handler setup shutdown)
(error 'make-world-event-handler "Must be run under a JavaScript context.")) (error 'make-world-event-handler "Must be run under a JavaScript context."))

View File

@ -2,16 +2,22 @@
(require "../js/world.rkt" (require "../js/world.rkt"
"../js.rkt") "../js.rkt")
;; Create a new event handler type (provide on-geo)
(define-values (on-geo-change locationCallback)
(make-js-event-type))
(define start-up-geo (define setup-geo
(js-function->procedure (js-function->procedure
"function(locationCallback) { "function(locationCallback) {
navigator.geolocation.watchPosition( return navigator.geolocation.watchPosition(
function(evt) { locationCallback(evt.latitude, evt.longitude); })}")) 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)

View File

@ -939,10 +939,12 @@
*/ */
var EventSource = function() {}; 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 = plt.baselib.heir(EventSource.prototype);
TickEventSource.prototype.onStart = function(fireEvent) { TickEventSource.prototype.onStart = function(fireEvent, k) {
if (this.id === undefined) { if (this.id === undefined) {
this.id = setInterval( this.id = setInterval(
function(evt) { function(evt) {
@ -967,13 +969,15 @@
}, },
this.delay); this.delay);
} }
k();
}; };
TickEventSource.prototype.onStop = function() { TickEventSource.prototype.onStop = function(k) {
if (this.id !== undefined) { if (this.id !== undefined) {
clearInterval(this.id); clearInterval(this.id);
this.id = undefined; this.id = undefined;
} }
k();
}; };
@ -985,7 +989,7 @@
this.elt = undefined; this.elt = undefined;
}; };
MockLocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); MockLocationEventSource.prototype = plt.baselib.heir(EventSource.prototype);
MockLocationEventSource.prototype.onStart = function(fireEvent) { MockLocationEventSource.prototype.onStart = function(fireEvent, k) {
if (this.elt === undefined) { if (this.elt === undefined) {
var mockLocationSetter = document.createElement("div"); var mockLocationSetter = document.createElement("div");
@ -1015,13 +1019,15 @@
this.elt = mockLocationSetter; this.elt = mockLocationSetter;
} }
k();
}; };
MockLocationEventSource.prototype.onStop = function() { MockLocationEventSource.prototype.onStop = function(k) {
if (this.elt !== undefined) { if (this.elt !== undefined) {
document.body.removeChild(this.elt); document.body.removeChild(this.elt);
this.elt = undefined; this.elt = undefined;
} }
k();
}; };
@ -1035,7 +1041,7 @@
LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype); LocationEventSource.prototype = plt.baselib.heir(EventSource.prototype);
LocationEventSource.prototype.onStart = function(fireEvent) { LocationEventSource.prototype.onStart = function(fireEvent, k) {
var that = this; var that = this;
if (this.id === undefined) { if (this.id === undefined) {
var success = function(position) { var success = function(position) {
@ -1070,13 +1076,15 @@
maximumAge : 10000}); maximumAge : 10000});
} }
} }
k();
}; };
LocationEventSource.prototype.onStop = function() { LocationEventSource.prototype.onStop = function(k) {
if (this.id !== undefined) { if (this.id !== undefined) {
navigator.geolocation.clearWatch(this.id); navigator.geolocation.clearWatch(this.id);
this.id = undefined; this.id = undefined;
} }
k();
}; };
@ -1095,7 +1103,7 @@
DomEventSource.prototype = plt.baselib.heir(EventSource.prototype); DomEventSource.prototype = plt.baselib.heir(EventSource.prototype);
DomEventSource.prototype.onStart = function(fireEvent) { DomEventSource.prototype.onStart = function(fireEvent, k) {
var element = this.elementOrId; var element = this.elementOrId;
if (typeof(this.elementOrId) === 'string') { if (typeof(this.elementOrId) === 'string') {
element = document.getElementById(this.elementOrId); element = document.getElementById(this.elementOrId);
@ -1113,10 +1121,11 @@
} }
}; };
$(element).bind(this.type, this.handler); $(element).bind(this.type, this.handler);
k();
}; };
DomEventSource.prototype.onStop = function() { DomEventSource.prototype.onStop = function(k) {
var element = this.elementOrId; var element = this.elementOrId;
if (typeof(this.elementOrId) === 'string') { if (typeof(this.elementOrId) === 'string') {
element = document.getElementById(this.elementOrId); element = document.getElementById(this.elementOrId);
@ -1128,6 +1137,7 @@
} }
this.handler = undefined; this.handler = undefined;
} }
k();
}; };
@ -1255,13 +1265,11 @@
0); 0);
} }
}; };
handler.eventSource.onStart(fireEvent); handler.eventSource.onStart(fireEvent, k);
k();
}; };
stopEventHandler = function(handler, k) { stopEventHandler = function(handler, k) {
handler.eventSource.onStop(); handler.eventSource.onStop(k);
k();
}; };