-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.accordionList.js
More file actions
57 lines (47 loc) · 1.59 KB
/
jquery.accordionList.js
File metadata and controls
57 lines (47 loc) · 1.59 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* name: accordionList - jQuery Plugin
* version: 0.5
* @requires jQuery v1.10 or later
*
* contributing author: John Nguyen
* source: https://github.com/nguyenj/accordion-list
* Copyright 2013 John Nguyen
*
*/
(function($) {
$.fn.accordionList = function (options) {
var defaults;
defaults = {
title: '.title',
description: '.description',
currentClass: 'current',
slideSpeed: 400,
onAfter: function (el) {}
};
options = $.extend({}, defaults, options);
return this.each(function () {
var $container = $(this);
if ($container.length) {
var $title = $container.find(options.title);
var $descriptions = $container.find(options.description);
$descriptions.not(':first').hide().end()
.first().parent().addClass(options.currentClass);
$title.on('click', function () {
var $this = $(this);
var isCurrent = $this.parent().hasClass(options.currentClass);
var $description = $(this).siblings(options.description);
$title.parent().removeClass(options.currentClass);
$descriptions.slideUp(options.slideSpeed);
if (!isCurrent) {
$this.parent().addClass(options.currentClass);
$description.slideDown(options.slideSpeed);
}
setTimeout(function() {
options.onAfter($this);
}, options.slideSpeed+1);
return false;
});
}
});
};
})(jQuery);