diff options
| author | mike-work | 2014-05-07 23:57:56 +0100 |
|---|---|---|
| committer | mike-work | 2014-05-29 02:42:51 +0100 |
| commit | a18ad484f2fdc0019c15d94405c915f8bfe6d76f (patch) | |
| tree | 3a8667096504d09b85ac0cd1cf4135763c95e375 /background_scripts/settings.coffee | |
| parent | 1aa7ba3a5810742d14edfb738120b70f4a0f7619 (diff) | |
| download | vimium-a18ad484f2fdc0019c15d94405c915f8bfe6d76f.tar.bz2 | |
Adding in search engines feature to fix #1009
Diffstat (limited to 'background_scripts/settings.coffee')
| -rw-r--r-- | background_scripts/settings.coffee | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index c26da5a4..175f3262 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -32,10 +32,28 @@ root.Settings = Settings = root.Commands.parseCustomKeyMappings value root.refreshCompletionKeysAfterMappingSave() + searchEngines: (value) -> + root.Settings.parseSearchEngines value + # postUpdateHooks convenience wrapper performPostUpdateHook: (key, value) -> @postUpdateHooks[key] value if @postUpdateHooks[key] + # Here we have our functions that parse the search engines + # this is a map that we use to store our search engines for use. + searchEnginesMap: {} + + # this parses the search engines settings and clears the old searchEngines and sets the new one + parseSearchEngines: (searchEnginesText) -> + @searchEnginesMap = {} + # find the split pairs by first splitting by line then splitting on the first `: ` + split_pairs = ( pair.split( /: (.+)/, 2) for pair in searchEnginesText.split( /\n/ ) when pair[0] != "#" ) + @searchEnginesMap[a[0]] = a[1] for a in split_pairs + @searchEnginesMap + getSearchEngines: -> + this.parseSearchEngines(@get("searchEngines") || "") if Object.keys(@searchEnginesMap).length == 0 + @searchEnginesMap + # options.coffee and options.html only handle booleans and strings; therefore all defaults must be booleans # or strings defaults: @@ -78,9 +96,12 @@ root.Settings = Settings = nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>" # default/fall back search engine searchUrl: "http://www.google.com/search?q=" + # put in an example search engine + searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s" settingsVersion: Utils.getCurrentVersion() + # We use settingsVersion to coordinate any necessary schema changes. if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1 Settings.set("scrollStepSize", parseFloat Settings.get("scrollStepSize")) |
