Skip to content

Instantly share code, notes, and snippets.

@UncleKo
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UncleKo/9526370 to your computer and use it in GitHub Desktop.
Save UncleKo/9526370 to your computer and use it in GitHub Desktop.
Just a sample for according menu using jQuery. I took this approach to keep the opening status to a liked page; it might be much easier than using cookie or other approaches. Here's a living example if you would like check html code: http://shrewd-design.com/blog/
$(function () {
var widgetAccordion = function() {
var $widget = $('aside .widget'),
// set the default status for the blog top page
dft = true;
$widget.children('ul').each( function() {
var currentURI = window.location.href,
links = $('a', this),
collapse = true;
for (var i = 0; i < links.size(); i++) {
var elem = links.eq(i);
var href = elem.attr('href');
if (href == currentURI) {
collapse = false;
dft = false;
break;
}
};
if (collapse) {
$(this).hide();
}
});
if (dft) {
$widget.eq(1).children('ul').show();
}
$widget.on('click', 'h2', function() {
$(this)
.next()
.slideDown(300)
.parent().siblings().children('ul')
.slideUp(300);
});
}
})();
@UncleKo
Copy link
Author

UncleKo commented Mar 13, 2014

I'm just having a trouble with indentation. When I change the indentation size, it looks working fine on the draft; but it doesn't take an effect on the final code. What's going on here?

@UncleKo
Copy link
Author

UncleKo commented Mar 13, 2014

Actually, all revisions here are just for trying to solve the indentation problem; so don't bother it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment