-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.candyaccordion.js
70 lines (49 loc) · 1.82 KB
/
jquery.candyaccordion.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* CandyAccordion
*
* @author: Stephen Radford, Twitter: @steve228uk
* @version: 1
* @Last Update: 28.03.2012
* @licence: MIT (http://www.opensource.org/licenses/mit-license.php)
* GPL (http://www.gnu.org/licenses/gpl.html)
* @documentation: http://www.github.com/steve228uk
* @feedback: [email protected]
*
*/
(function($) {
$.fn.candyaccordion = function(options) {
// Let's put some defaults in here
var defaults = {
speed: 250,
titleClass: 'candytitle',
textClass: 'candytext'
}
// Defined the options that were passed in, allows overwriting of defaults
var options = $.extend({}, defaults, options);
// For each of the ids/classes passed in attach the function
return this.each(function() {
var obj = $(this);
// Hide the defined class
$('.' + options.textClass).hide();
// Get the title class
var title = $('.' + options.titleClass);
// Fire off everything on click
$(title).click(function() {
if($(this).hasClass('active-' + options.titleClass)){
$(this).next('div').slideUp(options.speed);
$(this).next('div').removeClass('active-' + options.textClass);
$(this).removeClass('active-' + options.titleClass);
} else {
$('.active-' + options.textClass).slideUp(options.speed, function() {
$('.active-' + options.textClass).removeClass('active-' + options.textClass);
});
$('.active-' + options.titleClass).removeClass('active-' + options.titleClass);
$(this).addClass('active-' + options.titleClass);
$(this).next('div').slideToggle(options.speed, function() {
$(this).addClass('active-' + options.textClass);
});
}
});
}); // End this.each
} // End $.fn.candyaccordion
})(jQuery) // End main function and pass jQuery into the function