/*jslint unparam: true, browser: true, indent: 2 */ ;(function ($, window, document, undefined) { 'use strict'; Foundation.libs.topbar = { name : 'topbar', version : '4.1.0', settings : { index : 0, stickyClass : 'sticky', init : false }, init : function (scope, method, options) { var self = this; this.scope = scope || this.scope; if (typeof method === 'object') { $.extend(true, this.settings, method); } if (typeof method != 'string') { $('nav.top-bar').each(function () { self.settings.$w = $(window); self.settings.$topbar = $(this); self.settings.$section = self.settings.$topbar.find('section'); self.settings.$titlebar = self.settings.$topbar.children('ul').first(); self.settings.$topbar.data('index', 0); var breakpoint = $("
").insertAfter(self.settings.$topbar); self.settings.breakPoint = breakpoint.width(); breakpoint.remove(); self.assemble(); if (!self.settings.$topbar.data('height')) self.largestUL(); if (self.settings.$topbar.parent().hasClass('fixed')) { $('body').css('padding-top', this.outerHeight(this.settings.$topbar)); } }); if (!self.settings.init) { this.events(); } return this.settings.init; } else { // fire method return this[method].call(this, options); } }, events : function () { var self = this; $(this.scope) .on('click.fndtn.topbar', '.top-bar .toggle-topbar', function (e) { var topbar = $(this).closest('.top-bar'), section = topbar.find('section, .section'), titlebar = topbar.children('ul').first(); e.preventDefault(); if (self.breakpoint()) { topbar .toggleClass('expanded') .css('min-height', ''); } if (!topbar.hasClass('expanded')) { section.css({left: '0%'}); section.find('>.name').css({left: '100%'}); section.find('li.moved').removeClass('moved'); topbar.data('index', 0); } }) .on('click.fndtn.topbar', '.top-bar .has-dropdown>a', function (e) { var topbar = $(this).closest('.top-bar'), section = topbar.find('section, .section'), titlebar = topbar.children('ul').first(); if (Modernizr.touch || self.breakpoint()) { e.preventDefault(); } if (self.breakpoint()) { var $this = $(this), $selectedLi = $this.closest('li'); topbar.data('index', topbar.data('index') + 1); $selectedLi.addClass('moved'); section.css({left: -(100 * topbar.data('index')) + '%'}); section.find('>.name').css({left: 100 * topbar.data('index') + '%'}); $this.siblings('ul') .height(topbar.data('height') + self.outerHeight(titlebar, true)); topbar .css('min-height', topbar.data('height') + self.outerHeight(titlebar, true) * 2) } }); $(window).on('resize.fndtn.topbar', function () { if (!this.breakpoint()) { $('.top-bar').css('min-height', ''); } }.bind(this)); // Go up a level on Click $(this.scope).on('click.fndtn', '.top-bar .has-dropdown .back', function (e) { e.preventDefault(); var $this = $(this), topbar = $this.closest('.top-bar'), section = topbar.find('section, .section'), $movedLi = $this.closest('li.moved'), $previousLevelUl = $movedLi.parent(); topbar.data('index', topbar.data('index') - 1); section.css({left: -(100 * topbar.data('index')) + '%'}); section.find('>.name').css({'left': 100 * topbar.data('index') + '%'}); if (topbar.data('index') === 0) { topbar.css('min-height', 0); } setTimeout(function () { $movedLi.removeClass('moved'); }, 300); }); }, breakpoint : function () { return $(window).width() <= this.settings.breakPoint || $('html').hasClass('lt-ie9'); }, assemble : function () { // Pull element out of the DOM for manipulation this.settings.$section.detach(); this.settings.$section.find('.has-dropdown>a').each(function () { var $link = $(this), $dropdown = $link.siblings('.dropdown'), $titleLi = $('