From 00573389c63cebb42c225e10786aeb05e72fab39 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 3 Jan 2015 10:02:07 +0000 Subject: Modes; add SingletonMode. --- content_scripts/mode.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'content_scripts') 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 -- cgit v1.2.3