UNPKG

12.8 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./foundation.core"),require("./foundation.smoothScroll"),require("./foundation.util.motion"),require("jquery")):"function"==typeof define&&define.amd?define(["./foundation.core","./foundation.smoothScroll","./foundation.util.motion","jquery"],e):"object"==typeof exports?exports["foundation.magellan"]=e(require("./foundation.core"),require("./foundation.smoothScroll"),require("./foundation.util.motion"),require("jquery")):(t.__FOUNDATION_EXTERNAL__=t.__FOUNDATION_EXTERNAL__||{},t.__FOUNDATION_EXTERNAL__["foundation.magellan"]=e(t.__FOUNDATION_EXTERNAL__["foundation.core"],t.__FOUNDATION_EXTERNAL__["foundation.smoothScroll"],t.__FOUNDATION_EXTERNAL__["foundation.util.motion"],t.jQuery))}(window,function(i,n,o,r){return l={},a.m=s={"./foundation.core":function(t,e){t.exports=i},"./foundation.smoothScroll":function(t,e){t.exports=n},"./foundation.util.motion":function(t,e){t.exports=o},"./js/entries/plugins/foundation.magellan.js":function(t,e,i){"use strict";i.r(e);var n=i("./foundation.core");i.d(e,"Foundation",function(){return n.Foundation});var o=i("./js/foundation.magellan.js");i.d(e,"Magellan",function(){return o.Magellan}),n.Foundation.plugin(o.Magellan,"Magellan")},"./js/foundation.magellan.js":function(t,e,i){"use strict";i.r(e),i.d(e,"Magellan",function(){return g});var n=i("jquery"),u=i.n(n),o=i("./foundation.core"),r=i("./foundation.smoothScroll"),a=i("./js/foundation.util.triggers.js");function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e){return!e||"object"!==s(e)&&"function"!=typeof e?function(t){if(void 0!==t)return t;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function d(t,e){return(d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var g=function(){function i(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),c(this,f(i).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&d(t,e)}(i,o["Plugin"]),function(t,e,i){e&&l(t.prototype,e),i&&l(t,i)}(i,[{key:"_setup",value:function(t,e){this.$element=t,this.options=u.a.extend({},i.defaults,this.$element.data(),e),this.className="Magellan",a.Triggers.init(u.a),this._init(),this.calcPoints()}},{key:"_init",value:function(){var t=this.$element[0].id||Object(o.GetYoDigits)(6,"magellan");this.$targets=u()("[data-magellan-target]"),this.$links=this.$element.find("a"),this.$element.attr({"data-resize":t,"data-scroll":t,id:t}),this.$active=u()(),this.scrollPos=parseInt(window.pageYOffset,10),this._events()}},{key:"calcPoints",value:function(){var i=this,t=document.body,e=document.documentElement;this.points=[],this.winHeight=Math.round(Math.max(window.innerHeight,e.clientHeight)),this.docHeight=Math.round(Math.max(t.scrollHeight,t.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight)),this.$targets.each(function(){var t=u()(this),e=Math.round(t.offset().top-i.options.threshold);t.targetPoint=e,i.points.push(e)})}},{key:"_events",value:function(){var i=this;u()(window).one("load",function(){i.options.deepLinking&&location.hash&&i.scrollToLoc(location.hash),i.calcPoints(),i._updateActive()}),i.onLoadListener=Object(o.onLoad)(u()(window),function(){i.$element.on({"resizeme.zf.trigger":i.reflow.bind(i),"scrollme.zf.trigger":i._updateActive.bind(i)}).on("click.zf.magellan",'a[href^="#"]',function(t){t.preventDefault();var e=this.getAttribute("href");i.scrollToLoc(e)})}),this._deepLinkScroll=function(t){i.options.deepLinking&&i.scrollToLoc(window.location.hash)},u()(window).on("hashchange",this._deepLinkScroll)}},{key:"scrollToLoc",value:function(t){this._inTransition=!0;var e=this,i={animationEasing:this.options.animationEasing,animationDuration:this.options.animationDuration,threshold:this.options.threshold,offset:this.options.offset};r.SmoothScroll.scrollToLoc(t,i,function(){e._inTransition=!1})}},{key:"reflow",value:function(){this.calcPoints(),this._updateActive()}},{key:"_updateActive",value:function(){var i=this;if(!this._inTransition){var t,n=parseInt(window.pageYOffset,10),o=this.scrollPos>n;if((this.scrollPos=n)<this.points[0]);else if(n+this.winHeight===this.docHeight)t=this.points.length-1;else{var e=this.points.filter(function(t,e){return t-i.options.offset-(o?i.options.threshold:0)<=n});t=e.length?e.length-1:0}var r=this.$active,a="";void 0!==t?(this.$active=this.$links.filter('[href="#'+this.$targets.eq(t).data("magellan-target")+'"]'),this.$active.length&&(a=this.$active[0].getAttribute("href"))):this.$active=u()();var s=!(!this.$active.length&&!r.length||this.$active.is(r)),l=a!==window.location.hash;if(s&&(r.removeClass(this.options.activeClass),this.$active.addClass(this.options.activeClass)),this.options.deepLinking&&l)if(window.history.pushState){var c=a||window.location.pathname+window.location.search;this.options.updateHistory?window.history.pushState({},"",c):window.history.replaceState({},"",c)}else window.location.hash=a;s&&this.$element.trigger("update.zf.magellan",[this.$active])}}},{key:"_destroy",value:function(){if(this.$element.off(".zf.trigger .zf.magellan").find(".".concat(this.options.activeClass)).removeClass(this.options.activeClass),this.options.deepLinking){var t=this.$active[0].getAttribute("href");window.location.hash.replace(t,"")}u()(window).off("hashchange",this._deepLinkScroll),this.onLoadListener&&u()(window).off(this.onLoadListener)}}]),i}();g.defaults={animationDuration:500,animationEasing:"linear",threshold:50,activeClass:"is-active",deepLinking:!1,updateHistory:!1,offset:0}},"./js/foundation.util.triggers.js":function(t,e,i){"use strict";i.r(e),i.d(e,"Triggers",function(){return u});var n=i("jquery"),r=i.n(n),o=i("./foundation.core"),a=i("./foundation.util.motion");function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(e,i){e.data(i).split(" ").forEach(function(t){r()("#".concat(t))["close"===i?"trigger":"triggerHandler"]("".concat(i,".zf.trigger"),[e])})}var c=function(){for(var t=["WebKit","Moz","O","Ms",""],e=0;e<t.length;e++)if("".concat(t[e],"MutationObserver")in window)return window["".concat(t[e],"MutationObserver")];return!1}(),u={Listeners:{Basic:{},Global:{}},Initializers:{}};function f(e,t,i){var n,o=Array.prototype.slice.call(arguments,3);r()(window).off(t).on(t,function(t){n&&clearTimeout(n),n=setTimeout(function(){i.apply(null,o)},e||10)})}u.Listeners.Basic={openListener:function(){l(r()(this),"open")},closeListener:function(){r()(this).data("close")?l(r()(this),"close"):r()(this).trigger("close.zf.trigger")},toggleListener:function(){r()(this).data("toggle")?l(r()(this),"toggle"):r()(this).trigger("toggle.zf.trigger")},closeableListener:function(t){var e=r()(this).data("closable");t.stopPropagation(),""!==e?a.Motion.animateOut(r()(this),e,function(){r()(this).trigger("closed.zf")}):r()(this).fadeOut().trigger("closed.zf")},toggleFocusListener:function(){var t=r()(this).data("toggle-focus");r()("#".concat(t)).triggerHandler("toggle.zf.trigger",[r()(this)])}},u.Initializers.addOpenListener=function(t){t.off("click.zf.trigger",u.Listeners.Basic.openListener),t.on("click.zf.trigger","[data-open]",u.Listeners.Basic.openListener)},u.Initializers.addCloseListener=function(t){t.off("click.zf.trigger",u.Listeners.Basic.closeListener),t.on("click.zf.trigger","[data-close]",u.Listeners.Basic.closeListener)},u.Initializers.addToggleListener=function(t){t.off("click.zf.trigger",u.Listeners.Basic.toggleListener),t.on("click.zf.trigger","[data-toggle]",u.Listeners.Basic.toggleListener)},u.Initializers.addCloseableListener=function(t){t.off("close.zf.trigger",u.Listeners.Basic.closeableListener),t.on("close.zf.trigger","[data-closeable], [data-closable]",u.Listeners.Basic.closeableListener)},u.Initializers.addToggleFocusListener=function(t){t.off("focus.zf.trigger blur.zf.trigger",u.Listeners.Basic.toggleFocusListener),t.on("focus.zf.trigger blur.zf.trigger","[data-toggle-focus]",u.Listeners.Basic.toggleFocusListener)},u.Listeners.Global={resizeListener:function(t){c||t.each(function(){r()(this).triggerHandler("resizeme.zf.trigger")}),t.attr("data-events","resize")},scrollListener:function(t){c||t.each(function(){r()(this).triggerHandler("scrollme.zf.trigger")}),t.attr("data-events","scroll")},closeMeListener:function(t,e){var i=t.namespace.split(".")[0];r()("[data-".concat(i,"]")).not('[data-yeti-box="'.concat(e,'"]')).each(function(){var t=r()(this);t.triggerHandler("close.zf.trigger",[t])})}},u.Initializers.addClosemeListener=function(t){var e=r()("[data-yeti-box]"),i=["dropdown","tooltip","reveal"];if(t&&("string"==typeof t?i.push(t):"object"===s(t)&&"string"==typeof t[0]?i=i.concat(t):console.error("Plugin names must be strings")),e.length){var n=i.map(function(t){return"closeme.zf.".concat(t)}).join(" ");r()(window).off(n).on(n,u.Listeners.Global.closeMeListener)}},u.Initializers.addResizeListener=function(t){var e=r()("[data-resize]");e.length&&f(t,"resize.zf.trigger",u.Listeners.Global.resizeListener,e)},u.Initializers.addScrollListener=function(t){var e=r()("[data-scroll]");e.length&&f(t,"scroll.zf.trigger",u.Listeners.Global.scrollListener,e)},u.Initializers.addMutationEventsListener=function(t){if(!c)return!1;function e(t){var e=r()(t[0].target);switch(t[0].type){case"attributes":"scroll"===e.attr("data-events")&&"data-events"===t[0].attributeName&&e.triggerHandler("scrollme.zf.trigger",[e,window.pageYOffset]),"resize"===e.attr("data-events")&&"data-events"===t[0].attributeName&&e.triggerHandler("resizeme.zf.trigger",[e]),"style"===t[0].attributeName&&(e.closest("[data-mutate]").attr("data-events","mutate"),e.closest("[data-mutate]").triggerHandler("mutateme.zf.trigger",[e.closest("[data-mutate]")]));break;case"childList":e.closest("[data-mutate]").attr("data-events","mutate"),e.closest("[data-mutate]").triggerHandler("mutateme.zf.trigger",[e.closest("[data-mutate]")]);break;default:return!1}}var i=t.find("[data-resize], [data-scroll], [data-mutate]");if(i.length)for(var n=0;n<=i.length-1;n++){new c(e).observe(i[n],{attributes:!0,childList:!0,characterData:!1,subtree:!0,attributeFilter:["data-events","style"]})}},u.Initializers.addSimpleListeners=function(){var t=r()(document);u.Initializers.addOpenListener(t),u.Initializers.addCloseListener(t),u.Initializers.addToggleListener(t),u.Initializers.addCloseableListener(t),u.Initializers.addToggleFocusListener(t)},u.Initializers.addGlobalListeners=function(){var t=r()(document);u.Initializers.addMutationEventsListener(t),u.Initializers.addResizeListener(),u.Initializers.addScrollListener(),u.Initializers.addClosemeListener()},u.init=function(t,e){Object(o.onLoad)(t(window),function(){!0!==t.triggersInitialized&&(u.Initializers.addSimpleListeners(),u.Initializers.addGlobalListeners(),t.triggersInitialized=!0)}),e&&(e.Triggers=u,e.IHearYou=u.Initializers.addGlobalListeners)}},8:function(t,e,i){t.exports=i("./js/entries/plugins/foundation.magellan.js")},jquery:function(t,e){t.exports=r}},a.c=l,a.d=function(t,e,i){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(a.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(i,n,function(t){return e[t]}.bind(null,n));return i},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a(a.s=8);function a(t){if(l[t])return l[t].exports;var e=l[t]={i:t,l:!1,exports:{}};return s[t].call(e.exports,e,e.exports,a),e.l=!0,e.exports}var s,l});
2//# sourceMappingURL=foundation.magellan.min.js.map