Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support dynamically added components #8016 #10947

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions js/foundation.magellan.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,25 @@ class Magellan extends Plugin {
duration: _this.options.animationDuration,
easing: _this.options.animationEasing
};
$(window).one('load', function(){
if (document.readyState === 'complete') {
if(_this.options.deepLinking){
if(location.hash){
_this.scrollToLoc(location.hash);
}
}
_this.calcPoints();
_this._updateActive();
});
} else {
$(window).one('load', function(){
if(_this.options.deepLinking){
if(location.hash){
_this.scrollToLoc(location.hash);
}
}
_this.calcPoints();
_this._updateActive();
});
}
Copy link
Contributor

@ncoden ncoden Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a Magellan component is dynamically created, the window DO NOT scroll to the target corresponding to the location hash as the magellan did not created the target and should appear without effects on it after the page already loaded.

-- #11077 (comment)

@DanielRuf What do you think ?


this.$element.on({
'resizeme.zf.trigger': this.reflow.bind(this),
Expand Down
8 changes: 8 additions & 0 deletions js/foundation.offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ class OffCanvas extends Plugin {
_setMQChecker() {
var _this = this;

if (document.readyState === 'complete') {
if (MediaQuery.atLeast(_this.options.revealOn)) {
_this.reveal(true);
} else {
_this.reveal(false);
}
}

$(window).on('changed.zf.mediaquery', function() {
if (MediaQuery.atLeast(_this.options.revealOn)) {
_this.reveal(true);
Expand Down
6 changes: 5 additions & 1 deletion js/foundation.reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ class Reveal extends Plugin {
}
this._events();
if (this.options.deepLink && window.location.hash === ( `#${this.id}`)) {
$(window).one('load.zf.reveal', this.open.bind(this));
if (document.readyState === 'complete') {
this.open.bind(this)
} else {
$(window).one('load.zf.reveal', this.open.bind(this));
}
}
}

Expand Down
28 changes: 25 additions & 3 deletions js/foundation.sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Sticky extends Plugin {

this.scrollCount = this.options.checkEvery;
this.isStuck = false;
$(window).one('load.zf.sticky', function(){
//We calculate the container height to have correct values for anchor points offset calculation.
if (document.readyState === 'complete') {
//We calculate the container height to have correct values for anchor points offset calculation.
_this.containerHeight = _this.$element.css("display") == "none" ? 0 : _this.$element[0].getBoundingClientRect().height;
_this.$container.css('height', _this.containerHeight);
_this.elemHeight = _this.containerHeight;
Expand All @@ -80,7 +80,29 @@ class Sticky extends Plugin {
}
});
_this._events(id.split('-').reverse().join('-'));
});
} else {
$(window).one('load.zf.sticky', function(){
//We calculate the container height to have correct values for anchor points offset calculation.
_this.containerHeight = _this.$element.css("display") == "none" ? 0 : _this.$element[0].getBoundingClientRect().height;
_this.$container.css('height', _this.containerHeight);
_this.elemHeight = _this.containerHeight;
if(_this.options.anchor !== ''){
_this.$anchor = $('#' + _this.options.anchor);
}else{
_this._parsePoints();
}

_this._setSizes(function(){
var scroll = window.pageYOffset;
_this._calc(false, scroll);
//Unstick the element will ensure that proper classes are set.
if (!_this.isStuck) {
_this._removeSticky((scroll >= _this.topPoint) ? false : true);
}
});
_this._events(id.split('-').reverse().join('-'));
});
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/foundation.util.triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Triggers.init = function($, Foundation) {
if (typeof($.triggersInitialized) === 'undefined') {
let $document = $(document);

if(document.readyState === "complete") {
if (document.readyState === 'complete') {
Triggers.Initializers.addSimpleListeners();
Triggers.Initializers.addGlobalListeners();
} else {
Expand Down