I am currently running a jQuery script, in a .js file, and the script is getting longer and longer, with each new file added including my header.
I want to call a function for every URL opened up on my website which is in the same folder, running one function each URL is not that helpful.
My current script
$(document).ready(function(){
if (window.location.pathname == "/DE/") {
$(".Startseite").css("display","block");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","none");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/About/") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","none");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","block");
} else if (window.location.pathname == "/DE/Gaming-News/") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","block");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/Gaming-News/ExampleFileExample.php") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","block");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/Gaming-News/FIleExample.html") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","block");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/Gaming-News/File.Example") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","block");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/Gaming-News/Artikel4/Example.file") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","block");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/Clans/") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","none");
$(".Clans").css("display","block");
$(".Test").css("display","none");
$(".About").css("display","none");
} else if (window.location.pathname == "/DE/...") {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","none");
$(".Clans").css("display","none");
$(".Test").css("display","block");
$(".About").css("display","none");
} else {
$(".Startseite").css("display","none");
$(".Forum").css("display","none");
$(".Gaming-News").css("display","none");
$(".Clans").css("display","none");
$(".Test").css("display","none");
$(".About").css("display","none");
}
});
Now as you can see, each path with a file, that includes those classes, calls those functions. Can I mow this down to one function for per folder? Let's say I enter a folder and there's just an index, my header is included...blaaaa
Is there a function to call for every file in this folder? Don't know how to explain it. Now there's /DE/index.php, /DE/GN/index.php, /DE/GN/Art3.php.
Can I call one function only for the last two paths I just named, if the folder GN is in this path?
I hope everyone knows what I am talking about.
I also just put all that code in a .js file, before it was in an even larger script. But when including that with
<script src="https://Website.online/path%20to%20file/file.js"/>
in a html or php file, the script doesn't work. And yes I put that after the by Microsoft hosted compressed js source.