Last active
August 29, 2015 14:01
-
-
Save torounit/4f2f315c35bf2a0e2716 to your computer and use it in GitHub Desktop.
URLをParseして、適当にクラスをつける。適当実装。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do($=jQuery) => | |
$(".l-navigation__item").find("a").each -> | |
origin = location.origin | |
href = @.href.replace origin, "" | |
dir = href.replace "index.html", "" | |
if dir == "/" or dir == "" | |
#TOPの場合。 | |
pathname = location.pathname.replace "index.html", "" | |
if pathname == "/" or pathname == "" | |
$(@).addClass("current") | |
else | |
#通常の処理 | |
if location.pathname.indexOf(dir) != -1 | |
$(@).addClass("current") | |
#URL構造と、サイト構造が合っていない場合。。。/hogeにいるときに、piyoへのリンクをcurrentへ | |
else if location.pathname.indexOf("/^hoge/") == 0 and dir.indexOf("piyo") != -1 | |
$(@).addClass("current") |
Author
torounit
commented
May 23, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment