Permalink
Browse files

Added Blekko search.

  • Loading branch information...
1 parent 0136294 commit da033577ecc3facba13cdcbdc84b847c4699709a @nrs135 nrs135 committed with akoprow Feb 9, 2012
Showing with 450 additions and 24 deletions.
  1. +31 −13 editor.opa
  2. +1 −1 fb_login.opa
  3. +17 −1 parser.opa
  4. +374 −0 search.opa
  5. +27 −9 webshell.opa
View
@@ -7,10 +7,27 @@
client module Capture {
dhh = Reference.create({none});
- function set(fpress, fdown) {
+ function user_agent_to_bind_options(option(user_compat) user_agent) {
+ (list(Dom.event_option)) match (user_agent) {
+ case {some:ua}:
+ match (ua.renderer) {
+ case {Bot:_}: [];
+ case {Gecko:_}: [{stop_propagation}];
+ case {Trident:_}: [];
+ case {Webkit:_, variant:_}: [];
+ case {Nokia:_}: [];
+ case {Presto:_}: [{prevent_default}];
+ case {Unidentified}: [];
+ }
+ case {none}: [];
+ }
+ }
+
+ function set(option(user_compat) user_agent, fpress, fdown) {
doc = Dom.select_document();
- hpress = Dom.bind(doc, { keypress }, fpress);
- hdown = Dom.bind(doc, { keydown }, fdown);
+ options = user_agent_to_bind_options(user_agent);
+ hpress = Dom.bind_with_options(doc, { keypress }, fpress(_), options);
+ hdown = Dom.bind_with_options(doc, { keydown }, fdown(_), options);
Reference.set(dhh, { some: { ~doc, ~hpress, ~hdown}});
}
@@ -38,10 +55,10 @@ client module LineEditor {
void
}
- function init(selector, callback, echo) {
+ function init(option(user_compat) user_agent, selector, callback, echo) {
*selector = editor;
Scheduler.timer(blinking_delay, cursor_blink)
- Capture.set(evalKeyPress(echo, _), evalKeyDown(callback, _));
+ Capture.set(user_agent, evalKeyPress(echo, _), evalKeyDown(callback, _));
}
function get() {
@@ -52,14 +69,15 @@ client module LineEditor {
#precaret="";
#postcaret="";
}
-
- function evalKeyPress(echo, event) {
- match (event.key_code) {
- case {none}: #status = "KeyPress not captured";
- case {some: 13}: void;
- case {some: key}: #status = "Key: {key}"; addChar(echo, event, key);
- }
- }
+
+ function evalKeyPress(echo, event) {
+ match ((event.key_modifiers,event.key_code)) {
+ case (_,{none}): #status = "KeyPress not captured";
+ case ([],{some: 8}): void;
+ case ([],{some: 13}): void;
+ case (_,{some: key}): #status = "Key: {key}"; addChar(echo, event, key);
+ }
+ }
function evalKeyDown(callback, event) {
match (event.key_code) {
View
@@ -77,7 +77,7 @@ Please re-run your application with: --fb-config APP_ID,APP_SECRET")
case {~token}:
fb_user = { ~token, name: get_fb_name(token) }
{~fb_user}
- case {~error}: {guest}
+ case {error:_}: {guest}
}
}
View
@@ -4,6 +4,9 @@
client module Calc {
+ function int_of_string(string str) { (option(int)) Parser.try_parse(Rule.integer, str); }
+ function nat_of_string(string str) { (option(int)) Parser.try_parse(Rule.natural, str); }
+
function ws(p) {
parser
| Rule.ws res=p Rule.ws -> res
@@ -26,14 +29,27 @@ client module Calc {
| ~factor "-" ~expr -> factor - expr
| ~factor -> factor
+ search = ws(parser | "search" -> void)
+ set = ws(parser | "set" -> void)
+ next = ws(parser | "next" -> void)
+ prev = ws(parser | "prev" -> void)
+ page = ws(parser | "page" -> void)
+
+ args = parser | txt=(.*) -> List.map(String.trim,String.explode(" ",Text.to_string(txt)))
+
shell = parser
+ | search ~args -> { search:args }
+ | set ~args -> { set:args }
+ | next -> { next }
+ | prev -> { prev }
+ | page pagenum={ws(Rule.natural)} -> { ~pagenum }
| command={ws(Rule.ident)} arg={ws(Rule.ident)} -> { ~command, ~arg }
| ~expr -> {value: expr}
function compute(s) {
match (Parser.try_parse(expr, s)) {
case {some: result}: "{result}";
case {none}: "unknown";
- }
+ }
}
}
Oops, something went wrong.

0 comments on commit da03357

Please sign in to comment.