From 69ea703f584f65c962fb04fcae7bb6500a11b76a Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sat, 21 Jan 2012 04:00:12 +0100 Subject: allow custom functions as commands, add example in form of forced web search --- lib/completion.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/completion.js b/lib/completion.js index 2b29258f..6e8ea803 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -246,10 +246,17 @@ var completion = (function() { var term = query.slice(key.length, query.length); var command = commands[key]; var desc = command[0]; - var urlPattern = command[1]; + var pattern = command[1]; + var url; + + if (typeof pattern === 'function') + url = pattern(term); + else + url = pattern.replace(/%s/g, term); + suggestions.push({ render: createConstantFunction('' + desc + ' ' + term), - action: createActionOpenUrl(utils.createFullUrl(urlPattern.replace(/%s/g, term))), + action: createActionOpenUrl(utils.createFullUrl(url)), }); } } -- cgit v1.2.3