mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-22 10:51:24 +02:00
Add target property to search widget
This commit is contained in:
parent
b8e2717faf
commit
ea04aec0b4
@ -958,6 +958,7 @@ Preview:
|
|||||||
| search-engine | string | no | duckduckgo |
|
| search-engine | string | no | duckduckgo |
|
||||||
| new-tab | boolean | no | false |
|
| new-tab | boolean | no | false |
|
||||||
| autofocus | boolean | no | false |
|
| autofocus | boolean | no | false |
|
||||||
|
| target | string | no | _blank |
|
||||||
| placeholder | string | no | Type here to search… |
|
| placeholder | string | no | Type here to search… |
|
||||||
| bangs | array | no | |
|
| bangs | array | no | |
|
||||||
|
|
||||||
@ -975,6 +976,9 @@ When set to `true`, swaps the shortcuts for showing results in the same or new t
|
|||||||
##### `autofocus`
|
##### `autofocus`
|
||||||
When set to `true`, automatically focuses the search input on page load.
|
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`
|
##### `placeholder`
|
||||||
When set, modifies the text displayed in the input field before typing.
|
When set, modifies the text displayed in the input field before typing.
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ function setupSearchBoxes() {
|
|||||||
for (let i = 0; i < searchWidgets.length; i++) {
|
for (let i = 0; i < searchWidgets.length; i++) {
|
||||||
const widget = searchWidgets[i];
|
const widget = searchWidgets[i];
|
||||||
const defaultSearchUrl = widget.dataset.defaultSearchUrl;
|
const defaultSearchUrl = widget.dataset.defaultSearchUrl;
|
||||||
|
const target = widget.dataset.target || "_blank";
|
||||||
const newTab = widget.dataset.newTab === "true";
|
const newTab = widget.dataset.newTab === "true";
|
||||||
const inputElement = widget.getElementsByClassName("search-input")[0];
|
const inputElement = widget.getElementsByClassName("search-input")[0];
|
||||||
const bangElement = widget.getElementsByClassName("search-bang")[0];
|
const bangElement = widget.getElementsByClassName("search-bang")[0];
|
||||||
@ -143,7 +144,7 @@ function setupSearchBoxes() {
|
|||||||
const url = searchUrlTemplate.replace("!QUERY!", encodeURIComponent(query));
|
const url = searchUrlTemplate.replace("!QUERY!", encodeURIComponent(query));
|
||||||
|
|
||||||
if (newTab && !event.ctrlKey || !newTab && event.ctrlKey) {
|
if (newTab && !event.ctrlKey || !newTab && event.ctrlKey) {
|
||||||
window.open(url, '_blank').focus();
|
window.open(url, target).focus();
|
||||||
} else {
|
} else {
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{{ define "widget-content-classes" }}widget-content-frameless{{ end }}
|
{{ define "widget-content-classes" }}widget-content-frameless{{ end }}
|
||||||
|
|
||||||
{{ define "widget-content" }}
|
{{ 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">
|
<div class="search-bangs">
|
||||||
{{ range .Bangs }}
|
{{ range .Bangs }}
|
||||||
<input type="hidden" data-shortcut="{{ .Shortcut }}" data-title="{{ .Title }}" data-url="{{ .URL }}">
|
<input type="hidden" data-shortcut="{{ .Shortcut }}" data-title="{{ .Title }}" data-url="{{ .URL }}">
|
||||||
|
@ -20,6 +20,7 @@ type searchWidget struct {
|
|||||||
SearchEngine string `yaml:"search-engine"`
|
SearchEngine string `yaml:"search-engine"`
|
||||||
Bangs []SearchBang `yaml:"bangs"`
|
Bangs []SearchBang `yaml:"bangs"`
|
||||||
NewTab bool `yaml:"new-tab"`
|
NewTab bool `yaml:"new-tab"`
|
||||||
|
Target string `yaml:"target"`
|
||||||
Autofocus bool `yaml:"autofocus"`
|
Autofocus bool `yaml:"autofocus"`
|
||||||
Placeholder string `yaml:"placeholder"`
|
Placeholder string `yaml:"placeholder"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user