PageSourceSearch

https://studyonline.lt/wp-content/themes/vdu-fakultetas/js/vendor/foundation/foundation.topbar.js?ver=0.0.1

js studyonline.lt collected 2026-10-08 07:08:41 UTC 14,916 bytes, 452 lines download raw bytes

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