Skip to content

Commit

Permalink
added baseurl option
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTplayed committed Oct 21, 2018
1 parent 0486d84 commit 006ec13
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
5 changes: 3 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ <h1 id="header">My Website</h1>
<a href="login">Login</a>
</div>
<footer>
<script src="/ldf.js"></script>
<script src="ldf.js"></script>
<script>
var header = document.querySelector("#header");
ldf.baseurl = "ldf"; // needed for github pages
ldf.begin = function () {
header.innerHTML = "My Website (loading)";
};
ldf.end = function () {
header.innerHTML = "My Website";
};
</script>
</footer>
</footer>
4 changes: 2 additions & 2 deletions docs/pages/controls/controls.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<script src="/pages/controls/controls.js"></script>
<input type="button" value="Press me" id="btn">
<script src="pages/controls/controls.js"></script>
<input type="button" value="Press me" id="btn">
4 changes: 2 additions & 2 deletions docs/pages/helloworld/helloworld.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<link rel="stylesheet" href="/pages/helloworld/helloworld.css">
<link rel="stylesheet" href="pages/helloworld/helloworld.css">

<p id="hw">Hello World!</p>
<p id="hw">Hello World!</p>
4 changes: 2 additions & 2 deletions docs/pages/login/login.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<link href="/pages/login/login.css" rel="stylesheet">
<link href="pages/login/login.css" rel="stylesheet">
<div id="logincentercontainer">
<div id="imagecontainer">
<img id="loginicon" src="/pages/login/icon.png" alt="icon">
Expand All @@ -23,4 +23,4 @@
<input type="button" value="Log in" id="btn_login">
</div>
</div>
</div>
</div>
16 changes: 14 additions & 2 deletions ldf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var ldf = {
notfound: "<div>Page not Found</div>",
waitselector: "link[rel='stylesheet'],:not(script)[src]",
pagedir: "/pages",
baseurl: "",
begin: undefined,
end: undefined,
hash: true,
Expand All @@ -13,12 +14,16 @@ var ldf = {
}
}
if (!ldf.hash && location == "") location = "/";
history.pushState(null, "", location);
history.pushState(null, "", ldf.baseurl + location);
ldf.locchange();
},
locchange: function () {
var loc = ldf.hash ? document.location.hash : document.location.pathname;
loc = loc.replace(ldf.baseurl, "");
loc = loc.replace("#", "/");
if (!loc.startsWith("/")) {
loc = "/" + loc;
}
if (loc == "/" || loc == "") loc = "/index";
if (ldf.begin) ldf.begin();
ldf.load(loc);
Expand Down Expand Up @@ -97,5 +102,12 @@ var ldf = {
}
}
};
if(!ldf.baseurl.endsWith("/")) {
ldf.baseurl += "/";
}
if(!ldf.baseurl.startsWith("/")) {
ldf.baseurl = "/" + ldf.baseurl;
}

onpopstate = ldf.locchange;
onload = ldf.locchange;
onload = ldf.locchange;

0 comments on commit 006ec13

Please sign in to comment.