-
Notifications
You must be signed in to change notification settings - Fork 1
/
sol-catalog-search.js
31 lines (25 loc) · 1.13 KB
/
sol-catalog-search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {getDefaults} from './utils/utils.js';
export class SolCatalogSearch extends HTMLElement {
constructor() {
super();
}
async connectedCallback(){
await getDefaults(this);
this.innerHTML = `<input type="text" /> <button>search</button>`;
this.querySelector('button').addEventListener('click',(event)=>{runSearch(event,this)});
this.querySelector('input').addEventListener('keypress',(event)=>{checkEnter(event,this)});
}
}
customElements.define("sol-catalog-search",SolCatalogSearch);
function checkEnter(event,element){
if(event.key==="Enter") return runSearch(event,element);
}
function runSearch(event,element){
event.preventDefault();
let source = element.source || element.closest('.sol-catalog').source;
let view = element.view || element.closest('.sol-catalog').view;
const currentLink = event.target;
const display = currentLink.closest('.sol-wrapper').querySelector('.sol-display');
const input = currentLink.parentNode.querySelector('input') || "";
if(input) display.innerHTML=`<sol-catalog-page source="${source}" view="${view}" wanted="${input.value}"></sol-catalog-page>`;
}