summaryrefslogtreecommitdiff
path: root/common/content/bookmarks.js
diff options
context:
space:
mode:
authorKris Maglione <maglione.k@gmail.com>2011-02-22 10:01:56 -0500
committerKris Maglione <maglione.k@gmail.com>2011-02-22 10:01:56 -0500
commit8299257422e11ec7604efbc65f4d2bba365bfeee (patch)
treeac25440083dd76a469562e4858184e6042635e96 /common/content/bookmarks.js
parentd92f3f2c9c039b1bcb547171248e519ad53a4343 (diff)
downloadpentadactyl-8299257422e11ec7604efbc65f4d2bba365bfeee.tar.gz
Make Melodactyl minimally functional. Closes issue #340.
--HG-- rename : pentadactyl/chrome.manifest => common/chrome.manifest
Diffstat (limited to 'common/content/bookmarks.js')
-rw-r--r--common/content/bookmarks.js89
1 files changed, 41 insertions, 48 deletions
diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js
index cb411ba9..1e2c3138 100644
--- a/common/content/bookmarks.js
+++ b/common/content/bookmarks.js
@@ -263,63 +263,56 @@ var Bookmarks = Module("bookmarks", {
* @returns {[string, string | null] | null}
*/
getSearchURL: function getSearchURL(text, useDefsearch) {
- let searchString = (useDefsearch ? options["defsearch"] + " " : "") + text;
+ let query = (useDefsearch ? options["defsearch"] + " " : "") + text;
// ripped from Firefox
- function getShortcutOrURI(url) {
- var keyword = url;
- var param = "";
- var offset = url.indexOf(" ");
- if (offset > 0) {
- keyword = url.substr(0, offset);
- param = url.substr(offset + 1);
- }
+ var keyword = query;
+ var param = "";
+ var offset = query.indexOf(" ");
+ if (offset > 0) {
+ keyword = query.substr(0, offset);
+ param = query.substr(offset + 1);
+ }
- var engine = bookmarks.searchEngines[keyword];
- if (engine) {
- if (engine.searchForm && !param)
- return [engine.searchForm, null];
- let submission = engine.getSubmission(param, null);
- return [submission.uri.spec, submission.postData];
- }
+ var engine = bookmarks.searchEngines[keyword];
+ if (engine) {
+ if (engine.searchForm && !param)
+ return engine.searchForm;
+ let submission = engine.getSubmission(param, null);
+ return [submission.uri.spec, submission.postData];
+ }
- let [shortcutURL, postData] = PlacesUtils.getURLAndPostDataForKeyword(keyword);
- if (!shortcutURL)
- return [url, null];
- let bmark = bookmarkcache.keywords[keyword];
-
- let data = window.unescape(postData || "");
- if (/%s/i.test(shortcutURL) || /%s/i.test(data)) {
- var charset = "";
- var matches = shortcutURL.match(/^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/);
- if (matches)
- [, shortcutURL, charset] = matches;
- else
- try {
- charset = services.history.getCharsetForURI(util.newURI(shortcutURL));
- }
- catch (e) {}
- if (charset)
- var encodedParam = escape(window.convertFromUnicode(charset, param));
- else
- encodedParam = bmark.encodeURIComponent(param);
+ let [url, postData] = PlacesUtils.getURLAndPostDataForKeyword(keyword);
+ if (!url)
+ return null;
- shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param);
- if (/%s/i.test(data))
- postData = window.getPostDataStream(data, param, encodedParam, "application/x-www-form-urlencoded");
- }
- else if (param)
- return [shortcutURL, null];
- return [shortcutURL, postData];
- }
+ let data = window.unescape(postData || "");
+ if (/%s/i.test(url) || /%s/i.test(data)) {
+ var charset = "";
+ var matches = url.match(/^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/);
+ if (matches)
+ [, url, charset] = matches;
+ else
+ try {
+ charset = services.history.getCharsetForURI(util.newURI(url));
+ }
+ catch (e) {}
- let [url, postData] = getShortcutOrURI(searchString);
+ if (charset)
+ var encodedParam = escape(window.convertFromUnicode(charset, param));
+ else
+ encodedParam = bookmarkcache.keywords[keyword].encodeURIComponent(param);
+
+ url = url.replace(/%s/g, encodedParam).replace(/%S/g, param);
+ if (/%s/i.test(data))
+ postData = window.getPostDataStream(data, param, encodedParam, "application/x-www-form-urlencoded");
+ }
+ else if (param)
+ postData = null;
- if (url == searchString)
- return null;
if (postData)
return [url, postData];
- return url; // can be null
+ return url;
},
/**