forked from olton/metroui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccordion.js
More file actions
78 lines (63 loc) · 2.2 KB
/
Copy pathaccordion.js
File metadata and controls
78 lines (63 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* jQuery plugin for input elements for Metro UI CSS framework
*/
(function($) {
var pluginName = 'Accordion',
initAllSelector = '[data-role="accordion"]',
paramKeys = [];
$[pluginName] = function(element, options) {
if (!element) {
return $()[pluginName]({initAll: true});
}
var defaults = {
};
var plugin = this;
plugin.settings = {};
var $element = $(element);
var $li, $triggers, $frames;
plugin.init = function() {
plugin.settings = $.extend({}, defaults, options);
$li = $element.children("li");
$triggers = $li.children("a");
$frames = $li.children("div");
$triggers.on('click', function(e){
e.preventDefault();
var $a = $(this),
$activeLi = $li.filter('.active'),
$parentLi = $a.parent("li"),
target = $a.parent('li').children("div");
if ( $parentLi.hasClass('active') ) {
target.slideUp(undefined, function(){
$parentLi.removeClass("active");
});
} else {
$frames.slideUp(undefined, function(){
$activeLi.removeClass("active");
});
target.slideDown();
$parentLi.addClass("active");
}
});
};
plugin.init();
};
$.fn[pluginName] = function(options) {
var elements = options && options.initAll ? $(initAllSelector) : this;
return elements.each(function() {
var that = $(this),
params = {},
plugin;
if (undefined == that.data(pluginName)) {
$.each(paramKeys, function(index, key){
params[key[0].toLowerCase() + key.slice(1)] = that.data('param' + key);
});
plugin = new $[pluginName](this, params);
that.data(pluginName, plugin);
}
});
};
// autoinit
$(function(){
$()[pluginName]({initAll: true});
});
})(jQuery);