_this._updateActive();
});
- this.$element.on({
- 'resizeme.zf.trigger': this.reflow.bind(this),
- 'scrollme.zf.trigger': this._updateActive.bind(this)
- }).on('click.zf.magellan', 'a[href^="#"]', function(e) {
+ if (document.readyState === "complete") {
+ _this.$element.on({
+ 'resizeme.zf.trigger': _this.reflow.bind(_this),
+ 'scrollme.zf.trigger': _this._updateActive.bind(_this)
+ }).on('click.zf.magellan', 'a[href^="#"]', function(e) {
e.preventDefault();
- var arrival = this.getAttribute('href');
+ var arrival = _this.getAttribute('href');
_this.scrollToLoc(arrival);
});
-
+ } else {
+ $(window).one('load', function(){
+ _this.$element.on({
+ 'resizeme.zf.trigger': _this.reflow.bind(_this),
+ 'scrollme.zf.trigger': _this._updateActive.bind(_this)
+ }).on('click.zf.magellan', 'a[href^="#"]', function(e) {
+ e.preventDefault();
+ var arrival = _this.getAttribute('href');
+ _this.scrollToLoc(arrival);
+ });
+ });
+ }
+
this._deepLinkScroll = function(e) {
if(_this.options.deepLinking) {
_this.scrollToLoc(window.location.hash);
SmoothScroll.scrollToLoc(loc, options, function() {
_this._inTransition = false;
- _this._updateActive();
})
}
describe('Magellan', function() {
var plugin;
- var $html, $content;
+ var $html, $content;
var generateUl = function(count) {
var html = '';
animationDuration: duration
});
-
-
// Jump to last section
var target = $html.find('a').eq(-1).attr('href');
- plugin.scrollToLoc(target);
+ plugin.scrollToLoc(target);
- // The `update` event doesn't work properly because it fires too often
setTimeout(function() {
- var isInViewport = false;
- if ($content.find('div').eq(-1).offset().top > $('body').scrollTop() && $content.offset().top < $('body').scrollTop() + $('body').innerHeight()) {
- isInViewport = true;
- }
- isInViewport.should.equal(true);
- done();
+ var isInViewport = false;
+ if ($content.find('div').eq(-1).offset().top > $('body').scrollTop() && $content.offset().top < $('body').scrollTop() + $('body').innerHeight()) {
+ isInViewport = true;
+ }
+ isInViewport.should.equal(true);
+ done();
}, duration);
});
});
var hasError = false;
+ var targets = $html.find('a');
try {
- var target = $html.find('a').eq(-1).attr('href');
- plugin.scrollToLoc(target);
- } catch (err) {
- hasError = true;
+ var target = $(targets).eq(-1).attr('href');
+ plugin.scrollToLoc(target);
+ }
+ catch (err) {
+ hasError = true;
}
hasError.should.equal(false);
-
});
});
-});
\ No newline at end of file
+});