Commit d4e58a7b authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Launcher route url when not at the root

parent a0a68dd7
...@@ -7,7 +7,33 @@ ...@@ -7,7 +7,33 @@
var MAIN_SCOPE = "m"; var MAIN_SCOPE = "m";
function validURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return !!pattern.test(str);
}
function renderMainGadget(gadget, url, options) { function renderMainGadget(gadget, url, options) {
var path = "", path_list = window.location.pathname.split("/");
// If the url given is not a full url we add the current path
if (!validURL(url)) {
if (path_list) {
if (path_list[path_list.length - 1] !== "") {
if (path_list[path_list.length - 1].endsWith(".html")) {
path_list[path_list.length - 1] = "";
} else {
path_list.push("");
}
}
path = path_list.join("/");
}
url = path + url;
url = url.replace("//", "/");
}
return gadget.declareGadget(url, { return gadget.declareGadget(url, {
scope: MAIN_SCOPE scope: MAIN_SCOPE
}) })
......
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