diff options
| author | Stephen Blott | 2015-01-03 10:02:07 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-03 10:02:07 +0000 |
| commit | 00573389c63cebb42c225e10786aeb05e72fab39 (patch) | |
| tree | fdde26865ad01cc65c4cedd3d0a9200a9c1daba5 /content_scripts/mode.coffee | |
| parent | 734d16a457c0f18edcf3c951752f5e16ed2199e9 (diff) | |
| download | vimium-00573389c63cebb42c225e10786aeb05e72fab39.tar.bz2 | |
Modes; add SingletonMode.
Diffstat (limited to 'content_scripts/mode.coffee')
| -rw-r--r-- | content_scripts/mode.coffee | 16 |
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 |
