Add facilities for querying information about installed extensions
[conkeror.git] / modules / mode.js
blob20552d79314ae768b4b6628eedbf752bcca6826e
2 require("interactive.js");
4 function define_global_mode(name, enable, disable)
6     var hyphen_name = name.replace("_","-","g");
7     var state = name + "_enabled";
8     this[state] = false;
9     var enable_hook_name = hyphen_name + "-enable-hook";
10     var disable_hook_name = hyphen_name + "-disable-hook";
11     define_hook(enable_hook_name);
12     define_hook(disable_hook_name);
13     var func = function (arg) {
14         var curstate = conkeror[state];
15         var newstate = (arg == null) ? !curstate : (arg > 0);
16         if (curstate == newstate)
17             return;
18         conkeror[state] = newstate;
19         if (newstate) {
20             enable();
21             conkeror[enable_hook_name].run();
22         } else {
23             disable();
24             conkeror[disable_hook_name].run();
25         }
26     };
27     this[name] = func;
28     interactive(hyphen_name, function (I) {
29         var arg = I.P;
30         func(arg && univ_arg_to_number(arg));
31         I.minibuffer.message(hyphen_name + (conkeror[state] ? " enabled" : " disabled"));
32     });
34 ignore_function_for_get_caller_source_code_reference("define_global_mode");