aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorJez Ng2012-08-04 14:02:10 -0700
committerJez Ng2012-08-04 14:02:10 -0700
commita6116da5a03237fb1a3718060d972f1992618a99 (patch)
treec80c2b370da350014df2ab370941b056a2420e98 /background_scripts
parent6043f25b8dcbba3a522df4ddf59e1070fdc134e5 (diff)
downloadvimium-a6116da5a03237fb1a3718060d972f1992618a99.tar.bz2
Improve encapsulation of Settings.
We should eventually do this for the other modules as well.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/settings.coffee113
1 files changed, 55 insertions, 58 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index af0f8f16..72fffe7a 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -1,66 +1,15 @@
#
# Used by everyone to manipulate localStorage.
#
-Settings =
- defaults:
- scrollStepSize: 60
- linkHintCharacters: "sadfjklewcmpgh"
- filterLinkHints: false
- hideHud: false
- userDefinedLinkHintCss:
- """
- div > .vimiumHintMarker {
- /* linkhint boxes */
- background-color: yellow;
- border: 1px solid #E3BE23;
- }
-
- div > .vimiumHintMarker span {
- /* linkhint text */
- color: black;
- font-weight: bold;
- font-size: 12px;
- }
-
- div > .vimiumHintMarker > .matchingCharacter {
- }
- """
- excludedUrls:
- """
- http*://mail.google.com/*
- http*://www.google.com/reader/*
- """
-
- # NOTE : If a page contains both a single angle-bracket link and a double angle-bracket link, then in
- # most cases the single bracket link will be "prev/next page" and the double bracket link will be
- # "first/last page", so we put the single bracket first in the pattern string so that it gets searched
- # for first.
-
- # "\bprev\b,\bprevious\b,\bback\b,<,←,«,≪,<<"
- previousPatterns: "prev,previous,back,<,\u2190,\xab,\u226a,<<"
- # "\bnext\b,\bmore\b,>,→,»,≫,>>"
- nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>"
-
- init: ->
- # settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use
- # previousVersion as it is used to coordinate the display of the upgrade message, and is not updated
- # early enough when the extension loads.
- # 1.31 was also the version where we converted all localStorage values to JSON.
- if (!this.has("settingsVersion"))
- for key of localStorage
- # filterLinkHints' checkbox state used to be stored as a string
- if (key == "filterLinkHints")
- localStorage[key] = if (localStorage[key] == "true") then true else false
- else
- localStorage[key] = JSON.stringify(localStorage[key])
- this.set("settingsVersion", Utils.getCurrentVersion())
+root = exports ? window
+root.Settings = Settings =
get: (key) ->
- if (key of localStorage) then JSON.parse(localStorage[key]) else this.defaults[key]
+ if (key of localStorage) then JSON.parse(localStorage[key]) else defaults[key]
set: (key, value) ->
# don't store the value if it is equal to the default, so we can change the defaults in the future
- if (value == this.defaults[key])
+ if (value == defaults[key])
this.clear(key)
else
localStorage[key] = JSON.stringify(value)
@@ -69,6 +18,54 @@ Settings =
has: (key) -> key of localStorage
-Settings.init()
-root = exports ? window
-root.Settings = Settings
+defaults =
+ scrollStepSize: 60
+ linkHintCharacters: "sadfjklewcmpgh"
+ filterLinkHints: false
+ hideHud: false
+ userDefinedLinkHintCss:
+ """
+ div > .vimiumHintMarker {
+ /* linkhint boxes */
+ background-color: yellow;
+ border: 1px solid #E3BE23;
+ }
+
+ div > .vimiumHintMarker span {
+ /* linkhint text */
+ color: black;
+ font-weight: bold;
+ font-size: 12px;
+ }
+
+ div > .vimiumHintMarker > .matchingCharacter {
+ }
+ """
+ excludedUrls:
+ """
+ http*://mail.google.com/*
+ http*://www.google.com/reader/*
+ """
+ # NOTE : If a page contains both a single angle-bracket link and a double angle-bracket link, then in
+ # most cases the single bracket link will be "prev/next page" and the double bracket link will be
+ # "first/last page", so we put the single bracket first in the pattern string so that it gets searched
+ # for first.
+
+ # "\bprev\b,\bprevious\b,\bback\b,<,←,«,≪,<<"
+ previousPatterns: "prev,previous,back,<,\u2190,\xab,\u226a,<<"
+ # "\bnext\b,\bmore\b,>,→,»,≫,>>"
+ nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>"
+
+# Initialization code.
+# settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use
+# previousVersion as it is used to coordinate the display of the upgrade message, and is not updated
+# early enough when the extension loads.
+# 1.31 was also the version where we converted all localStorage values to JSON.
+if (!Settings.has("settingsVersion"))
+ for key of localStorage
+ # filterLinkHints' checkbox state used to be stored as a string
+ if (key == "filterLinkHints")
+ localStorage[key] = if (localStorage[key] == "true") then true else false
+ else
+ localStorage[key] = JSON.stringify(localStorage[key])
+ Settings.set("settingsVersion", Utils.getCurrentVersion())