vendor/assets/javascripts/foundation/foundation.topbar.js in foundation-rails-5.3.3.0 vs vendor/assets/javascripts/foundation/foundation.topbar.js in foundation-rails-5.4.0.0
- old
+ new
@@ -14,11 +14,11 @@
mobile_show_parent_link: true,
is_hover: true,
scrolltop : true, // jump to top when sticky nav menu toggle is clicked
sticky_on : 'all'
},
-
+
init : function (section, method, options) {
Foundation.inherit(this, 'add_custom_rule register_media throttle');
var self = this;
self.register_media('topbar', 'foundation-mq-topbar');
@@ -26,11 +26,11 @@
this.bindings(method, options);
self.S('[' + this.attr_name() + ']', this.scope).each(function () {
var topbar = $(this),
settings = topbar.data(self.attr_name(true) + '-init'),
- section = self.S('section', this);
+ section = self.S('section, .top-bar-section', this);
topbar.data('index', 0);
var topbarContainer = topbar.parent();
if (topbarContainer.hasClass('fixed') || self.is_sticky(topbar, topbarContainer, settings) ) {
self.settings.sticky_class = settings.sticky_class;
self.settings.sticky_topbar = topbar;
@@ -65,11 +65,11 @@
if (sticky && settings.sticky_on === 'all') {
return true;
} else if (sticky && this.small() && settings.sticky_on === 'small') {
return (matchMedia(Foundation.media_queries.small).matches && !matchMedia(Foundation.media_queries.medium).matches &&
- !matchMedia(Foundation.media_queries.large).matches);
+ !matchMedia(Foundation.media_queries.large).matches);
//return true;
} else if (sticky && this.medium() && settings.sticky_on === 'medium') {
return (matchMedia(Foundation.media_queries.small).matches && matchMedia(Foundation.media_queries.medium).matches &&
!matchMedia(Foundation.media_queries.large).matches);
//return true;
@@ -92,11 +92,11 @@
topbar = self.S('[' + this.attr_name() + ']');
}
var settings = topbar.data(this.attr_name(true) + '-init');
- var section = self.S('section, .section', topbar);
+ var section = self.S('section, .top-bar-section', topbar);
if (self.breakpoint()) {
if (!self.rtl) {
section.css({left: '0%'});
$('>.name', section).css({left: '100%'});
@@ -208,11 +208,11 @@
e.preventDefault();
var $this = S(this),
topbar = $this.closest('[' + self.attr_name() + ']'),
- section = topbar.find('section, .section'),
+ section = topbar.find('section, .top-bar-section'),
dropdownHeight = $this.next('.dropdown').outerHeight(),
$selectedLi = $this.closest('li');
topbar.data('index', topbar.data('index') + 1);
$selectedLi.addClass('moved');
@@ -226,15 +226,18 @@
}
topbar.css('height', $this.siblings('ul').outerHeight(true) + topbar.data('height'));
}
});
-
- S(window).off('.topbar').on('resize.fndtn.topbar', self.throttle(function () {
- self.resize.call(self);
- }, 50)).trigger('resize').trigger('resize.fndtn.topbar');
+ S(window).off(".topbar").on("resize.fndtn.topbar", self.throttle(function() {
+ self.resize.call(self);
+ }, 50)).trigger("resize").trigger("resize.fndtn.topbar").load(function(){
+ // Ensure that the offset is calculated after all of the pages resources have loaded
+ S(this).trigger("resize.fndtn.topbar");
+ });
+
S('body').off('.topbar').on('click.fndtn.topbar', function (e) {
var parent = S(e.target).closest('li').closest('li.hover');
if (parent.length > 0) {
return;
@@ -247,11 +250,11 @@
S(this.scope).on('click.fndtn.topbar', '[' + this.attr_name() + '] .has-dropdown .back', function (e) {
e.preventDefault();
var $this = S(this),
topbar = $this.closest('[' + self.attr_name() + ']'),
- section = topbar.find('section, .section'),
+ section = topbar.find('section, .top-bar-section'),
settings = topbar.data(self.attr_name(true) + '-init'),
$movedLi = $this.closest('li.moved'),
$previousLevelUl = $movedLi.parent();
topbar.data('index', topbar.data('index') - 1);
@@ -336,11 +339,11 @@
},
assemble : function (topbar) {
var self = this,
settings = topbar.data(this.attr_name(true) + '-init'),
- section = self.S('section', topbar);
+ section = self.S('section, .top-bar-section', topbar);
// Pull element out of the DOM for manipulation
section.detach();
self.S('.has-dropdown>a', section).each(function () {
@@ -355,11 +358,11 @@
if (settings.mobile_show_parent_link == true && url) {
$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>');
} else {
$titleLi = $('<li class="title back js-generated"><h5><a href="javascript:void(0)"></a></h5>');
}
-
+
// Copy link to subnav
if (settings.custom_back_text == true) {
$('h5>a', $titleLi).html(settings.back_text);
} else {
$('h5>a', $titleLi).html('« ' + $link.html());
@@ -383,12 +386,12 @@
height : function (ul) {
var total = 0,
self = this;
- $('> li', ul).each(function () {
- total += self.S(this).outerHeight(true);
+ $('> li', ul).each(function () {
+ total += self.S(this).outerHeight(true);
});
return total;
},
@@ -400,11 +403,11 @@
});
},
update_sticky_positioning: function() {
var klass = '.' + this.settings.sticky_class,
- $window = this.S(window),
+ $window = this.S(window),
self = this;
if (self.settings.sticky_topbar && self.is_sticky(this.settings.sticky_topbar,this.settings.sticky_topbar.parent(), this.settings)) {
var distance = this.settings.sticky_topbar.data('stickyoffset');
if (!self.S(klass).hasClass('expanded')) {
@@ -428,6 +431,6 @@
this.S(window).off('.fndtn.topbar');
},
reflow : function () {}
};
-}(jQuery, this, this.document));
+}(jQuery, window, window.document));