mirror of
https://github.com/esiur/iui.git
synced 2026-04-04 06:58:22 +00:00
Add router base option and navigate to origin after on init
This commit is contained in:
@@ -3,86 +3,84 @@ import { IUI } from "../Core/IUI.js";
|
||||
import Router from "./Router.js";
|
||||
import RefsCollection from "../Core/RefsCollection.js";
|
||||
|
||||
export default IUI.module(class Route extends IUIElement {
|
||||
|
||||
export default IUI.module(
|
||||
class Route extends IUIElement {
|
||||
constructor() {
|
||||
super();
|
||||
super();
|
||||
|
||||
this.routes = [];
|
||||
this.refs = new RefsCollection(this);
|
||||
this.routes = [];
|
||||
this.refs = new RefsCollection(this);
|
||||
|
||||
this._register("show");
|
||||
this._register("hide");
|
||||
this._register("show");
|
||||
this._register("hide");
|
||||
}
|
||||
|
||||
async setData(value) {
|
||||
if (this.hasAttribute("debug"))
|
||||
debugger;
|
||||
if (this.hasAttribute("debug")) debugger;
|
||||
|
||||
return await super.setData(value);
|
||||
return await super.setData(value);
|
||||
}
|
||||
|
||||
get scope(){
|
||||
return {route: this, view: this};
|
||||
get scope() {
|
||||
return { route: this, view: this };
|
||||
}
|
||||
|
||||
_updateLinks() {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
if (this.children[i] instanceof Route) {
|
||||
this.routes.push(this.children[i]);
|
||||
window.router.add(this.children[i], this);
|
||||
i--;
|
||||
}
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
if (this.children[i] instanceof Route) {
|
||||
this.routes.push(this.children[i]);
|
||||
window.router.add(this.children[i], this);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get link() {
|
||||
var link = this.name;
|
||||
var parent = this.parent;
|
||||
while (parent != null) {
|
||||
link = parent.name + "/" + link;
|
||||
parent = parent.parent;
|
||||
}
|
||||
var link = this.name;
|
||||
var parent = this.parent;
|
||||
while (parent != null) {
|
||||
link = parent.name + "/" + link;
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
||||
return link;
|
||||
return (window.router.base ? window.router.base + "/" : "") + link;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.getAttribute("name");
|
||||
return this.getAttribute("name");
|
||||
}
|
||||
|
||||
get src() {
|
||||
return this.getAttribute("src");
|
||||
return this.getAttribute("src");
|
||||
}
|
||||
|
||||
get dst() {
|
||||
return this._dst || this.getAttribute("dst");
|
||||
return this._dst || this.getAttribute("dst");
|
||||
}
|
||||
|
||||
set dst(value){
|
||||
this._dst = value;
|
||||
set dst(value) {
|
||||
this._dst = value;
|
||||
}
|
||||
|
||||
|
||||
get caption() {
|
||||
return this.getAttribute("caption");
|
||||
return this.getAttribute("caption");
|
||||
}
|
||||
|
||||
get private() {
|
||||
return this.hasAttribute("private");
|
||||
return this.hasAttribute("private");
|
||||
}
|
||||
|
||||
get icon() {
|
||||
return this.getAttribute("icon");
|
||||
return this.getAttribute("icon");
|
||||
}
|
||||
|
||||
_getParent() {
|
||||
let e = null;//this.parentElement;
|
||||
while (e = this.parentElement) {
|
||||
if (e instanceof Route || e instanceof Router)
|
||||
return e;
|
||||
}
|
||||
let e = null; //this.parentElement;
|
||||
while ((e = this.parentElement)) {
|
||||
if (e instanceof Route || e instanceof Router) return e;
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// get route() {
|
||||
@@ -92,93 +90,85 @@ export default IUI.module(class Route extends IUIElement {
|
||||
// get view() {
|
||||
// return this;
|
||||
// }
|
||||
|
||||
|
||||
async create() {
|
||||
//window.router.add(this);
|
||||
this._updateLinks();
|
||||
|
||||
//window.router.add(this);
|
||||
this._updateLinks();
|
||||
if (this.hasAttribute("src")) {
|
||||
let src = this.getAttribute("src").replace(/^\/+|\/+$/g, "");
|
||||
let x = await fetch(src);
|
||||
if (x.status != 200) return;
|
||||
|
||||
if (this.hasAttribute("src")) {
|
||||
let t = await x.text();
|
||||
|
||||
let src = this.getAttribute("src").replace(/^\/+|\/+$/g, '');
|
||||
let x = await fetch(src);
|
||||
if (x.status != 200)
|
||||
return;
|
||||
|
||||
let t = await x.text();
|
||||
this.innerHTML = t;
|
||||
|
||||
this.innerHTML = t;
|
||||
|
||||
//let xeval = (code) => eval(code);
|
||||
}
|
||||
//let xeval = (code) => eval(code);
|
||||
}
|
||||
|
||||
|
||||
if (window?.app?.loaded)
|
||||
{
|
||||
await IUI.create(this);
|
||||
IUI.bind(this, true, "route:" + src, this.scope);
|
||||
this.refs._build();
|
||||
await IUI.created(this);
|
||||
await IUI.render(this, this._data, true);
|
||||
}
|
||||
|
||||
// // call create for the new elements
|
||||
// var newElements = this.querySelectorAll("*");
|
||||
// for (var i = 0; i < newElements.length; i++) {
|
||||
// // set route for all elements
|
||||
// var el = newElements[i];
|
||||
// // newElements[i].route = this;
|
||||
// el.view = this;
|
||||
// el.route = this;
|
||||
|
||||
// if (el.hasAttribute("ref")) {
|
||||
// this.refs[el.getAttribute("ref")] = el;
|
||||
// }
|
||||
|
||||
// if (el instanceof HTMLScriptElement) {
|
||||
// // this because HTML parsers don't evaluate script tag
|
||||
// // xeval.call(el.parentElement, "//# sourceURL=iui://" + src + "\r\n" + el.text);
|
||||
|
||||
// //let func = new Function("//# sourceURL=iui://" +
|
||||
// // src + "-" + Math.round(Math.random() * 10000) + "\r\n return " + el.text.trim());
|
||||
|
||||
// let func = new Function("//# sourceURL=iui://" + this.link
|
||||
// + "\r\n return " + el.text.trim());
|
||||
|
||||
// let rt = func.call(el.parentElement);
|
||||
|
||||
// if (typeof (rt) === "object") {
|
||||
// for (var k in rt)
|
||||
// el.parentElement[k] = rt[k];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
created()
|
||||
{
|
||||
if (window?.app?.loaded) {
|
||||
await IUI.create(this);
|
||||
IUI.bind(this, true, "route:" + src, this.scope);
|
||||
this.refs._build();
|
||||
await IUI.created(this);
|
||||
await IUI.render(this, this._data, true);
|
||||
}
|
||||
|
||||
// // call create for the new elements
|
||||
// var newElements = this.querySelectorAll("*");
|
||||
// for (var i = 0; i < newElements.length; i++) {
|
||||
// // set route for all elements
|
||||
// var el = newElements[i];
|
||||
// // newElements[i].route = this;
|
||||
// el.view = this;
|
||||
// el.route = this;
|
||||
|
||||
// if (el.hasAttribute("ref")) {
|
||||
// this.refs[el.getAttribute("ref")] = el;
|
||||
// }
|
||||
|
||||
// if (el instanceof HTMLScriptElement) {
|
||||
// // this because HTML parsers don't evaluate script tag
|
||||
// // xeval.call(el.parentElement, "//# sourceURL=iui://" + src + "\r\n" + el.text);
|
||||
|
||||
// //let func = new Function("//# sourceURL=iui://" +
|
||||
// // src + "-" + Math.round(Math.random() * 10000) + "\r\n return " + el.text.trim());
|
||||
|
||||
// let func = new Function("//# sourceURL=iui://" + this.link
|
||||
// + "\r\n return " + el.text.trim());
|
||||
|
||||
// let rt = func.call(el.parentElement);
|
||||
|
||||
// if (typeof (rt) === "object") {
|
||||
// for (var k in rt)
|
||||
// el.parentElement[k] = rt[k];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
created() {
|
||||
this.refs._build();
|
||||
}
|
||||
|
||||
set(value) {
|
||||
if (value == this.visible)
|
||||
return;
|
||||
if (value == this.visible) return;
|
||||
|
||||
if (value) {
|
||||
|
||||
this.setAttribute("selected", "");
|
||||
this._emit("show");
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.removeAttribute("selected");
|
||||
this._emit("hide");
|
||||
}
|
||||
if (value) {
|
||||
this.setAttribute("selected", "");
|
||||
this._emit("show");
|
||||
} else {
|
||||
this.removeAttribute("selected");
|
||||
this._emit("hide");
|
||||
}
|
||||
}
|
||||
|
||||
get visible() { return this.hasAttribute("selected"); }
|
||||
set visible(value) { this.set(value); }
|
||||
|
||||
});
|
||||
get visible() {
|
||||
return this.hasAttribute("selected");
|
||||
}
|
||||
set visible(value) {
|
||||
this.set(value);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user