1/*jslint unparam: true, browser: true, indent: 2 */ 2 3;(function ($, window, document, undefined) { 4 'use strict'; 5 6 Foundation.libs.topbar = { 7 name : 'topbar', 8 9 version: '4.3.1', 10 11 settings : { 12 index : 0, 13 stickyClass : 'topbar-sticky', 14 custom_back_text: true, 15 back_text: 'Back', 16 is_hover: true, 17 mobile_show_parent_link: true, 18 scrolltop : true, // jump to top when sticky nav menu toggle is clicked 19 init : false 20 }, 21 22 init : function (section, method, options) { 23 Foundation.inherit(this, 'data_options'); 24 var self = this; 25 26 if (typeof method === 'object') { 27 $.extend(true, this.settings, method); 28 } else if (typeof options !== 'undefined') { 29 $.extend(true, this.settings, options); 30 } 31 32 if (typeof method !== 'string') { 33 34 $('.top-bar, [data-topbar]').each(function () { 35 $.extend(true, self.settings, self.data_options($(this))); 36 self.settings.$w = $(window); 37 self.settings.$topbar = $(this); 38 self.settings.$section = self.settings.$topbar.find('section, .section'); 39 self.settings.$titlebar = self.settings.$topbar.children('ul').first(); 40 self.settings.$topbar.data('index', 0); 41 42 var breakpoint = $("<div class='top-bar-js-breakpoint'/>").insertAfter(self.settings.$topbar); 43 self.settings.breakPoint = breakpoint.width(); 44 breakpoint.remove(); 45 46 self.assemble(); 47 48 if (self.settings.is_hover) { 49 self.settings.$topbar.find('.has-dropdown').addClass('not-click'); 50 } 51 52 // if (self.settings.$topbar.parent().hasClass('fixed')) { 53 // var topBarPadding = self.outerHeight(self.settings.$topbar); 54 55 // if( $('.ctc-header').is(':visible') ){ 56 // topBarPadding += $('.ctc-header').height(); 57 // } 58 59 // // if( $('#wpadminbar').is(':visible') && window.matchMedia("screen and (max-width: 600px)").matches ){ 60 // // topBarPadding += $('#wpadminbar').height(); 61 // // } 62 63 // $('body').css('padding-top', topBarPadding); console.log(topBarPadding); 64 // } 65 }); 66 67 if (!self.settings.init) { 68 this.events(); 69 } 70 71 return this.settings.init; 72 } else { 73 // fire method 74 return this[method].call(this, options); 75 } 76 }, 77 78 timer : null, 79 80 events : function () { 81 var self = this; 82 var offst = this.outerHeight($('.top-bar, [data-topbar]')); 83 $(this.scope) 84 .off('.fndtn.topbar') 85 .on('click.fndtn.topbar', '.top-bar .toggle-topbar, [data-topbar] .toggle-topbar', function (e) { 86 var topbar = $(this).closest('.top-bar, [data-topbar]'), 87 section = topbar.find('section, .section'), 88 titlebar = topbar.children('ul').first(); 89 90 e.preventDefault(); 91 92 if (self.breakpoint()) { 93 if (!self.rtl) { 94 section.css({left: '0%'}); 95 section.find('>.name').css({left: '100%'}); 96 } else { 97 section.css({right: '0%'}); 98 section.find('>.name').css({right: '100%'}); 99 } 100 101 section.find('li.moved').removeClass('moved'); 102 topbar.data('index', 0); 103 104 topbar 105 .toggleClass('expanded') 106 .css('height', ''); 107 } 108 109 if (!topbar.hasClass('expanded')) { 110 if (topbar.hasClass('fixed')) { 111 topbar.parent().addClass('fixed'); 112 topbar.removeClass('fixed'); 113 $('body').removeClass('nav-expanded'); 114 115 // if( $('#wpadminbar').is(':visible') && window.matchMedia("screen and (max-width: 600px)").matches ){ 116 // offst += $('#wpadminbar').height(); 117 // } 118 119 // $('body').css('padding-top',offst); 120 } 121 } else if (topbar.parent().hasClass('fixed')) { 122 topbar.parent().removeClass('fixed'); 123 topbar.addClass('fixed'); 124 $('body').addClass('nav-expanded'); 125 126 // $('body').css('padding-top','0'); 127 128 if (self.settings.scrolltop) { 129 window.scrollTo(0,0); 130 } 131 } 132 }) 133 134 .on('click.fndtn.topbar', '.top-bar li.has-dropdown', function (e) { 135 if (self.breakpoint()) return; 136 137 var li = $(this), 138 target = $(e.target), 139 topbar = li.closest('[data-topbar], .top-bar'), 140 is_hover = topbar.data('topbar'); 141 142 if (self.settings.is_hover && !Modernizr.touch) return; 143 144 e.stopImmediatePropagation(); 145 146 if (target[0].nodeName === 'A' && target.parent().hasClass('has-dropdown')) { 147 e.preventDefault(); 148 } 149 150 if (li.hasClass('hover')) { 151 li 152 .removeClass('hover') 153 .find('li') 154 .removeClass('hover'); 155 } else { 156 li.addClass('hover'); 157 } 158 }) 159 160 .on('click.fndtn.topbar', '.top-bar .has-dropdown>a, [data-topbar] .has-dropdown>a', function (e) { 161 if (self.breakpoint()) { 162 e.preventDefault(); 163 164 var $this = $(this), 165 topbar = $this.closest('.top-bar, [data-topbar]'), 166 section = topbar.find('section, .section'), 167 titlebar = topbar.children('ul').first(), 168 dropdownHeight = $this.next('.dropdown').outerHeight(), 169 $selectedLi = $this.closest('li'); 170 171 topbar.data('index', topbar.data('index') + 1); 172 $selectedLi.addClass('moved'); 173 174 if (!self.rtl) { 175 section.css({left: -(100 * topbar.data('index')) + '%'}); 176 section.find('>.name').css({left: 100 * topbar.data('index') + '%'}); 177 } else { 178 section.css({right: -(100 * topbar.data('index')) + '%'}); 179 section.find('>.name').css({right: 100 * topbar.data('index') + '%'}); 180 } 181 182 // var topBarPadding = self.outerHeight($this.siblings('ul'), true) + self.height(titlebar); 183 var topBarPadding = self.outerHeight($this.siblings('ul'), true) + self.outerHeight(titlebar); 184 185 // if( $('#wpadminbar').is(':visible') && window.matchMedia("screen and (max-width: 600px)").matches ){ 186 // topBarPadding += $('#wpadminbar').height(); 187 // } 188 189 topbar.css('height', topBarPadding); 190 } 191 }); 192 193 $(window).on('resize.fndtn.topbar', function () { 194 if (!self.breakpoint()) { 195 $('.top-bar, [data-topbar]') 196 .css('height', '') 197 .removeClass('expanded') 198 .find('li') 199 .removeClass('hover'); 200 } 201 }.bind(this)); 202 203 $('body').on('click.fndtn.topbar', function (e) { 204 var parent = $(e.target).closest('[data-topbar], .top-bar'); 205 206 if (parent.length > 0) { 207 return; 208 } 209 210 $('.top-bar li, [data-topbar] li').removeClass('hover'); 211 }); 212 213 // Go up a level on Click 214 $(this.scope).on('click.fndtn', '.top-bar .has-dropdown .back, [data-topbar] .has-dropdown .back', function (e) { 215 e.preventDefault(); 216 217 var $this = $(this), 218 topbar = $this.closest('.top-bar, [data-topbar]'), 219 titlebar = topbar.children('ul').first(), 220 section = topbar.find('section, .section'), 221 $movedLi = $this.closest('li.moved'), 222 $previousLevelUl = $movedLi.parent(); 223 224 topbar.data('index', topbar.data('index') - 1); 225 226 if (!self.rtl) { 227 section.css({left: -(100 * topbar.data('index')) + '%'}); 228 section.find('>.name').css({left: 100 * topbar.data('index') + '%'}); 229 } else { 230 section.css({right: -(100 * topbar.data('index')) + '%'}); 231 section.find('>.name').css({right: 100 * topbar.data('index') + '%'}); 232 } 233 234 if (topbar.data('index') === 0) { 235 topbar.css('height', ''); 236 } else { 237 238 // var topBarPadding = self.outerHeight($previousLevelUl, true) + self.height(titlebar); 239 var topBarPadding = self.outerHeight($previousLevelUl, true) + self.outerHeight(titlebar); 240 241 // if( $('#wpadminbar').is(':visible') && window.matchMedia("screen and (max-width: 600px)").matches ){ 242 // topBarPadding += $('#wpadminbar').height(); 243 // } 244 245 topbar.css('height', topBarPadding); 246 } 247 248 setTimeout(function () { 249 $movedLi.removeClass('moved'); 250 }, 300); 251 }); 252 }, 253 254 breakpoint : function () { 255 return $(document).width() <= this.settings.breakPoint || $('html').hasClass('lt-ie9'); 256 }, 257 258 assemble : function () { 259 var self = this; 260 // Pull element out of the DOM for manipulation 261 this.settings.$section.detach(); 262 263 this.settings.$section.find('.has-dropdown>a').each(function () { 264 var $link = $(this), 265 $dropdown = $link.siblings('.dropdown'), 266 url = $link.attr('href'); 267 268 if (self.settings.mobile_show_parent_link && url && url.length > 1) { 269 var $titleLi = $('<li class="title back js-generated"><h5><a href="#"></a></h5></li><li><a class="parent-link js-generated" href="' + url + '">' + $link.text() +'</a></li>'); 270 } else { 271 var $titleLi = $('<li class="title back js-generated"><h5><a href="#"></a></h5></li>'); 272 } 273 274 // Copy link to subnav 275 if (self.settings.custom_back_text == true) { 276 $titleLi.find('h5>a').html('« ' + self.settings.back_text); 277 } else { 278 $titleLi.find('h5>a').html('« ' + $link.html()); 279 } 280 $dropdown.prepend($titleLi); 281 }); 282 283 // Put element back in the DOM 284 this.settings.$section.appendTo(this.settings.$topbar); 285 286 // check for sticky 287 this.sticky(); 288 }, 289 290 height : function (ul) { 291 var total = 0, 292 self = this; 293 294 ul.find('> li').each(function () { total += self.outerHeight($(this), true); }); 295 296 return total; 297 }, 298 299 sticky : function () { 300 var klass = '.' + this.settings.stickyClass; 301 if ($(klass).length > 0) { 302 var distance = $(klass).length ? $(klass).offset().top: 0, 303 $window = $(window), 304 offst = this.outerHeight($('.top-bar')), 305 t_top; 306 307 //Whe resize elements of the page on windows resize. Must recalculate distance 308 $(window).resize(function() { 309 clearTimeout(t_top); 310 t_top = setTimeout (function() { 311 distance = $(klass).offset().top; 312 },105); 313 });
314 $window.scroll(function() { 315 if ($window.scrollTop() > (distance)) { 316 $(klass).addClass("fixed"); 317 // $('body').css('padding-top',offst); 318 } else if ($window.scrollTop() <= distance) { 319 $(klass).removeClass("fixed"); 320 // $('body').css('padding-top','0'); 321 } 322 }); 323 } 324 }, 325 326 off : function () { 327 $(this.scope).off('.fndtn.topbar'); 328 $(window).off('.fndtn.topbar'); 329 }, 330 331 reflow : function () {} 332 }; 333}(Foundation.zj, this, this.document));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.