Debian package: Support waterfox as alternative to old firefoxes and iceweasels
[conkeror.git] / contrib / modules / mode-line-buttons.js
blobcfbf6e2cda27596158ff50b0bef9c08d2e122280
1 /**
2 * (C) Copyright 2009 David Kettler
4 * Use, modification, and distribution are subject to the terms specified in the
5 * COPYING file.
6 **/
8 require("mode-line.js");
10 function button_widget (window) {
11 this.class_name = "button-widget";
12 text_widget.call(this, window);
14 button_widget.prototype = {
15 constructor: button_widget,
16 __proto__: text_widget.prototype,
18 make_element: function (window) {
19 var command = this.command;
20 var element = create_XUL(window, "image");
22 element.addEventListener("click", function (event) {
23 var I = new interactive_context(window.buffers.current);
24 co_call(call_interactively(I, command));
25 }, false);
27 element.addEventListener("mouseover", function (event) {
28 var msg = "Button: " + command;
29 var keymaps = get_current_keymaps(window);
30 var list = keymap_lookup_command(keymaps, command);
31 if (list.length)
32 msg += " (which is on key " + list.join(", ") + ")";
33 window.minibuffer.show(msg);
34 }, false);
36 element.addEventListener("mouseout", function (event) {
37 window.minibuffer.show("");
38 }, false);
40 element.setAttribute("id", "button-widget-" + command);
41 element.setAttribute("class", this.class_name);
42 for (var a in this.attributes) {
43 element.setAttribute(a, this.attributes[a]);
46 return element;
50 function make_button_widget (command, attributes) {
51 if (typeof attributes == "string")
52 // Simple case
53 attributes = { src: "moz-icon://stock/gtk-" + attributes };
55 function new_widget (window) {
56 button_widget.call(this, window);
58 new_widget.prototype = {
59 constructor: new_widget,
60 __proto__: button_widget.prototype,
61 command: command,
62 attributes: attributes
64 new_widget.mode_line_adder = function (window) {
65 var widget = new new_widget(window);
66 window.mode_line.add_widget(widget, widget.make_element(window));
69 return new_widget;
72 function mode_line_add_buttons (buttons, prepend) {
73 for (var i = 0, n = buttons.length; i < n; i++) {
74 var j = prepend ? n - i - 1 : i;
75 var w = make_button_widget(buttons[j][0], buttons[j][1]);
76 add_hook("mode_line_hook", mode_line_adder(w), prepend);
80 standard_mode_line_buttons = [
81 ["find-url", "open"],
82 ["find-url-new-buffer", "new"],
83 ["back", "go-back"],
84 ["forward", "go-forward"],
85 ["reload", "refresh"],
86 ["kill-current-buffer", "close"],
87 ["buffer-previous", "go-up"],
88 ["buffer-next", "go-down"],
89 ["help-page", "help"],
92 provide("mode-line-buttons");