Skip to content

A self-hosted dashboard that puts all your feeds in one place

Add target property to search widget

Svilen Markovea04aec0b4ef
diff --git a/docs/configuration.md b/docs/configuration.md
index 3999d8c..b8121f0 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -958,6 +958,7 @@ Preview:
| search-engine | string | no | duckduckgo |
| new-tab | boolean | no | false |
| autofocus | boolean | no | false |
+| target | string | no | _blank |
| placeholder | string | no | Type here to search… |
| bangs | array | no | |
@@ -975,6 +976,9 @@ When set to `true`, swaps the shortcuts for showing results in the same or new t
##### `autofocus`
When set to `true`, automatically focuses the search input on page load.
+##### `target`
+The target to use when opening the search results in a new tab. Possible values are `_blank`, `_self`, `_parent` and `_top`.
+
##### `placeholder`
When set, modifies the text displayed in the input field before typing.
diff --git a/internal/glance/static/js/main.js b/internal/glance/static/js/main.js
index 41d2ae3..dca713b 100644
--- a/internal/glance/static/js/main.js
+++ b/internal/glance/static/js/main.js
@@ -104,6 +104,7 @@ function setupSearchBoxes() {
for (let i = 0; i < searchWidgets.length; i++) {
const widget = searchWidgets[i];
const defaultSearchUrl = widget.dataset.defaultSearchUrl;
+ const target = widget.dataset.target || "_blank";
const newTab = widget.dataset.newTab === "true";
const inputElement = widget.getElementsByClassName("search-input")[0];
const bangElement = widget.getElementsByClassName("search-bang")[0];
@@ -143,7 +144,7 @@ function setupSearchBoxes() {
const url = searchUrlTemplate.replace("!QUERY!", encodeURIComponent(query));
if (newTab && !event.ctrlKey || !newTab && event.ctrlKey) {
- window.open(url, '_blank').focus();
+ window.open(url, target).focus();
} else {
window.location.href = url;
}
diff --git a/internal/glance/templates/search.html b/internal/glance/templates/search.html
index 6e8fc43..ae981c6 100644
--- a/internal/glance/templates/search.html
+++ b/internal/glance/templates/search.html
@@ -3,7 +3,7 @@
{{ define "widget-content-classes" }}widget-content-frameless{{ end }}
{{ define "widget-content" }}
-<div class="search widget-content-frame padding-inline-widget flex gap-15 items-center" data-default-search-url="{{ .SearchEngine }}" data-new-tab="{{ .NewTab }}">
+<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 }}">
<div class="search-bangs">
{{ range .Bangs }}
<input type="hidden" data-shortcut="{{ .Shortcut }}" data-title="{{ .Title }}" data-url="{{ .URL }}">
diff --git a/internal/glance/widget-search.go b/internal/glance/widget-search.go
index 9d2b600..f7da868 100644
--- a/internal/glance/widget-search.go
+++ b/internal/glance/widget-search.go
@@ -20,6 +20,7 @@ type searchWidget struct {
SearchEngine string `yaml:"search-engine"`
Bangs []SearchBang `yaml:"bangs"`
NewTab bool `yaml:"new-tab"`
+ Target string `yaml:"target"`
Autofocus bool `yaml:"autofocus"`
Placeholder string `yaml:"placeholder"`
}