summaryrefslogtreecommitdiff
path: root/js/core/nav.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/core/nav.js')
-rwxr-xr-xjs/core/nav.js136
1 files changed, 0 insertions, 136 deletions
diff --git a/js/core/nav.js b/js/core/nav.js
deleted file mode 100755
index a6157ab..0000000
--- a/js/core/nav.js
+++ /dev/null
@@ -1,136 +0,0 @@
1/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2(function(UI) {
3
4 "use strict";
5
6 UI.component('nav', {
7
8 defaults: {
9 "toggle": ">li.uk-parent > a[href='#']",
10 "lists": ">li.uk-parent > ul",
11 "multiple": false
12 },
13
14 boot: function() {
15
16 // init code
17 UI.ready(function(context) {
18
19 UI.$("[data-uk-nav]", context).each(function() {
20 var nav = UI.$(this);
21
22 if (!nav.data("nav")) {
23 var obj = UI.nav(nav, UI.Utils.options(nav.attr("data-uk-nav")));
24 }
25 });
26 });
27 },
28
29 init: function() {
30
31 var $this = this;
32
33 this.on("click.uk.nav", this.options.toggle, function(e) {
34 e.preventDefault();
35 var ele = UI.$(this);
36 $this.open(ele.parent()[0] == $this.element[0] ? ele : ele.parent("li"));
37 });
38
39 this.find(this.options.lists).each(function() {
40 var $ele = UI.$(this),
41 parent = $ele.parent(),
42 active = parent.hasClass("uk-active");
43
44 $ele.wrap('<div style="overflow:hidden;height:0;position:relative;"></div>');
45 parent.data("list-container", $ele.parent()[active ? 'removeClass':'addClass']('uk-hidden'));
46
47 // Init ARIA
48 parent.attr('aria-expanded', parent.hasClass("uk-open"));
49
50 if (active) $this.open(parent, true);
51 });
52
53 },
54
55 open: function(li, noanimation) {
56
57 var $this = this, element = this.element, $li = UI.$(li), $container = $li.data('list-container');
58
59 if (!this.options.multiple) {
60
61 element.children('.uk-open').not(li).each(function() {
62
63 var ele = UI.$(this);
64
65 if (ele.data('list-container')) {
66 ele.data('list-container').stop().animate({height: 0}, function() {
67 UI.$(this).parent().removeClass('uk-open').end().addClass('uk-hidden');
68 });
69 }
70 });
71 }
72
73 $li.toggleClass('uk-open');
74
75 // Update ARIA
76 $li.attr('aria-expanded', $li.hasClass('uk-open'));
77
78 if ($container) {
79
80 if ($li.hasClass('uk-open')) {
81 $container.removeClass('uk-hidden');
82 }
83
84 if (noanimation) {
85
86 $container.stop().height($li.hasClass('uk-open') ? 'auto' : 0);
87
88 if (!$li.hasClass('uk-open')) {
89 $container.addClass('uk-hidden');
90 }
91
92 this.trigger('display.uk.check');
93
94 } else {
95
96 $container.stop().animate({
97 height: ($li.hasClass('uk-open') ? getHeight($container.find('ul:first')) : 0)
98 }, function() {
99
100 if (!$li.hasClass('uk-open')) {
101 $container.addClass('uk-hidden');
102 } else {
103 $container.css('height', '');
104 }
105
106 $this.trigger('display.uk.check');
107 });
108 }
109 }
110 }
111 });
112
113
114 // helper
115
116 function getHeight(ele) {
117 var $ele = UI.$(ele), height = "auto";
118
119 if ($ele.is(":visible")) {
120 height = $ele.outerHeight();
121 } else {
122 var tmp = {
123 position: $ele.css("position"),
124 visibility: $ele.css("visibility"),
125 display: $ele.css("display")
126 };
127
128 height = $ele.css({position: 'absolute', visibility: 'hidden', display: 'block'}).outerHeight();
129
130 $ele.css(tmp); // reset element
131 }
132
133 return height;
134 }
135
136})(UIkit);