-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultilevel.js
92 lines (72 loc) · 2.11 KB
/
multilevel.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
Multilevel
---------------------------------------------------------------------
Author: Lane Olson
Version: 1.0
Date: April 27, 2012
Description: Displays multiple lists of links as a dropdown menu
---------------------------------------------------------------------
**/
;(function ($) {
// initialize namespace if it doesn't exist
if (!$.responsive) {
$.responsive = {};
};
$.responsive.multilevel = function ( el, options ) {
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data( "responsive.multilevel" , base );
var topLevelUl = $('ul:first', base.el);
var topLevelLi = $('ul:first > li', base.el);
base.init = function () {
base.options = $.extend({}, $.responsive.multilevel.defaultOptions, options);
base.$el.bind("createmultilevel", function() {
base.create();
});
base.$el.bind("destroymultilevel", function() {
base.destroy();
});
base.create();
};
// item - list item containing the sub menu
base.showDropdown = function(item) {
item.children().show();
};
base.hideDropdown = function() {
if($('ul > li > div', base.el).length > 0) {
$('ul > li > div', base.el).hide();
} else {
$('ul li ul', base.el).hide();
}
};
base.create = function()
{
// hide the sub navigation
base.hideDropdown();
topLevelLi.bind("click mouseenter", function() {
base.showDropdown($(this));
});
topLevelLi.bind("mouseleave", function () {
base.hideDropdown();
});
};
base.destroy = function() {
$('div', base.el).removeAttr('style');
$('ul', base.el).removeAttr('style');
topLevelLi.unbind("click mouseenter mouseleave");
};
base.init();
};
$.responsive.multilevel.defaultOptions = {
};
$.fn.multilevel = function( options ) {
return this.each(function () {
(new $.responsive.multilevel(this, options));
});
};
})( jQuery );