Commit 2d78d30a authored by Clément's avatar Clément

feature: Add a data-src to sib-link

parent d44e9c0c
......@@ -74,7 +74,9 @@
constructor() {
super();
window.addEventListener('popstate', event => this.display());
window.addEventListener('requestNavigation', event => this.navigate(event.detail.route, event.detail.resource));
window.addEventListener('requestNavigation', event => {
this.navigate(event.detail.route, event.detail.resource);
})
window.addEventListener('WebComponentsReady', event => this.display());
}
get useHash() {
......@@ -113,20 +115,20 @@
else
route.hide();
}
navigate(name, resource) {
name = name || '';// of the route
const route = this.querySelector('sib-route[name='+name+']');
navigate(routeName = '', resource) {
const route = this.querySelector('sib-route[name='+routeName+']');
if(!route) return; //this route is not for me!
const id = resource ? resource['@id'] : null;
const path = route.getPath(this.prefix, routeName, id)
route.getPath(this.prefix, routeName, id);
//update current URL
if(this.useHash)
window.location.hash = route.getPath(this.prefix, name, id);
window.location.hash = path;
else
history.pushState({}, name, '/' + route.getPath(this.prefix, name, id));
this.dispatchEvent(new CustomEvent('navigate', {detail: {route: name, resource: resource}}));
this.display(name);
history.pushState({}, routeName, '/' + path);
this.dispatchEvent(new CustomEvent('navigate', {detail: {route: routeName, resource: resource}}));
this.display(routeName);
}
}
......@@ -138,15 +140,14 @@
super();
this.addEventListener('click', event => this.trigger());
}
get next() {
return this.getAttribute('next');
}
trigger() {
if (!this.next) return
const route = this.getAttribute('next')
const resource = this.dataset.src && { '@id': this.dataset.src }
if(!route && !resource) return;
this.dispatchEvent(
new CustomEvent('requestNavigation', {
bubbles: true,
detail: { route: this.next },
detail: { route, resource },
}),
);
}
......
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