F
F
Faha19982015-10-25 16:04:50
JavaScript
Faha1998, 2015-10-25 16:04:50

Trimming url in pathname, how?

There is a site on dle, it has Javascript code for tabs

<script type="text/javascript"> 
switch(window.location.pathname) {
    case "/techit/":
        document.getElementById("it").className += " tab-active3";
        document.getElementById("mhead").className += " mhead-active";
        document.getElementById("leftside").className += " leftside-active";
        break;
    case "/blogs/":
        document.getElementById("blogs").className += " tab-active4";
        document.getElementById("mhead").className += " mhead-active1";
        document.getElementById("leftside").className += " leftside-active1";
        break;
    case "/game/":
        document.getElementById("game").className += " tab-active2";
        document.getElementById("mhead").className += " mhead-active3";
        document.getElementById("leftside").className += " leftside-active3";
        break;
    case "/lhack/":
        document.getElementById("lhack").className += " tab-active55";
        document.getElementById("mhead").className += " mhead-active4";
        document.getElementById("leftside").className += " leftside-active4";
        break;
    case "//":
    default:
        document.getElementById("maintab").className += " tab-active1";
        document.getElementById("mhead").className += " mhead-active2";
        document.getElementById("leftside").className += " leftside-active2";
} </script>

It changes the appearance as it should, but when you go to the news itself, for example example.ru/game/novaya-novost-12412.html , all settings are reset, that is, the code only works when you are in the /game/ category itself, and when you go to the news doesn’t plow everything, how to fix it ?, don’t prescribe every news :D
+++ How to make the code more rational, too many repetitions
JS I’m just starting to learn, don’t throw stones pliz)
UPD
Now the link looks like example.ru/game/ tt/novaya-novost-12412.html
and case became /game/tt/ , but still doesn't work
UPD
How to cut url to a certain character using JS itself? how to set pathname property like this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Khokhlov, 2015-10-25
@andrhohlov

If it's difficult with js, take a ready-made plugin, for example: vdw.github.io/Tabslet
You can set an active taboo in it.
Then you already need to dig in this dle of yours, maybe those who understand it will tell you.
I can only dream up, I'm sure in reality everything will be even simpler than my fantasies.
For example, there is a blogs section template.
Add code to it
In the news template, respectively
Well, when initializing tabs

$('.tabs').tabslet({
  active: self.activeTab 
});

I hope the train of thought is clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question