From ea04aec0b4efafe965ee8083dc5b525013367f88 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Tue, 22 Apr 2025 23:07:07 +0100 Subject: [PATCH] Add target property to search widget --- docs/configuration.md | 4 ++++ internal/glance/static/js/main.js | 3 ++- internal/glance/templates/search.html | 2 +- internal/glance/widget-search.go | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) 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" }} -