Skip to content

Commit

Permalink
Improve SPArling.js logic
Browse files Browse the repository at this point in the history
main.js, spa,json
  • Loading branch information
HamzaElkotp committed Sep 21, 2022
1 parent cd4b85f commit 97ee99b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 14 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
function jsonRead(jsonpages, metatagFunc){
function jsonRead(jsonpages, metatagArr){
let xhr = fetch(jsonpages);
xhr.then((res)=>{
return res.json()
}).then((data)=>{
return data
}).then((data)=>{
function evenAdder(){

let SPAname = metatagArr[0];
let SPAurl = metatagArr[1];
let SPAtitle = metatagArr[2];

let elements = document.querySelectorAll('[SPAname]');
elements.forEach((ele, index)=>{
ele.addEventListener('click',()=>{
document.title = data[index].SPAtitle;
window.history.pushState("","",data[index].SPAurl);
document.title = data[index][SPAtitle];
window.history.pushState("","",data[index][SPAurl]);
})
})
}
evenAdder(metatagFunc);
evenAdder();
});
}

function metaTags(SPAnameKeyName, urlKeyName, titleKeyName){
let SPAname = SPAnameKeyName;
let SPAurl = urlKeyName;
let SPAtitle = titleKeyName;
}
jsonRead("spa.json",["SPAnameR", "SPAurlR", "SPAtitleR"]);





jsonRead("spa.json",metaTags("SPAname", "SPAurl", "SPAtitle"));
24 changes: 12 additions & 12 deletions spa.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
[
{
"SPAname" : "home",
"SPAurl": "../",
"SPAtitle": "SPA APP | My Logic",
"SPAnameR" : "home",
"SPAurlR": "../",
"SPAtitleR": "SPA APP | My Logic",
"Body": {

}
},
{
"SPAname" : "customers",
"SPAurl": "customers",
"SPAtitle": "Customers",
"SPAnameR" : "customers",
"SPAurlR": "customers",
"SPAtitleR": "Customers",
"Body": {

}
},
{
"SPAname" : "links",
"SPAurl": "links",
"SPAtitle": "Links",
"SPAnameR" : "links",
"SPAurlR": "links",
"SPAtitleR": "Links",
"Body": {

}
},
{
"SPAname" : "notifications",
"SPAurl": "notifications",
"SPAtitle": "Notifications",
"SPAnameR" : "notifications",
"SPAurlR": "notifications",
"SPAtitleR": "Notifications",
"Body": {

}
Expand Down

0 comments on commit 97ee99b

Please sign in to comment.