Merge pull request #4 from darrencruse/master
add support for on-release in big-bang
This commit is contained in:
commit
e6d399f3a5
|
@ -9,9 +9,11 @@ This fork of Whalesong differs from dyoo/whalesong in the following ways:
|
||||||
(require whalesong/lang/for)
|
(require whalesong/lang/for)
|
||||||
* Adds match
|
* Adds match
|
||||||
(require whalesong/lang/match)
|
(require whalesong/lang/match)
|
||||||
|
* Adds on-release
|
||||||
|
(as a complement to on-key)
|
||||||
* Adds parameters
|
* Adds parameters
|
||||||
(require whalesong/lang/parameters)
|
(require whalesong/lang/parameters)
|
||||||
|
|
||||||
Note: The implementation of parameters works fine,
|
Note: The implementation of parameters works fine,
|
||||||
as long as you don't mix parameterize with non-local-exits
|
as long as you don't mix parameterize with non-local-exits
|
||||||
and reentries (i.e. call/cc and friends)
|
and reentries (i.e. call/cc and friends)
|
||||||
|
|
|
@ -103,6 +103,15 @@ EXPORTS['on-key'] =
|
||||||
return new OnKey(f);
|
return new OnKey(f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EXPORTS['on-release'] =
|
||||||
|
makePrimitiveProcedure(
|
||||||
|
'on-release',
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
var f = checkProcedureWithKey(MACHINE, "on-key", 0);
|
||||||
|
return new OnRelease(f);
|
||||||
|
});
|
||||||
|
|
||||||
EXPORTS['on-mouse'] =
|
EXPORTS['on-mouse'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'on-mouse',
|
'on-mouse',
|
||||||
|
|
|
@ -168,6 +168,22 @@ OnKey.prototype.toRawHandler = function(MACHINE, toplevelNode) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var OnRelease = function(handler) {
|
||||||
|
WorldConfigOption.call(this, 'on-release');
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnRelease.prototype = plt.baselib.heir(WorldConfigOption.prototype);
|
||||||
|
|
||||||
|
OnRelease.prototype.toRawHandler = function(MACHINE, toplevelNode) {
|
||||||
|
var that = this;
|
||||||
|
var worldFunction = adaptWorldFunction(that.handler);
|
||||||
|
return rawJsworld.on_release(
|
||||||
|
function(w, e, success) {
|
||||||
|
worldFunction(w, getKeyCodeName(e), success);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var getKeyCodeName = function(e) {
|
var getKeyCodeName = function(e) {
|
||||||
var code = e.charCode || e.keyCode;
|
var code = e.charCode || e.keyCode;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#:provided-values (big-bang
|
#:provided-values (big-bang
|
||||||
on-tick
|
on-tick
|
||||||
on-key
|
on-key
|
||||||
|
on-release
|
||||||
on-mouse
|
on-mouse
|
||||||
key=?
|
key=?
|
||||||
to-draw
|
to-draw
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
on-tick
|
on-tick
|
||||||
on-mouse
|
on-mouse
|
||||||
on-key
|
on-key
|
||||||
|
on-release
|
||||||
key=?
|
key=?
|
||||||
stop-when)
|
stop-when)
|
||||||
|
|
||||||
|
@ -33,6 +34,9 @@
|
||||||
(define (on-key handler)
|
(define (on-key handler)
|
||||||
(error 'on-key "must be run in JavaScript context"))
|
(error 'on-key "must be run in JavaScript context"))
|
||||||
|
|
||||||
|
(define (on-release handler)
|
||||||
|
(error 'on-release "must be run in JavaScript context"))
|
||||||
|
|
||||||
(define (key=? key-1 key-2)
|
(define (key=? key-1 key-2)
|
||||||
(error 'key=? "must be run in JavaScript context"))
|
(error 'key=? "must be run in JavaScript context"))
|
||||||
|
|
||||||
|
|
|
@ -743,7 +743,27 @@ var rawJsworld = {};
|
||||||
}
|
}
|
||||||
Jsworld.on_key = on_key;
|
Jsworld.on_key = on_key;
|
||||||
|
|
||||||
|
function on_release(release) {
|
||||||
|
return function() {
|
||||||
|
var wrappedRelease = function(e) {
|
||||||
|
preventDefault(e);
|
||||||
|
stopPropagation(e);
|
||||||
|
change_world(function(w, k) { release(w, e, k); }, doNothing);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
onRegister: function(top) {
|
||||||
|
//http://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribue
|
||||||
|
jQuery(top).attr('tabindex', 1);
|
||||||
|
jQuery(top).focus();
|
||||||
|
attachEvent(top, 'keyup', wrappedRelease);
|
||||||
|
},
|
||||||
|
onUnregister: function(top) {
|
||||||
|
detachEvent(top, 'keyup', wrappedRelease);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Jsworld.on_release = on_release;
|
||||||
|
|
||||||
|
|
||||||
// http://www.quirksmode.org/js/events_mouse.html
|
// http://www.quirksmode.org/js/events_mouse.html
|
||||||
|
|
Loading…
Reference in New Issue
Block a user