Created
September 14, 2011 14:16
-
-
Save ohryan/1216670 to your computer and use it in GitHub Desktop.
Collapses Wordpress Categories.
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
/* | |
* jQuery Wordpress Category Collapse | |
* | |
* Automatically collapses categories in your sidebar | |
* | |
*/ | |
$(function() { | |
var thing = $('#subnmenu .page_item').find('ul.children'); | |
var i = 0; | |
thing.each( | |
function(){ | |
i++; | |
var siblings = $(this).siblings(); | |
$(this).attr('id', 'category_'+i) | |
if (!$(this).parent().hasClass('current_page_ancestor') ) { | |
$(this).hide(); | |
siblings.after(' <a href="#" class="category_expander active" rel="category_'+i+'" style="float:right">+</a>'); | |
} else { | |
siblings.after(' <a href="#" class="category_expander" rel="category_'+i+'" style="float:right">-</a>'); | |
} | |
} | |
); | |
$('.category_expander').click( | |
function(evt) { | |
evt.preventDefault(); | |
var id = $(this).attr('rel') | |
$(this).toggleClass('active'); | |
$('#'+id).toggle(); | |
$(this).text(($(this).hasClass('active') ? '+': '-')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment