Skip to content

Instantly share code, notes, and snippets.

@JKirchartz
Created April 25, 2011 16:36
Show Gist options
  • Save JKirchartz/940770 to your computer and use it in GitHub Desktop.
Save JKirchartz/940770 to your computer and use it in GitHub Desktop.
XUIjs Accordion
<!DOCTYPE html>
<html>
<head>
<title>XUIaccordion Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--[if !IE]>-->
<!-- no blackberry support if you use IE conditionals to detect browser, but this is a demo so relax -->
<script type="text/javascript" src="http://xuijs.com/downloads/xui-2.0.0.min.js"></script>
<!-- sorry for hotlinking, XUI dudes, but this is a demo so deal with it. -->
<!--<![endif]-->
<!--[if IE]>
<script type="text/javascript" src="http://xuijs.com/downloads/xui-ie-2.0.0.min.js"></script>
<![endif]-->
<style>
</style>
</head>
<body>
<ul id="nav">
<li>
<a href="#" class="navItem">Menu Item 1<span>&#9660;</span></a>
<div class="item">
Lorem Ipsum Dolar Sit Amet
</div>
</li>
<li>
<a href="#" class="navItem">Menu Item 2<span>&#9660;</span></a>
<div class="item">
Lorem Ipsum Dolar Sit Amet
</div>
</li>
<li>
<a href="#" class="navItem">Menu Item 3<span>&#9660;</span></a>
<div class="item">
Lorem Ipsum Dolar Sit Amet
</div>
</li>
<li>
<a href="#" class="navItem">Menu Item 4<span>&#9660;</span></a>
<div class="item">
Lorem Ipsum Dolar Sit Amet
</div>
</li>
<li>
<a href="#" class="navItem">Menu Item 5<span>&#9660;</span></a>
<div class="item">
Lorem Ipsum Dolar Sit Amet
</div>
</li>
</ul>
<script type="text/javascript" src="xuiAccordion.js"></script>
</body>
</html>
x$.extend({
'hide':function(){
this.addClass('hide');
this.removeClass('show');
return x$(this);
},
'show':function(){
this.addClass('show');
this.removeClass('hide');
return x$(this);
},
'next': function() {
var n = this[0];
do{n = n.nextSibling;}
while (n && n.nodeType != 1);
return x$(n);
},
'is': function(sr) {
sr = sr.toUpperCase();
var n = this[0];
if(sr == n.nodeName){
return x$(n);
}
return false;
}
});
window.onload = function(){
x$('#nav div.item').hide();
x$('#nav a.navItem').click(function(e) {
var next = x$(this).next();
if(next.hasClass("hide")){
x$('#nav div.item').hide();
next.show();
}else{
next.hide();
}
e.stopPropagation();
e.preventDefault();
return false;
});
};
@JKirchartz
Copy link
Author

Here's a simple accordion created with XUIjs

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