Created
July 31, 2012 22:19
-
-
Save octavioamu/3221163 to your computer and use it in GitHub Desktop.
Accordion show open with the current url
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
<nav class="main-nav"> | |
<ul> | |
<li> | |
<a href="/escola" title="" class="home"> | |
<i></i> | |
<span>Início</span> | |
</a> | |
</li> | |
<li class="dropdown"> | |
<a href="" title="" class="ballon"> | |
<i></i> | |
<span>Cadastros</span> | |
</a> | |
<ul> | |
<li> | |
<a href="/editar-escola" title="" class="posts">Meu cadastro</a> | |
</li> | |
<li> | |
<a href="/escola/novo-atleta">Novo cadastro</a> | |
</li> | |
<li> | |
<a href="/escola/atletas">Pessoas cadastradas</a> | |
</li> | |
</ul> | |
</li> | |
<li class="dropdown"> | |
<a href="" title="" class="paper"> | |
<i></i> | |
<span>Espaços</span> | |
</a> | |
<ul> | |
<li> | |
<a href="/escola/espacos" title="" class="posts">Espaços cadastrados</a> | |
</li> | |
<li> | |
<a href="/escola/novo-auditorio">Novo espaço</a> | |
</li> | |
</ul> | |
</li> | |
<li class="dropdown"> | |
<a href="" title="" class="ballon active"> | |
<i></i> | |
<span>Mensagens</span> | |
</a> | |
<ul style="display: block; "> | |
<li> | |
<a href="/escola/mensagens" class="current">Todas as mensagens</a> | |
</li> | |
<li> | |
<a href="/escola/nova-mensagem">Nova mensagem</a> | |
</li> | |
</ul> | |
</li> | |
<li class="dropdown"> | |
<a href="" title="" class="paper"> | |
<i></i> | |
<span>Agenda</span> | |
</a> | |
<ul> | |
<li> | |
<a href="/escola/agenda/auditorio/5/31-07-2012">Auditório (Fernando Pessoa)</a> | |
</li> | |
<li> | |
<a href="/escola/agenda/piscina/4/31-07-2012">Piscina (Semi)</a> | |
</li> | |
<li> | |
<a href="/escola/agenda/quadra/6/31-07-2012">Quadra (Antônio Souza)</a> | |
</li> | |
<li> | |
<a href="/escola/agenda/ginasio/2/31-07-2012">Ginásio (A#)</a> | |
</li> | |
</ul> </li> | |
</ul> | |
</nav> |
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
/*=====[ =URLDropdown ]=====*/ | |
$(function(){ | |
var url = window.location.pathname, | |
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$"); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there | |
// now grab every link from the navigation | |
$('.dropdown ul li a').each(function(){ | |
// and test its normalized href against the url pathname regexp | |
if(urlRegExp.test(this.href.replace(/\/$/,''))){ | |
$(this).addClass('current'); | |
$currentUl = $(this).closest('ul'); // find selected accordion | |
$currentUl.show(); // mostra | |
$currentUl.closest('.dropdown').children('a').addClass('active'); // add class current to active link | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment