Added loading of bookmark links from localStorage
This commit is contained in:
parent
531524d192
commit
9880643655
1 changed files with 18 additions and 9 deletions
|
@ -1,15 +1,24 @@
|
|||
var data_links = "links.json";
|
||||
var bookmarks = JSON.parse(localStorage.getItem("links"));
|
||||
|
||||
function handleLinks(data) {
|
||||
var mysource = document.getElementById("links-template").innerHTML;
|
||||
var mytemplate = Handlebars.compile(mysource);
|
||||
var myresult = mytemplate(data)
|
||||
document.getElementById("links").innerHTML = myresult;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
fetch(data_links)
|
||||
.then( response => response.json())
|
||||
.then(
|
||||
function (data) {
|
||||
var mysource = document.getElementById("links-template").innerHTML;
|
||||
var mytemplate = Handlebars.compile(mysource);
|
||||
var myresult = mytemplate(data)
|
||||
document.getElementById("links").innerHTML = myresult;
|
||||
});
|
||||
if (!bookmarks) {
|
||||
fetch(data_links)
|
||||
.then(response => response.json())
|
||||
.then(function (data) {
|
||||
handleLinks(data);
|
||||
localStorage.setItem("links", JSON.stringify(data));
|
||||
});
|
||||
} else {
|
||||
handleLinks(bookmarks);
|
||||
}
|
||||
});
|
||||
|
||||
var data_apps = "apps.json";
|
||||
|
|
Loading…
Reference in a new issue