aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-01-03 10:02:07 +0000
committerStephen Blott2015-01-03 10:02:07 +0000
commit00573389c63cebb42c225e10786aeb05e72fab39 (patch)
treefdde26865ad01cc65c4cedd3d0a9200a9c1daba5 /content_scripts
parent734d16a457c0f18edcf3c951752f5e16ed2199e9 (diff)
downloadvimium-00573389c63cebb42c225e10786aeb05e72fab39.tar.bz2
Modes; add SingletonMode.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode.coffee16
1 files changed, 16 insertions, 0 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index f411d29b..8041f462 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -76,5 +76,21 @@ class Mode
func()
mode.exit()
+# A SingletonMode is a Mode of which there may be at most one instance of the same name (@singleton) active at
+# any one time. New instances cancel previous instances on startup.
+class SingletonMode extends Mode
+ constructor: (@singleton, options) ->
+ @cancel @singleton
+ super options
+
+ @instances: {}
+
+ cancel: (instance) ->
+ SingletonMode[instance].exit() if SingletonMode[instance]
+
+ exit: ->
+ delete SingletonMode[@instance]
+ super()
+
root = exports ? window
root.Mode = Mode