volt-foundation 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,445 +0,0 @@
1
- ;(function ($, window, document, undefined) {
2
- 'use strict';
3
-
4
- Foundation.libs.topbar = {
5
- name : 'topbar',
6
-
7
- version: '5.4.6',
8
-
9
- settings : {
10
- index : 0,
11
- sticky_class : 'sticky',
12
- custom_back_text: true,
13
- back_text: 'Back',
14
- mobile_show_parent_link: true,
15
- is_hover: true,
16
- scrolltop : true, // jump to top when sticky nav menu toggle is clicked
17
- sticky_on : 'all'
18
- },
19
-
20
- init : function (section, method, options) {
21
- Foundation.inherit(this, 'add_custom_rule register_media throttle');
22
- var self = this;
23
-
24
- self.register_media('topbar', 'foundation-mq-topbar');
25
-
26
- this.bindings(method, options);
27
-
28
- self.S('[' + this.attr_name() + ']', this.scope).each(function () {
29
- var topbar = $(this),
30
- settings = topbar.data(self.attr_name(true) + '-init'),
31
- section = self.S('section, .top-bar-section', this);
32
- topbar.data('index', 0);
33
- var topbarContainer = topbar.parent();
34
- if (topbarContainer.hasClass('fixed') || self.is_sticky(topbar, topbarContainer, settings) ) {
35
- self.settings.sticky_class = settings.sticky_class;
36
- self.settings.sticky_topbar = topbar;
37
- topbar.data('height', topbarContainer.outerHeight());
38
- topbar.data('stickyoffset', topbarContainer.offset().top);
39
- } else {
40
- topbar.data('height', topbar.outerHeight());
41
- }
42
-
43
- if (!settings.assembled) {
44
- self.assemble(topbar);
45
- }
46
-
47
- if (settings.is_hover) {
48
- self.S('.has-dropdown', topbar).addClass('not-click');
49
- } else {
50
- self.S('.has-dropdown', topbar).removeClass('not-click');
51
- }
52
-
53
- // Pad body when sticky (scrolled) or fixed.
54
- self.add_custom_rule('.f-topbar-fixed { padding-top: ' + topbar.data('height') + 'px }');
55
-
56
- if (topbarContainer.hasClass('fixed')) {
57
- self.S('body').addClass('f-topbar-fixed');
58
- }
59
- });
60
-
61
- },
62
-
63
- is_sticky: function (topbar, topbarContainer, settings) {
64
- var sticky = topbarContainer.hasClass(settings.sticky_class);
65
-
66
- if (sticky && settings.sticky_on === 'all') {
67
- return true;
68
- } else if (sticky && this.small() && settings.sticky_on === 'small') {
69
- return (matchMedia(Foundation.media_queries.small).matches && !matchMedia(Foundation.media_queries.medium).matches &&
70
- !matchMedia(Foundation.media_queries.large).matches);
71
- //return true;
72
- } else if (sticky && this.medium() && settings.sticky_on === 'medium') {
73
- return (matchMedia(Foundation.media_queries.small).matches && matchMedia(Foundation.media_queries.medium).matches &&
74
- !matchMedia(Foundation.media_queries.large).matches);
75
- //return true;
76
- } else if(sticky && this.large() && settings.sticky_on === 'large') {
77
- return (matchMedia(Foundation.media_queries.small).matches && matchMedia(Foundation.media_queries.medium).matches &&
78
- matchMedia(Foundation.media_queries.large).matches);
79
- //return true;
80
- }
81
-
82
- return false;
83
- },
84
-
85
- toggle: function (toggleEl) {
86
- var self = this,
87
- topbar;
88
-
89
- if (toggleEl) {
90
- topbar = self.S(toggleEl).closest('[' + this.attr_name() + ']');
91
- } else {
92
- topbar = self.S('[' + this.attr_name() + ']');
93
- }
94
-
95
- var settings = topbar.data(this.attr_name(true) + '-init');
96
-
97
- var section = self.S('section, .top-bar-section', topbar);
98
-
99
- if (self.breakpoint()) {
100
- if (!self.rtl) {
101
- section.css({left: '0%'});
102
- $('>.name', section).css({left: '100%'});
103
- } else {
104
- section.css({right: '0%'});
105
- $('>.name', section).css({right: '100%'});
106
- }
107
-
108
- self.S('li.moved', section).removeClass('moved');
109
- topbar.data('index', 0);
110
-
111
- topbar
112
- .toggleClass('expanded')
113
- .css('height', '');
114
- }
115
-
116
- if (settings.scrolltop) {
117
- if (!topbar.hasClass('expanded')) {
118
- if (topbar.hasClass('fixed')) {
119
- topbar.parent().addClass('fixed');
120
- topbar.removeClass('fixed');
121
- self.S('body').addClass('f-topbar-fixed');
122
- }
123
- } else if (topbar.parent().hasClass('fixed')) {
124
- if (settings.scrolltop) {
125
- topbar.parent().removeClass('fixed');
126
- topbar.addClass('fixed');
127
- self.S('body').removeClass('f-topbar-fixed');
128
-
129
- window.scrollTo(0,0);
130
- } else {
131
- topbar.parent().removeClass('expanded');
132
- }
133
- }
134
- } else {
135
- if (self.is_sticky(topbar, topbar.parent(), settings)) {
136
- topbar.parent().addClass('fixed');
137
- }
138
-
139
- if (topbar.parent().hasClass('fixed')) {
140
- if (!topbar.hasClass('expanded')) {
141
- topbar.removeClass('fixed');
142
- topbar.parent().removeClass('expanded');
143
- self.update_sticky_positioning();
144
- } else {
145
- topbar.addClass('fixed');
146
- topbar.parent().addClass('expanded');
147
- self.S('body').addClass('f-topbar-fixed');
148
- }
149
- }
150
- }
151
- },
152
-
153
- timer : null,
154
-
155
- events : function (bar) {
156
- var self = this,
157
- S = this.S;
158
-
159
- S(this.scope)
160
- .off('.topbar')
161
- .on('click.fndtn.topbar', '[' + this.attr_name() + '] .toggle-topbar', function (e) {
162
- e.preventDefault();
163
- self.toggle(this);
164
- })
165
- .on('click.fndtn.topbar','.top-bar .top-bar-section li a[href^="#"],[' + this.attr_name() + '] .top-bar-section li a[href^="#"]',function (e) {
166
- var li = $(this).closest('li');
167
- if(self.breakpoint() && !li.hasClass('back') && !li.hasClass('has-dropdown'))
168
- {
169
- self.toggle();
170
- }
171
- })
172
- .on('click.fndtn.topbar', '[' + this.attr_name() + '] li.has-dropdown', function (e) {
173
- var li = S(this),
174
- target = S(e.target),
175
- topbar = li.closest('[' + self.attr_name() + ']'),
176
- settings = topbar.data(self.attr_name(true) + '-init');
177
-
178
- if(target.data('revealId')) {
179
- self.toggle();
180
- return;
181
- }
182
-
183
- if (self.breakpoint()) return;
184
- if (settings.is_hover && !Modernizr.touch) return;
185
-
186
- e.stopImmediatePropagation();
187
-
188
- if (li.hasClass('hover')) {
189
- li
190
- .removeClass('hover')
191
- .find('li')
192
- .removeClass('hover');
193
-
194
- li.parents('li.hover')
195
- .removeClass('hover');
196
- } else {
197
- li.addClass('hover');
198
-
199
- $(li).siblings().removeClass('hover');
200
-
201
- if (target[0].nodeName === 'A' && target.parent().hasClass('has-dropdown')) {
202
- e.preventDefault();
203
- }
204
- }
205
- })
206
- .on('click.fndtn.topbar', '[' + this.attr_name() + '] .has-dropdown>a', function (e) {
207
- if (self.breakpoint()) {
208
-
209
- e.preventDefault();
210
-
211
- var $this = S(this),
212
- topbar = $this.closest('[' + self.attr_name() + ']'),
213
- section = topbar.find('section, .top-bar-section'),
214
- dropdownHeight = $this.next('.dropdown').outerHeight(),
215
- $selectedLi = $this.closest('li');
216
-
217
- topbar.data('index', topbar.data('index') + 1);
218
- $selectedLi.addClass('moved');
219
-
220
- if (!self.rtl) {
221
- section.css({left: -(100 * topbar.data('index')) + '%'});
222
- section.find('>.name').css({left: 100 * topbar.data('index') + '%'});
223
- } else {
224
- section.css({right: -(100 * topbar.data('index')) + '%'});
225
- section.find('>.name').css({right: 100 * topbar.data('index') + '%'});
226
- }
227
-
228
- topbar.css('height', $this.siblings('ul').outerHeight(true) + topbar.data('height'));
229
- }
230
- });
231
-
232
- S(window).off(".topbar").on("resize.fndtn.topbar", self.throttle(function() {
233
- self.resize.call(self);
234
- }, 50)).trigger("resize").trigger("resize.fndtn.topbar").load(function(){
235
- // Ensure that the offset is calculated after all of the pages resources have loaded
236
- S(this).trigger("resize.fndtn.topbar");
237
- });
238
-
239
- S('body').off('.topbar').on('click.fndtn.topbar', function (e) {
240
- var parent = S(e.target).closest('li').closest('li.hover');
241
-
242
- if (parent.length > 0) {
243
- return;
244
- }
245
-
246
- S('[' + self.attr_name() + '] li.hover').removeClass('hover');
247
- });
248
-
249
- // Go up a level on Click
250
- S(this.scope).on('click.fndtn.topbar', '[' + this.attr_name() + '] .has-dropdown .back', function (e) {
251
- e.preventDefault();
252
-
253
- var $this = S(this),
254
- topbar = $this.closest('[' + self.attr_name() + ']'),
255
- section = topbar.find('section, .top-bar-section'),
256
- settings = topbar.data(self.attr_name(true) + '-init'),
257
- $movedLi = $this.closest('li.moved'),
258
- $previousLevelUl = $movedLi.parent();
259
-
260
- topbar.data('index', topbar.data('index') - 1);
261
-
262
- if (!self.rtl) {
263
- section.css({left: -(100 * topbar.data('index')) + '%'});
264
- section.find('>.name').css({left: 100 * topbar.data('index') + '%'});
265
- } else {
266
- section.css({right: -(100 * topbar.data('index')) + '%'});
267
- section.find('>.name').css({right: 100 * topbar.data('index') + '%'});
268
- }
269
-
270
- if (topbar.data('index') === 0) {
271
- topbar.css('height', '');
272
- } else {
273
- topbar.css('height', $previousLevelUl.outerHeight(true) + topbar.data('height'));
274
- }
275
-
276
- setTimeout(function () {
277
- $movedLi.removeClass('moved');
278
- }, 300);
279
- });
280
-
281
- // Show dropdown menus when their items are focused
282
- S(this.scope).find('.dropdown a')
283
- .focus(function() {
284
- $(this).parents('.has-dropdown').addClass('hover');
285
- })
286
- .blur(function() {
287
- $(this).parents('.has-dropdown').removeClass('hover');
288
- });
289
- },
290
-
291
- resize : function () {
292
- var self = this;
293
- self.S('[' + this.attr_name() + ']').each(function () {
294
- var topbar = self.S(this),
295
- settings = topbar.data(self.attr_name(true) + '-init');
296
-
297
- var stickyContainer = topbar.parent('.' + self.settings.sticky_class);
298
- var stickyOffset;
299
-
300
- if (!self.breakpoint()) {
301
- var doToggle = topbar.hasClass('expanded');
302
- topbar
303
- .css('height', '')
304
- .removeClass('expanded')
305
- .find('li')
306
- .removeClass('hover');
307
-
308
- if(doToggle) {
309
- self.toggle(topbar);
310
- }
311
- }
312
-
313
- if(self.is_sticky(topbar, stickyContainer, settings)) {
314
- if(stickyContainer.hasClass('fixed')) {
315
- // Remove the fixed to allow for correct calculation of the offset.
316
- stickyContainer.removeClass('fixed');
317
-
318
- stickyOffset = stickyContainer.offset().top;
319
- if(self.S(document.body).hasClass('f-topbar-fixed')) {
320
- stickyOffset -= topbar.data('height');
321
- }
322
-
323
- topbar.data('stickyoffset', stickyOffset);
324
- stickyContainer.addClass('fixed');
325
- } else {
326
- stickyOffset = stickyContainer.offset().top;
327
- topbar.data('stickyoffset', stickyOffset);
328
- }
329
- }
330
-
331
- });
332
- },
333
-
334
- breakpoint : function () {
335
- return !matchMedia(Foundation.media_queries['topbar']).matches;
336
- },
337
-
338
- small : function () {
339
- return matchMedia(Foundation.media_queries['small']).matches;
340
- },
341
-
342
- medium : function () {
343
- return matchMedia(Foundation.media_queries['medium']).matches;
344
- },
345
-
346
- large : function () {
347
- return matchMedia(Foundation.media_queries['large']).matches;
348
- },
349
-
350
- assemble : function (topbar) {
351
- var self = this,
352
- settings = topbar.data(this.attr_name(true) + '-init'),
353
- section = self.S('section, .top-bar-section', topbar);
354
-
355
- // Pull element out of the DOM for manipulation
356
- section.detach();
357
-
358
- self.S('.has-dropdown>a', section).each(function () {
359
- var $link = self.S(this),
360
- $dropdown = $link.siblings('.dropdown'),
361
- url = $link.attr('href'),
362
- $titleLi;
363
-
364
-
365
- if (!$dropdown.find('.title.back').length) {
366
-
367
- if (settings.mobile_show_parent_link == true && url) {
368
- $titleLi = $('<li class="title back js-generated"><h5><a href="javascript:void(0)"></a></h5></li><li class="parent-link show-for-small"><a class="parent-link js-generated" href="' + url + '">' + $link.html() +'</a></li>');
369
- } else {
370
- $titleLi = $('<li class="title back js-generated"><h5><a href="javascript:void(0)"></a></h5>');
371
- }
372
-
373
- // Copy link to subnav
374
- if (settings.custom_back_text == true) {
375
- $('h5>a', $titleLi).html(settings.back_text);
376
- } else {
377
- $('h5>a', $titleLi).html('&laquo; ' + $link.html());
378
- }
379
- $dropdown.prepend($titleLi);
380
- }
381
- });
382
-
383
- // Put element back in the DOM
384
- section.appendTo(topbar);
385
-
386
- // check for sticky
387
- this.sticky();
388
-
389
- this.assembled(topbar);
390
- },
391
-
392
- assembled : function (topbar) {
393
- topbar.data(this.attr_name(true), $.extend({}, topbar.data(this.attr_name(true)), {assembled: true}));
394
- },
395
-
396
- height : function (ul) {
397
- var total = 0,
398
- self = this;
399
-
400
- $('> li', ul).each(function () {
401
- total += self.S(this).outerHeight(true);
402
- });
403
-
404
- return total;
405
- },
406
-
407
- sticky : function () {
408
- var self = this;
409
-
410
- this.S(window).on('scroll', function() {
411
- self.update_sticky_positioning();
412
- });
413
- },
414
-
415
- update_sticky_positioning: function() {
416
- var klass = '.' + this.settings.sticky_class,
417
- $window = this.S(window),
418
- self = this;
419
-
420
- if (self.settings.sticky_topbar && self.is_sticky(this.settings.sticky_topbar,this.settings.sticky_topbar.parent(), this.settings)) {
421
- var distance = this.settings.sticky_topbar.data('stickyoffset');
422
- if (!self.S(klass).hasClass('expanded')) {
423
- if ($window.scrollTop() > (distance)) {
424
- if (!self.S(klass).hasClass('fixed')) {
425
- self.S(klass).addClass('fixed');
426
- self.S('body').addClass('f-topbar-fixed');
427
- }
428
- } else if ($window.scrollTop() <= distance) {
429
- if (self.S(klass).hasClass('fixed')) {
430
- self.S(klass).removeClass('fixed');
431
- self.S('body').removeClass('f-topbar-fixed');
432
- }
433
- }
434
- }
435
- }
436
- },
437
-
438
- off : function () {
439
- this.S(this.scope).off('.fndtn.topbar');
440
- this.S(window).off('.fndtn.topbar');
441
- },
442
-
443
- reflow : function () {}
444
- };
445
- }(jQuery, window, window.document));