blob: a29090b662839409a58b29eabda130a81cb27141 (
plain)
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
|
/**
* Gumby Navbar
*/
!function() {
'use strict';
// define module class and init only if we're on touch devices
if(!Modernizr.touch) {
return;
}
function Navbar($el) {
this.$el = $el;
var scope = this;
// when navbar items are tapped hide/show dropdowns
this.$el.find('li').on(Gumby.click, function(e) {
var $this = $(this);
e.stopPropagation();
// prevent jump to top of page
if(this.href === '#') {
e.preventDefault();
}
scope.dropdown($this);
});
}
// hide/show dropdowns
Navbar.prototype.dropdown = function($this) {
// we have dropdowns so open/cose
if($this.children('.dropdown').length) {
if($this.hasClass('active')) {
$this.removeClass('active');
} else {
$this.addClass('active');
}
// no dropdown so close others
} else {
this.$items.removeClass('active');
}
};
// add initialisation
Gumby.addInitalisation('navbars', function() {
$('.navbar').each(function() {
var $this = $(this);
// this element has already been initialized
if($this.data('isNavbar')) {
return true;
}
// mark element as initialized
$this.data('isNavbar', true);
new Navbar($this);
});
});
// register UI module
Gumby.UIModule({
module: 'navbar',
events: [],
init: function() {
Gumby.initialize('navbars');
}
});
}();
|