aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-05-05 16:28:28 -0700
committerPhil Crosby2012-05-05 18:32:14 -0700
commitb7d445c74b188077898779103c4fa951fab17b66 (patch)
tree95faa823e206926d958a45746629226c4dda17e8
parent00cdb82cdd025a8d246073330d9970563d1676cb (diff)
downloadvimium-b7d445c74b188077898779103c4fa951fab17b66.tar.bz2
Make createActionOpenUrl be a simple function.
-rw-r--r--fuzzyMode.js29
-rw-r--r--lib/utils.js11
2 files changed, 25 insertions, 15 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js
index f4bc2357..31911c91 100644
--- a/fuzzyMode.js
+++ b/fuzzyMode.js
@@ -186,7 +186,7 @@ var fuzzyMode = (function() {
if (msg.id != id) return;
callback(msg.results.map(function(result) {
var action = result.action;
- result.action = eval(action.func).apply(null, action.args);
+ result.action = eval(action.func).curry(action.args);
return result;
}));
});
@@ -195,23 +195,22 @@ var fuzzyMode = (function() {
});
/** Creates an action that opens :url in the current tab by default or in a new tab as an alternative. */
- function createActionOpenUrl(url) {
- return function(openInNewTab) {
- // If the URL is a bookmarklet prefixed with javascript:, we don't need to open that in a new tab.
- if (url.indexOf("javascript:") == 0)
- openInNewTab = false;
- var selected = openInNewTab;
- chrome.extension.sendRequest({
- handler: openInNewTab ? "openUrlInNewTab" : "openUrlInCurrentTab",
- url: url,
- selected: openInNewTab
- });
- };
+ function createActionOpenUrl(url, openInNewTab) {
+ console.log("arguments:", arguments);
+ // If the URL is a bookmarklet prefixed with javascript:, we don't need to open that in a new tab.
+ if (url.indexOf("javascript:") == 0)
+ openInNewTab = false;
+ var selected = openInNewTab;
+ chrome.extension.sendRequest({
+ handler: openInNewTab ? "openUrlInNewTab" : "openUrlInCurrentTab",
+ url: url,
+ selected: openInNewTab
+ });
}
/** Returns an action that switches to the tab with the given :id. */
- function createActionSwitchToTab(id) {
- return function() { chrome.extension.sendRequest({ handler: "selectSpecificTab", id: id }); };
+ function createActionSwitchToTab(tabId) {
+ chrome.extension.sendRequest({ handler: "selectSpecificTab", id: tabId });
}
diff --git a/lib/utils.js b/lib/utils.js
index a5887e89..ab44e43f 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -166,6 +166,17 @@ Function.prototype.proxy = function(self) {
};
/*
+ * This creates a new function out of an existing function, where the new function takes fewer arguments.
+ * This allows us to pass around functions instead of functions + a partial list of arguments.
+ */
+Function.prototype.curry = function(fixedArguments) {
+ var fn = this;
+ return function() { return fn.apply(this, fixedArguments.concat(Array.copy(arguments))); };
+};
+
+Array.copy = function(array) { return Array.prototype.slice.call(array, 0); };
+
+/*
* Simple JavaScript Inheritance, by John Resig.
* This provides a short syntax for organizing code into classes.
* Taken from http://ejohn.org/blog/simple-javascript-inheritance/.