File: vomnibar.js

package info (click to toggle)
vimium 2.1.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,212 kB
  • sloc: javascript: 12,766; makefile: 7
file content (81 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// This wraps the vomnibar iframe, which we inject into the page to provide the vomnibar.
//
const Vomnibar = {
  vomnibarUI: null,

  // sourceFrameId here (and below) is the ID of the frame from which this request originates, which
  // may be different from the current frame.

  activate(sourceFrameId, registryEntry) {
    const options = Object.assign({}, registryEntry.options, { completer: "omni" });
    this.open(sourceFrameId, options);
  },

  activateInNewTab(sourceFrameId, registryEntry) {
    const options = Object.assign({}, registryEntry.options, { completer: "omni", newTab: true });
    this.open(sourceFrameId, options);
  },

  activateTabSelection(sourceFrameId) {
    this.open(sourceFrameId, {
      completer: "tabs",
      selectFirst: true,
    });
  },

  activateBookmarks(sourceFrameId) {
    this.open(sourceFrameId, {
      completer: "bookmarks",
      selectFirst: true,
    });
  },

  activateBookmarksInNewTab(sourceFrameId) {
    this.open(sourceFrameId, {
      completer: "bookmarks",
      selectFirst: true,
      newTab: true,
    });
  },

  activateEditUrl(sourceFrameId) {
    this.open(sourceFrameId, {
      completer: "omni",
      selectFirst: false,
      query: window.location.href,
    });
  },

  activateEditUrlInNewTab(sourceFrameId) {
    this.open(sourceFrameId, {
      completer: "omni",
      selectFirst: false,
      query: window.location.href,
      newTab: true,
    });
  },

  init() {
    if (!this.vomnibarUI) {
      this.vomnibarUI = new UIComponent("pages/vomnibar.html", "vomnibarFrame", function () {});
    }
  },

  // Opens the vomnibar.
  // - options: a map with values
  //     completer   - The name of the completer to fetch results from.
  //     query       - Optional. Text to prefill the Vomnibar with.
  //     selectFirst - Optional, boolean. Whether to select the first entry.
  //     newTab      - Optional, boolean. Whether to open the result in a new tab.
  open(sourceFrameId, options) {
    this.init();
    // The Vomnibar cannot coexist with the help dialog (it causes focus issues).
    HelpDialog.abort();
    this.vomnibarUI.activate(
      Object.assign(options, { name: "activate", sourceFrameId, focus: true }),
    );
  },
};

window.Vomnibar = Vomnibar;