var pluginsAsExternals = {
'jquery': 'jQuery',
'./foundation.core': '{Foundation: window.Foundation}',
- './foundation.util.core' : '{rtl: window.Foundation.rtl, GetYoDigits: window.Foundation.GetYoDigits, transitionend: window.Foundation.transitionend, RegExpEscape: window.Foundation.RegExpEscape}',
+ './foundation.util.core' : '{rtl: window.Foundation.rtl, GetYoDigits: window.Foundation.GetYoDigits, transitionend: window.Foundation.transitionend, RegExpEscape: window.Foundation.RegExpEscape, onLoad: window.Foundation.onLoad}',
'./foundation.util.imageLoader' : '{onImagesLoaded: window.Foundation.onImagesLoaded}',
'./foundation.util.keyboard' : '{Keyboard: window.Foundation.Keyboard}',
'./foundation.util.mediaQuery' : '{MediaQuery: window.Foundation.MediaQuery}',
Foundation.GetYoDigits = CoreUtils.GetYoDigits;
Foundation.transitionend = CoreUtils.transitionend;
Foundation.RegExpEscape = CoreUtils.RegExpEscape;
+Foundation.onLoad = CoreUtils.onLoad;
Foundation.Box = Box;
Foundation.onImagesLoaded = onImagesLoaded;
// These are now separated out, but historically were a part of this module,
// and since this is here for backwards compatibility we include them in
// this entry.
-import {rtl, GetYoDigits, transitionend, RegExpEscape} from '../../foundation.util.core';
+import {rtl, GetYoDigits, transitionend, RegExpEscape, onLoad} from '../../foundation.util.core';
Foundation.rtl = rtl;
Foundation.GetYoDigits = GetYoDigits;
Foundation.transitionend = transitionend;
Foundation.RegExpEscape = RegExpEscape;
+Foundation.onLoad = onLoad;
// Every plugin depends on plugin now, we can include that on the core for the
// script inclusion path.
'use strict';
import $ from 'jquery';
+import { onLoad, GetYoDigits } from './foundation.util.core';
import { Keyboard } from './foundation.util.keyboard';
-import { GetYoDigits } from './foundation.util.core';
import { Plugin } from './foundation.plugin';
/**
//roll up a little to show the titles
if (this.options.deepLinkSmudge) {
var _this = this;
- $(window).on('load', function() {
+ onLoad($(window), function() {
var offset = _this.$element.offset();
$('html, body').animate({ scrollTop: offset.top }, _this.options.deepLinkSmudgeDelay);
});
import $ from 'jquery';
-import { GetYoDigits } from './foundation.util.core';
+import { onLoad, GetYoDigits } from './foundation.util.core';
import { Plugin } from './foundation.plugin';
import { SmoothScroll } from './foundation.smoothScroll';
duration: _this.options.animationDuration,
easing: _this.options.animationEasing
};
+
$(window).one('load', function(){
if(_this.options.deepLinking){
if(location.hash){
_this._updateActive();
});
- 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');
- _this.scrollToLoc(arrival);
- });
- } else {
- $(window).one('load', function(){
- _this.$element.on({
+ _this.onLoadListener = onLoad($(window), 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) {
+ })
+ .on('click.zf.magellan', 'a[href^="#"]', function (e) {
e.preventDefault();
- var arrival = this.getAttribute('href');
+ var arrival = _this.getAttribute('href');
_this.scrollToLoc(arrival);
});
- });
- }
-
+ });
+
this._deepLinkScroll = function(e) {
if(_this.options.deepLinking) {
_this.scrollToLoc(window.location.hash);
var hash = this.$active[0].getAttribute('href');
window.location.hash.replace(hash, '');
}
- $(window).off('hashchange', this._deepLinkScroll);
+
+ $(window)
+ .off('hashchange', this._deepLinkScroll)
+ .off(this.onLoadListener);
}
}
'use strict';
import $ from 'jquery';
+import { onLoad, transitionend, RegExpEscape } from './foundation.util.core';
import { Keyboard } from './foundation.util.keyboard';
import { MediaQuery } from './foundation.util.mediaQuery';
-import { transitionend, RegExpEscape } from './foundation.util.core';
import { Plugin } from './foundation.plugin';
import { Triggers } from './foundation.util.triggers';
_setMQChecker() {
var _this = this;
- $(window).on('changed.zf.mediaquery', function() {
+ this.onLoadListener = onLoad($(window), function () {
if (MediaQuery.atLeast(_this.options.revealOn)) {
_this.reveal(true);
- } else {
- _this.reveal(false);
}
- }).one('load.zf.offcanvas', function() {
+ });
+
+ $(window).on('changed.zf.mediaquery', function () {
if (MediaQuery.atLeast(_this.options.revealOn)) {
_this.reveal(true);
+ } else {
+ _this.reveal(false);
}
});
}
this.close();
this.$element.off('.zf.trigger .zf.offcanvas');
this.$overlay.off('.zf.offcanvas');
+ $(window).off(this.onLoadListener);
}
}
'use strict';
import $ from 'jquery';
+import { onLoad } from './foundation.util.core';
import { Keyboard } from './foundation.util.keyboard';
import { MediaQuery } from './foundation.util.mediaQuery';
import { Motion } from './foundation.util.motion';
}
this._events();
if (this.options.deepLink && window.location.hash === ( `#${this.id}`)) {
- $(window).one('load.zf.reveal', this.open.bind(this));
+ this.onLoadListener = onLoad($(window), () => this.open());
}
}
}
this.$element.hide().off();
this.$anchor.off('.zf');
- $(window).off(`.zf.reveal:${this.id}`);
+ $(window)
+ .off(`.zf.reveal:${this.id}`)
+ .off(this.onLoadListener);
if ($('.reveal:visible').length === 0) {
this._removeRevealOpenClasses(); // also remove .is-reveal-open from the html element when there is no opened reveal
'use strict';
import $ from 'jquery';
-import { GetYoDigits } from './foundation.util.core';
+import { onLoad, GetYoDigits } from './foundation.util.core';
import { MediaQuery } from './foundation.util.mediaQuery';
import { Plugin } from './foundation.plugin';
import { Triggers } from './foundation.util.triggers';
this.scrollCount = this.options.checkEvery;
this.isStuck = false;
- $(window).one('load.zf.sticky', function(){
+ this.onLoadListener = onLoad($(window), 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 !== ''){
+ if (_this.options.anchor !== '') {
_this.$anchor = $('#' + _this.options.anchor);
- }else{
+ } else {
_this._parsePoints();
}
- _this._setSizes(function(){
+ _this._setSizes(function () {
var scroll = window.pageYOffset;
_this._calc(false, scroll);
//Unstick the element will ensure that proper classes are set.
if (this.$anchor && this.$anchor.length) {
this.$anchor.off('change.zf.sticky');
}
- $(window).off(this.scrollListener);
+ $(window)
+ .off(this.scrollListener)
+ .off(this.onLoadListener);
if (this.wasWrapped) {
this.$element.unwrap();
'use strict';
import $ from 'jquery';
+import { onLoad } from './foundation.util.core';
import { Keyboard } from './foundation.util.keyboard';
import { onImagesLoaded } from './foundation.util.imageLoader';
import { Plugin } from './foundation.plugin';
}
if(isActive && _this.options.autoFocus){
- $(window).on('load', function() {
+ _this.onLoadListener = onLoad($(window), function() {
$('html, body').animate({ scrollTop: $elem.offset().top }, _this.options.deepLinkSmudgeDelay, () => {
$link.focus();
});
$(window).off('hashchange', this._checkDeepLink);
}
+ $(window).off(this.onLoadListener);
}
}
}
}
-export {rtl, GetYoDigits, RegExpEscape, transitionend};
+/**
+ * Return an event type to listen for window load.
+ *
+ * If `$elem` is passed, an event will be triggered on `$elem`. If window is already loaded, the event will still be triggered.
+ * If `handler` is passed, attach it to the event on `$elem`.
+ * Calling `onLoad` without handler allows you to get the event type that will be triggered before attaching the handler by yourself.
+ * @function
+ *
+ * @param {Object} [] $elem - jQuery element on which the event will be triggered if passed.
+ * @param {Function} [] handler - function to attach to the event.
+ * @returns {String} - event type that should or will be triggered.
+ */
+function onLoad($elem, handler) {
+ const didLoad = document.readyState === 'complete';
+ const eventType = (didLoad ? '_didLoad' : 'load') + '.zf.util.onLoad';
+ const cb = () => $elem.triggerHandler(eventType);
+
+ if ($elem) {
+ if (handler) $elem.one(eventType, handler);
+
+ if (didLoad)
+ setTimeout(cb);
+ else
+ $(window).one('load', cb);
+ }
+
+ return eventType;
+}
+
+export {rtl, GetYoDigits, RegExpEscape, transitionend, onLoad};
'use strict';
import $ from 'jquery';
+import { onLoad } from './foundation.util.core';
import { Motion } from './foundation.util.motion';
const MutationObserver = (function () {
if (typeof($.triggersInitialized) === 'undefined') {
let $document = $(document);
- if(document.readyState === "complete") {
+ onLoad($(window), function () {
Triggers.Initializers.addSimpleListeners();
Triggers.Initializers.addGlobalListeners();
- } else {
- $(window).on('load', () => {
- Triggers.Initializers.addSimpleListeners();
- Triggers.Initializers.addGlobalListeners();
- });
- }
-
+ });
$.triggersInitialized = true;
}
name.should.be.a('string');
name.should.be.equal('');
});
-
+
it('should handle a named function expression', function() {
var D = function foo(){};
var name = Foundation.getFnName(D);
name.should.be.equal('foo');
});
});
-
+
describe('transitionEnd()', function() {
});
+ describe('onLoad()', function (done) {
+ });
+
describe('throttle()', function() {
});
});