aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.coffee
diff options
context:
space:
mode:
authorStephen Blott2014-12-29 15:16:46 +0000
committerStephen Blott2014-12-29 15:16:46 +0000
commitba743054dcd26b225db407db261e480ab485e2d0 (patch)
tree60eb4400ee55a42fa9b3fecd60ab0893c62d3b53 /lib/utils.coffee
parent25473c3dea3d847d36bda9c56a190dd3b0e5a43f (diff)
parent5c750bb10104aeef8fff6131e24b2889619c3ab7 (diff)
downloadvimium-ba743054dcd26b225db407db261e480ab485e2d0.tar.bz2
Merge pull request #1384 from smblott-github/fix-search-custom-search-engine-support
Uniform treatment of search queries
Diffstat (limited to 'lib/utils.coffee')
-rw-r--r--lib/utils.coffee12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index b7f8731a..1bedb3d1 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -88,11 +88,17 @@ Utils =
# Fallback: no URL
return false
+ # Map a search query to its URL encoded form. The query may be either a string or an array of strings.
+ # E.g. "BBC Sport" -> "BBC+Sport".
+ createSearchQuery: (query) ->
+ query = query.split(/\s+/) if typeof(query) == "string"
+ query.map(encodeURIComponent).join "+"
+
# Creates a search URL from the given :query.
createSearchUrl: (query) ->
- # it would be better to pull the default search engine from chrome itself,
- # but it is not clear if/how that is possible
- Settings.get("searchUrl") + encodeURIComponent(query)
+ # It would be better to pull the default search engine from chrome itself. However, unfortunately chrome
+ # does not provide an API for doing so.
+ Settings.get("searchUrl") + @createSearchQuery query
# Converts :string into a Google search if it's not already a URL. We don't bother with escaping characters
# as Chrome will do that for us.