Commit d497e992 authored by Clément's avatar Clément

check document contain view

parent a2f33089
<script>
(function(){
class SIBRoute extends HTMLElement {
constructor() {
super()
this.name = this.name;
}
connectedCallback() {
this.addEventListener('click', event => this.router.navigate(this.name));
}
......@@ -10,6 +14,10 @@
}
set name(name) {
this.setAttribute('name', name);
this.view = document.getElementById(this.name);
if(!this.view) {
throw new Error(`view "#${this.name}" is not in document`);
}
}
get router() {
return this.closest('sib-router');
......@@ -26,11 +34,11 @@
id = id.replace(this.getAttribute('id-prefix'), '');
return [prefix, name, id].filter(s=>s).join('/');
}
updateResource(view) {
updateResource() {
if(this.resourceId) {
if(view.hasAttribute('bind-resources'))
view.setAttribute('data-src', this.resourceId);
for(let element of view.querySelectorAll('[bind-resources]'))
if(this.view.hasAttribute('bind-resources'))
this.view.setAttribute('data-src', this.resourceId);
for(let element of this.view.querySelectorAll('[bind-resources]'))
element.setAttribute('data-src', this.resourceId);
}
}
......@@ -39,20 +47,16 @@
router.display();
}
activate() {
const view = document.getElementById(this.name);
if(view) {
view.style.display = 'block';
this.setAttribute('active', '');
this.updateResource(view);
// Reseting all routers within the selected view
for(let router of view.querySelectorAll('sib-router'))
this.updateSubrouter(router);
}
this.view.style.display = 'block';
this.setAttribute('active', '');
this.updateResource();
// Reseting all routers within the selected view
for(let router of this.view.querySelectorAll('sib-router'))
this.updateSubrouter(router);
}
hide() {
const view = document.getElementById(this.name);
view.style.display = 'none';
this.view.style.display = 'none';
this.removeAttribute('active');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment