forked from onokumus/metismenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.metisMenu.js
52 lines (41 loc) · 1.45 KB
/
jquery.metisMenu.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
/**
* metisMenu v1.0.1
* Author : Osman Nuri Okumuş
* Copyright 2014
* Licensed under MIT
*/
;(function ($, window, document, undefined) {
var pluginName = "metisMenu",
defaults = {
toggle: true
};
function Plugin(element, options) {
this.element = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function () {
var $this = $(this.element),
$toggle = this.settings.toggle;
$this.find('li.active').has('ul').children('ul').addClass('collapse in');
$this.find('li').not('.active').has('ul').children('ul').addClass('collapse');
$this.find('li').has('ul').children('a').on('click', function (e) {
e.preventDefault();
$(this).parent('li').toggleClass('active').children('ul').collapse('toggle');
if ($toggle) {
$(this).parent('li').siblings().removeClass('active').children('ul.in').collapse('hide');
}
});
}
};
$.fn[ pluginName ] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
})(jQuery, window, document);