forked from olton/Metro-UI-CSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accordion.js
44 lines (38 loc) · 1.21 KB
/
accordion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function($){
$.fn.Accordion = function( options ){
var defaults = {
};
var $this = $(this)
, $li = $this.children("li")
, $triggers = $li.children("a")
, $frames = $this.find("li div")
;
var initTriggers = function(triggers){
triggers.on('click', function(e){
e.preventDefault();
var $a = $(this)
, target = $($a.parent('li').children("div"));
if ( $a.parent('li').hasClass('active') ) {
target.slideUp();
$(this).parent("li").removeClass("active");
} else {
$frames.slideUp();
$li.removeClass("active");
target.slideDown();
$(this).parent("li").addClass("active");
}
});
}
return this.each(function(){
if ( options ) {
$.extend(defaults, options)
}
initTriggers($triggers);
});
}
$(function () {
$('[data-role="accordion"]').each(function () {
$(this).Accordion();
})
})
})(window.jQuery);