Merge pull request #675 from trheyi/main
fix sui GlobRoutes bug and add s:click support
This commit is contained in:
commit
d381f02639
2 changed files with 50 additions and 1 deletions
|
|
@ -7,6 +7,16 @@ const initScriptTmpl = `
|
||||||
var __sui_data = %s;
|
var __sui_data = %s;
|
||||||
} catch (e) { console.log('init data error:', e); }
|
} catch (e) { console.log('init data error:', e); }
|
||||||
|
|
||||||
|
function __sui_findParentWithAttribute(element, attributeName) {
|
||||||
|
while (element && element !== document) {
|
||||||
|
if (element.hasAttribute(attributeName)) {
|
||||||
|
return element.getAttribute(attributeName);
|
||||||
|
}
|
||||||
|
element = element.parentElement;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
try {
|
try {
|
||||||
document.querySelectorAll("[s\\:ready]").forEach(function (element) {
|
document.querySelectorAll("[s\\:ready]").forEach(function (element) {
|
||||||
|
|
@ -21,6 +31,39 @@ const initScriptTmpl = `
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll("[s\\:click]").forEach(function (element) {
|
||||||
|
const method = element.getAttribute("s:click");
|
||||||
|
const cn = __sui_findParentWithAttribute(element, "s:cn");
|
||||||
|
if (method && cn && typeof window[cn] === "function") {
|
||||||
|
const obj = new window[cn]();
|
||||||
|
if (typeof obj[method] === "function") {
|
||||||
|
element.addEventListener("click", function (event) {
|
||||||
|
try {
|
||||||
|
obj[method](element, event);
|
||||||
|
} catch (e) {
|
||||||
|
const message = e.message || e || "An error occurred";
|
||||||
|
console.error(` + "`[SUI] ${cn}.${method} Error: ${message}`" + `);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.error(` + "`[SUI] ${cn}.${method} Error: Method not found`" + `);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method && typeof window[method] === "function") {
|
||||||
|
element.addEventListener("click", function (event) {
|
||||||
|
try {
|
||||||
|
window[method](element, event);
|
||||||
|
} catch (e) {
|
||||||
|
const message = e.message || e || "An error occurred";
|
||||||
|
console.error(` + "`[SUI] ${method} Error: ${message}`" + `);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
%s
|
%s
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,13 @@ func (tmpl *Template) GlobRoutes(patterns []string, unique ...bool) ([]string, e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
routes = append(routes, paths...)
|
|
||||||
|
for _, path := range paths {
|
||||||
|
if !tmpl.local.fs.IsDir(filepath.Join(tmpl.Root, path)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
routes = append(routes, path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unique
|
// Unique
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue