mirror of
https://github.com/Lissy93/dashy.git
synced 2025-12-06 08:34:14 +01:00
Merge pull request #1947 from pwhelan/custom-search-opening-method
Add opening method option for custom search widget.
This commit is contained in:
commit
10d8559ccc
2 changed files with 23 additions and 3 deletions
|
|
@ -1491,6 +1491,7 @@ Allows web search using multiple user-defined search engines and other websites.
|
|||
--- | --- | --- | ---
|
||||
**`engines`** | `array` | required | An array of search engine objects. Each search engine object should have two required properties: **title** and **url**. See the example below.
|
||||
**`placeholder`** | `string` | optional | Placeholder text in the search box.
|
||||
**`openingMethod`** | `string` | optional | Open search in one of `newtab`, `sametab` or `workspace`.
|
||||
|
||||
#### Notes
|
||||
- The first search engine in the engines array will be treated as the default search engine, and used when the user presses `Enter` in the search box.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<div class="buttons">
|
||||
<button
|
||||
v-for="(engine, key) in engines" :key="key"
|
||||
v-on:click="search(engine)">
|
||||
v-on:click="search(engine, openingMethod)">
|
||||
{{ engine.title }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -15,7 +15,9 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import router from '@/router';
|
||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||
import ErrorHandler from '@/utils/ErrorHandler';
|
||||
|
||||
export default {
|
||||
mixins: [WidgetMixin],
|
||||
|
|
@ -35,11 +37,28 @@ export default {
|
|||
defaultEngine() {
|
||||
return this.engines[0];
|
||||
},
|
||||
openingMethod() {
|
||||
return this.options.openingMethod || '';
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
search(engine) {
|
||||
search(engine, openingMethod) {
|
||||
if (engine !== undefined && this.query !== '') {
|
||||
window.open(engine.url + this.query, '_blank');
|
||||
const url = engine.url + this.query;
|
||||
switch (openingMethod) {
|
||||
case 'newtab':
|
||||
window.open(url, '_blank');
|
||||
break;
|
||||
case 'sametab':
|
||||
window.open(url, '_self');
|
||||
break;
|
||||
case 'workspace':
|
||||
router.push({ name: 'workspace', query: { url } });
|
||||
break;
|
||||
default:
|
||||
ErrorHandler(`Unknown opening method: ${openingMethod}`);
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue