Skip to content

Commit ea04aec

Browse files
committed
Add target property to search widget
1 parent b8e2717 commit ea04aec

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ Preview:
958958
| search-engine | string | no | duckduckgo |
959959
| new-tab | boolean | no | false |
960960
| autofocus | boolean | no | false |
961+
| target | string | no | _blank |
961962
| placeholder | string | no | Type here to search… |
962963
| bangs | array | no | |
963964

@@ -975,6 +976,9 @@ When set to `true`, swaps the shortcuts for showing results in the same or new t
975976
##### `autofocus`
976977
When set to `true`, automatically focuses the search input on page load.
977978

979+
##### `target`
980+
The target to use when opening the search results in a new tab. Possible values are `_blank`, `_self`, `_parent` and `_top`.
981+
978982
##### `placeholder`
979983
When set, modifies the text displayed in the input field before typing.
980984

internal/glance/static/js/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function setupSearchBoxes() {
104104
for (let i = 0; i < searchWidgets.length; i++) {
105105
const widget = searchWidgets[i];
106106
const defaultSearchUrl = widget.dataset.defaultSearchUrl;
107+
const target = widget.dataset.target || "_blank";
107108
const newTab = widget.dataset.newTab === "true";
108109
const inputElement = widget.getElementsByClassName("search-input")[0];
109110
const bangElement = widget.getElementsByClassName("search-bang")[0];
@@ -143,7 +144,7 @@ function setupSearchBoxes() {
143144
const url = searchUrlTemplate.replace("!QUERY!", encodeURIComponent(query));
144145

145146
if (newTab && !event.ctrlKey || !newTab && event.ctrlKey) {
146-
window.open(url, '_blank').focus();
147+
window.open(url, target).focus();
147148
} else {
148149
window.location.href = url;
149150
}

internal/glance/templates/search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{ define "widget-content-classes" }}widget-content-frameless{{ end }}
44

55
{{ define "widget-content" }}
6-
<div class="search widget-content-frame padding-inline-widget flex gap-15 items-center" data-default-search-url="{{ .SearchEngine }}" data-new-tab="{{ .NewTab }}">
6+
<div class="search widget-content-frame padding-inline-widget flex gap-15 items-center" data-default-search-url="{{ .SearchEngine }}" data-new-tab="{{ .NewTab }}" data-target="{{ .Target }}">
77
<div class="search-bangs">
88
{{ range .Bangs }}
99
<input type="hidden" data-shortcut="{{ .Shortcut }}" data-title="{{ .Title }}" data-url="{{ .URL }}">

internal/glance/widget-search.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type searchWidget struct {
2020
SearchEngine string `yaml:"search-engine"`
2121
Bangs []SearchBang `yaml:"bangs"`
2222
NewTab bool `yaml:"new-tab"`
23+
Target string `yaml:"target"`
2324
Autofocus bool `yaml:"autofocus"`
2425
Placeholder string `yaml:"placeholder"`
2526
}

0 commit comments

Comments
 (0)