Modified page_fragment_load_spec to use the document URI rather than base URI.
[conkeror.git] / modules / minibuffer-read-option.js
blob7dcabb1e36b3e8c8a397ff8ea8f907e249d4f737
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  * (C) Copyright 2009 John J. Foerch
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 require("minibuffer-read.js");
11 function or_string(options) {
12     return options.slice(0,options.length-1).join(", ") + " or " + options[options.length - 1];
15 define_keywords("$options");
16 minibuffer.prototype.read_explicit_option = function () {
17     keywords(arguments);
18     var options = arguments.$options;
19     var options_string = or_string(options);
20     var result = yield this.read(forward_keywords(arguments),
21         $prompt = arguments.$prompt + " (" + options_string + ")",
22         $validator = function (x, m) {
23             if (options.indexOf(x) == -1) {
24                 m.message("Please answer " + options_string + ".");
25                 m._input_text = "";
26                 m._set_selection();
27                 return false;
28             }
29             return true;
30         });
31     yield co_return(result);
34 minibuffer.prototype.read_yes_or_no = function () {
35     keywords(arguments);
36     var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
37     yield co_return(result == "yes");
40 function single_character_options_minibuffer_state (window, continuation) {
41     keywords(arguments);
42     this.continuation = continuation;
43     this.options = arguments.$options;
44     minibuffer_input_state.call(this, window, single_character_options_minibuffer_keymap, arguments.$prompt);
46 single_character_options_minibuffer_state.prototype = {
47     __proto__: minibuffer_input_state.prototype,
48     destroy: function (window) {
49         if (this.continuation)
50             this.continuation.throw(abort());
51         minibuffer_input_state.prototype.destroy.call(this, window);
52     }
54 function single_character_options_enter_character(window, s, event) {
55     var ch = String.fromCharCode(event.charCode);
56     if (s.options.indexOf(ch) != -1) {
57         var c = s.continuation;
58         delete s.continuation;
59         window.minibuffer.pop_state();
60         if (c)
61             c(ch);
62         return;
63     }
64     var str = "Please answer " + or_string(s.options) + ".";
65     window.minibuffer.message(str);
68 interactive("single-character-options-enter-character", null,
69             function (I) {
70                 single_character_options_enter_character(
71                     I.window,
72                     I.minibuffer.check_state(single_character_options_minibuffer_state),
73                     I.event);
74             });
76 minibuffer.prototype.read_single_character_option = function () {
77     keywords(arguments);
78     var s = new single_character_options_minibuffer_state(this.window, (yield CONTINUATION), forward_keywords(arguments));
79     this.push_state(s);
80     var result = yield SUSPEND;
81     yield co_return(result);