[Conkeror] [PATCH] webjumps: manage alternative url explicitly, not in handler functions

David Kettler kettler at internode.on.net
Wed Feb 18 03:57:19 PST 2009


If no arguments are supplied to a webjump and an alternative url is
available, then the webjump system will visit the alternative url.
Handler functions are no longer concerned with the alternative url.
---
 modules/search-engine.js |    5 +----
 modules/webjump.js       |   17 +++++++++--------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/modules/search-engine.js b/modules/search-engine.js
index 3836b01..51f8ffa 100644
--- a/modules/search-engine.js
+++ b/modules/search-engine.js
@@ -333,10 +333,7 @@ function define_search_engine_webjump(search_engine_name, key) {
 
     define_webjump(key,
                    function (arg) {
-                       if (arg == null && alternative)
-                           return alternative
-                       else
-                           return eng.get_query_load_spec(arg);
+                       return eng.get_query_load_spec(arg);
                    },
                    $alternative = alternative,
                    $description = eng.description,
diff --git a/modules/webjump.js b/modules/webjump.js
index e4b8456..7ca9c48 100644
--- a/modules/webjump.js
+++ b/modules/webjump.js
@@ -18,11 +18,11 @@ function define_webjump(key, handler) {
     // handler may be a function or a string.  An alternative url may
     // be passed using the $alternative keyword; it is used in place
     // of the handler when no arguments are supplied by the user when
-    // invoking the webjump.  For string webjumps that contain %s and
-    // for which no alternative is provided, an alternative is
-    // autogenerated by trimming the path from the url.  A webjump can
-    // thus function both as a way to invoke a search and as a
-    // bookmark.
+    // invoking the webjump (see getWebJump).  For string webjumps
+    // that contain %s and for which no alternative is provided, an
+    // alternative is autogenerated by trimming the path from the url.
+    // A webjump can thus function both as a way to invoke a search
+    // and as a bookmark.
     //
     // The argument property may be false (no arguments will be
     // accepted for the webjump), true (arguments are required for the
@@ -49,8 +49,6 @@ function define_webjump(key, handler) {
         var b = template.indexOf('%s');
         return function (arg) {
             var a = b + 2;
-            if (arg == null && alternative)
-                return alternative;
             // Just return the same string if it doesn't contain a %s
             if (b == -1)
                 return template;
@@ -65,7 +63,8 @@ function define_webjump(key, handler) {
                       handler: handler,
                       completer: arguments.$completer,
                       description: arguments.$description,
-                      argument: argument };
+                      argument: argument,
+                      alternative: alternative};
 }
 
 
@@ -181,6 +180,8 @@ function getWebJump(value)
     if (!res)
         return null;
     let [match,key,arg] = res;
+    if (arg == null && match.alternative)
+        return match.alternative;
     return match.handler(arg);
 }
 
-- 
1.5.6.5



More information about the Conkeror mailing list