Skip to content

Commit

Permalink
small error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTplayed committed Oct 21, 2018
1 parent 3be6c45 commit c6624f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1 id="header">My Website</h1>
<script src="ldf.js"></script>
<script>
var header = document.querySelector("#header");
ldf.baseurl = "ldf/demo"; // needed for github pages
ldf.baseurl = "/ldf/demo/"; // needed for github pages
ldf.begin = function () {
header.innerHTML = "My Website (loading)";
};
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/login/login.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<link href="pages/login/login.css" rel="stylesheet">
<div id="logincentercontainer">
<div id="imagecontainer">
<img id="loginicon" src="/pages/login/icon.png" alt="icon">
<img id="loginicon" src="pages/login/icon.png" alt="icon">
</div>
<div id="logincontainer">
<p id="title">Login</p>
Expand Down
31 changes: 16 additions & 15 deletions ldf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ var ldf = {
change: function (content) {
var ldfnode = document.querySelector("#ldf");
var ldfclone = ldfnode.cloneNode();
var ended = false;
ldfclone.innerHTML = content;
ldfclone.style.display = "none";
ldfnode.parentElement.insertBefore(ldfclone, ldfnode);
ldf.helpers.waitForLoad(ldfclone.querySelectorAll(ldf.waitselector),
function () {
ldfnode.remove();
ldfclone.style.display = "";
if (ldf.end) ldf.end();
if (!ended) {
ended = true;
ldfnode.remove();
ldfclone.style.display = "";
if (ldf.end) ldf.end();
}
}
);
ldf.updatePageLinks();
Expand All @@ -74,17 +78,20 @@ var ldf = {
waitForLoad: function (loadings, cb) {
if (loadings.length > 0) {
var loadedcounter = 0;
loadings.forEach(function (loading) {
loading.onload = function () {
loadedcounter++;
if (loadedcounter == loadings.length) {
cb();
}
var onloadOrError = function() {
loadedcounter++;
if (loadedcounter == loadings.length) {
cb();
}
}
loadings.forEach(function (loading) {
loading.onload = onloadOrError;
loading.onerror = onloadOrError;
});
} else {
cb();
}

},
listener: function (e) {
e.preventDefault();
Expand All @@ -102,12 +109,6 @@ var ldf = {
}
}
};
if(!ldf.baseurl.endsWith("/")) {
ldf.baseurl += "/";
}
if(!ldf.baseurl.startsWith("/")) {
ldf.baseurl = "/" + ldf.baseurl;
}

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

0 comments on commit c6624f1

Please sign in to comment.