foundation-sites
Version:
The most advanced responsive front-end framework in the world.
3 lines (2 loc) • 20.1 kB
JavaScript
((t,e)=>{"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./foundation.core"),require("jquery"),require("./foundation.util.keyboard"),require("./foundation.util.box"),require("./foundation.util.motion"),require("./foundation.util.touch")):"function"==typeof define&&define.amd?define(["./foundation.core","jquery","./foundation.util.keyboard","./foundation.util.box","./foundation.util.motion","./foundation.util.touch"],e):"object"==typeof exports?exports.__FOUNDATION_EXTERNAL__=e(require("./foundation.core"),require("jquery"),require("./foundation.util.keyboard"),require("./foundation.util.box"),require("./foundation.util.motion"),require("./foundation.util.touch")):(t.__FOUNDATION_EXTERNAL__=t.__FOUNDATION_EXTERNAL__||{},t.__FOUNDATION_EXTERNAL__["foundation.dropdown"]=e(t.__FOUNDATION_EXTERNAL__["foundation.core"],t.jQuery,t.__FOUNDATION_EXTERNAL__["foundation.util.keyboard"],t.__FOUNDATION_EXTERNAL__["foundation.util.box"],t.__FOUNDATION_EXTERNAL__["foundation.util.motion"],t.__FOUNDATION_EXTERNAL__["foundation.util.touch"]))})(self,function(e,o,n,i,r,s){return l={"./js/foundation.dropdown.js":function(t,e,o){o.r(e),o.d(e,{Dropdown:function(){return n}});var e=o("jquery"),i=o.n(e),r=o("./foundation.util.keyboard"),s=o("./foundation.core"),e=o("./js/foundation.positionable.js"),a=o("./js/foundation.util.triggers.js"),l=o("./foundation.util.touch");function u(t){return(u="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 c(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(t=>(t=((t,e)=>{if("object"!=u(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0===o)return("string"===e?String:Number)(t);if("object"!=u(o=o.call(t,e||"default")))return o;throw new TypeError("@@toPrimitive must return a primitive value.")})(t,"string"),"symbol"==u(t)?t:t+""))(n.key),n)}}function f(t,e,o){e=g(e);var n=t,e=d()?Reflect.construct(e,o||[],g(t).constructor):e.apply(t,o);if(!e||"object"!=u(e)&&"function"!=typeof e){if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");if(void 0===(e=n))throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function d(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(d=function(){return!!t})()}function p(t,e,o,n){var i=h(g(1&n?t.prototype:t),e,o);return 2&n&&"function"==typeof i?function(t){return i.apply(o,t)}:i}function h(){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,o){var n=((t,e)=>{for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=g(t)););return t})(t,e);if(n)return(n=Object.getOwnPropertyDescriptor(n,e)).get?n.get.call(arguments.length<3?t:o):n.value}).apply(null,arguments)}function g(t){return(g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function m(t,e){return(m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var n=(t=>{function o(){var t=this,e=o;if(t instanceof e)return f(this,o,arguments);throw new TypeError("Cannot call a class as a function")}var e,n=o;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");return n.prototype=Object.create(t&&t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),t&&m(n,t),n=o,(t=[{key:"_setup",value:function(t,e){this.$element=t,this.options=i().extend({},o.defaults,this.$element.data(),e),this.className="Dropdown",l.Touch.init(i()),a.Triggers.init(i()),this._init(),r.Keyboard.register("Dropdown",{ENTER:"toggle",SPACE:"toggle",ESCAPE:"close"})}},{key:"_init",value:function(){var t=this.$element.attr("id");this.$anchors=i()('[data-toggle="'.concat(t,'"]')).length?i()('[data-toggle="'.concat(t,'"]')):i()('[data-open="'.concat(t,'"]')),this.$anchors.attr({"aria-controls":t,"data-is-focus":!1,"data-yeti-box":t,"aria-haspopup":!0,"aria-expanded":!1}),this._setCurrentAnchor(this.$anchors.first()),this.options.parentClass?this.$parent=this.$element.parents("."+this.options.parentClass):this.$parent=null,void 0===this.$element.attr("aria-labelledby")&&(void 0===this.$currentAnchor.attr("id")&&this.$currentAnchor.attr("id",(0,s.GetYoDigits)(6,"dd-anchor")),this.$element.attr("aria-labelledby",this.$currentAnchor.attr("id"))),this.$element.attr({"aria-hidden":"true","data-yeti-box":t,"data-resize":t}),p(o,"_init",this,3)([]),this._events()}},{key:"_getDefaultPosition",value:function(){var t=this.$element[0].className.match(/(top|left|right|bottom)/g);return t?t[0]:"bottom"}},{key:"_getDefaultAlignment",value:function(){var t=/float-(\S+)/.exec(this.$currentAnchor.attr("class"));return t?t[1]:p(o,"_getDefaultAlignment",this,3)([])}},{key:"_setPosition",value:function(){this.$element.removeClass("has-position-".concat(this.position," has-alignment-").concat(this.alignment)),p(o,"_setPosition",this,3)([this.$currentAnchor,this.$element,this.$parent]),this.$element.addClass("has-position-".concat(this.position," has-alignment-").concat(this.alignment))}},{key:"_setCurrentAnchor",value:function(t){this.$currentAnchor=i()(t)}},{key:"_events",value:function(){var o=this,e="ontouchstart"in window||void 0!==window.ontouchstart;this.$element.on({"open.zf.trigger":this.open.bind(this),"close.zf.trigger":this.close.bind(this),"toggle.zf.trigger":this.toggle.bind(this),"resizeme.zf.trigger":this._setPosition.bind(this)}),this.$anchors.off("click.zf.trigger").on("click.zf.trigger",function(t){o._setCurrentAnchor(this),(!1===o.options.forceFollow||e&&o.options.hover&&!1===o.$element.hasClass("is-open"))&&t.preventDefault()}),this.options.hover&&(this.$anchors.off("mouseenter.zf.dropdown mouseleave.zf.dropdown").on("mouseenter.zf.dropdown",function(){o._setCurrentAnchor(this);var t=i()("body").data();void 0!==t.whatinput&&"mouse"!==t.whatinput||(clearTimeout(o.timeout),o.timeout=setTimeout(function(){o.open(),o.$anchors.data("hover",!0)},o.options.hoverDelay))}).on("mouseleave.zf.dropdown",(0,s.ignoreMousedisappear)(function(){clearTimeout(o.timeout),o.timeout=setTimeout(function(){o.close(),o.$anchors.data("hover",!1)},o.options.hoverDelay)})),this.options.hoverPane)&&this.$element.off("mouseenter.zf.dropdown mouseleave.zf.dropdown").on("mouseenter.zf.dropdown",function(){clearTimeout(o.timeout)}).on("mouseleave.zf.dropdown",(0,s.ignoreMousedisappear)(function(){clearTimeout(o.timeout),o.timeout=setTimeout(function(){o.close(),o.$anchors.data("hover",!1)},o.options.hoverDelay)})),this.$anchors.add(this.$element).on("keydown.zf.dropdown",function(t){var e=i()(this);r.Keyboard.handleKey(t,"Dropdown",{open:function(){e.is(o.$anchors)&&!e.is("input, textarea")&&(o.open(),o.$element.attr("tabindex",-1).focus(),t.preventDefault())},close:function(){o.close(),o.$anchors.focus()}})})}},{key:"_addBodyHandler",value:function(){var e=i()(document.body).not(this.$element),o=this;e.off("click.zf.dropdown tap.zf.dropdown").on("click.zf.dropdown tap.zf.dropdown",function(t){o.$anchors.is(t.target)||o.$anchors.find(t.target).length||o.$element.is(t.target)||o.$element.find(t.target).length||(o.close(),e.off("click.zf.dropdown tap.zf.dropdown"))})}},{key:"open",value:function(){var t;this.$element.trigger("closeme.zf.dropdown",this.$element.attr("id")),this.$anchors.addClass("hover").attr({"aria-expanded":!0}),this.$element.addClass("is-opening"),this._setPosition(),this.$element.removeClass("is-opening").addClass("is-open").attr({"aria-hidden":!1}),this.options.autoFocus&&(t=r.Keyboard.findFocusable(this.$element)).length&&t.eq(0).focus(),this.options.closeOnClick&&this._addBodyHandler(),this.options.trapFocus&&r.Keyboard.trapFocus(this.$element),this.$element.trigger("show.zf.dropdown",[this.$element])}},{key:"close",value:function(){if(!this.$element.hasClass("is-open"))return!1;this.$element.removeClass("is-open").attr({"aria-hidden":!0}),this.$anchors.removeClass("hover").attr("aria-expanded",!1),this.$element.trigger("hide.zf.dropdown",[this.$element]),this.options.trapFocus&&r.Keyboard.releaseFocus(this.$element)}},{key:"toggle",value:function(){this.$element.hasClass("is-open")?this.$anchors.data("hover")||this.close():this.open()}},{key:"_destroy",value:function(){this.$element.off(".zf.trigger").hide(),this.$anchors.off(".zf.dropdown"),i()(document.body).off("click.zf.dropdown tap.zf.dropdown")}}])&&c(n.prototype,t),e&&c(n,e),Object.defineProperty(n,"prototype",{writable:!1}),n})(e.Positionable);n.defaults={parentClass:null,hoverDelay:250,hover:!1,hoverPane:!1,vOffset:0,hOffset:0,position:"auto",alignment:"auto",allowOverlap:!1,allowBottomOverlap:!0,trapFocus:!1,autoFocus:!1,closeOnClick:!1,forceFollow:!0}},"./js/foundation.positionable.js":function(t,e,o){o.r(e),o.d(e,{Positionable:function(){return n}});var s=o("./foundation.util.box"),i=o("./foundation.core");function r(t){return(r="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 a(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(t=>(t=((t,e)=>{if("object"!=r(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0===o)return("string"===e?String:Number)(t);if("object"!=r(o=o.call(t,e||"default")))return o;throw new TypeError("@@toPrimitive must return a primitive value.")})(t,"string"),"symbol"==r(t)?t:t+""))(n.key),n)}}function l(t,e,o){e=c(e);var n=t,e=u()?Reflect.construct(e,o||[],c(t).constructor):e.apply(t,o);if(!e||"object"!=r(e)&&"function"!=typeof e){if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");if(void 0===(e=n))throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(u=function(){return!!t})()}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var d=["left","right","top","bottom"],e=["top","bottom","center"],o=["left","right","center"],p={left:e,right:e,top:o,bottom:o};function h(t,e){t=e.indexOf(t);return t===e.length-1?e[0]:e[t+1]}var n=(t=>{function o(){var t=this,e=o;if(t instanceof e)return l(this,o,arguments);throw new TypeError("Cannot call a class as a function")}var e,n=o;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");return n.prototype=Object.create(t&&t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),t&&f(n,t),n=o,(t=[{key:"_init",value:function(){this.triedPositions={},this.position="auto"===this.options.position?this._getDefaultPosition():this.options.position,this.alignment="auto"===this.options.alignment?this._getDefaultAlignment():this.options.alignment,this.originalPosition=this.position,this.originalAlignment=this.alignment}},{key:"_getDefaultPosition",value:function(){return"bottom"}},{key:"_getDefaultAlignment",value:function(){switch(this.position){case"bottom":case"top":return(0,i.rtl)()?"right":"left";case"left":case"right":return"bottom"}}},{key:"_reposition",value:function(){this._alignmentsExhausted(this.position)?(this.position=h(this.position,d),this.alignment=p[this.position][0]):this._realign()}},{key:"_realign",value:function(){this._addTriedPosition(this.position,this.alignment),this.alignment=h(this.alignment,p[this.position])}},{key:"_addTriedPosition",value:function(t,e){this.triedPositions[t]=this.triedPositions[t]||[],this.triedPositions[t].push(e)}},{key:"_positionsExhausted",value:function(){for(var t=!0,e=0;e<d.length;e++)t=t&&this._alignmentsExhausted(d[e]);return t}},{key:"_alignmentsExhausted",value:function(t){return this.triedPositions[t]&&this.triedPositions[t].length===p[t].length}},{key:"_getVOffset",value:function(){return this.options.vOffset}},{key:"_getHOffset",value:function(){return this.options.hOffset}},{key:"_setPosition",value:function(t,e,o){if("false"===t.attr("aria-expanded"))return!1;if(this.options.allowOverlap||(this.position=this.originalPosition,this.alignment=this.originalAlignment),e.offset(s.Box.GetExplicitOffsets(e,t,this.position,this.alignment,this._getVOffset(),this._getHOffset())),!this.options.allowOverlap){for(var n=1e8,i={position:this.position,alignment:this.alignment};!this._positionsExhausted();){var r=s.Box.OverlapArea(e,o,!1,!1,this.options.allowBottomOverlap);if(0===r)return;r<n&&(n=r,i={position:this.position,alignment:this.alignment}),this._reposition(),e.offset(s.Box.GetExplicitOffsets(e,t,this.position,this.alignment,this._getVOffset(),this._getHOffset()))}this.position=i.position,this.alignment=i.alignment,e.offset(s.Box.GetExplicitOffsets(e,t,this.position,this.alignment,this._getVOffset(),this._getHOffset()))}}}])&&a(n.prototype,t),e&&a(n,e),Object.defineProperty(n,"prototype",{writable:!1}),n})(i.Plugin);n.defaults={position:"auto",alignment:"auto",allowOverlap:!1,allowBottomOverlap:!0,vOffset:0,hOffset:0}},"./js/foundation.util.triggers.js":function(t,e,o){o.r(e),o.d(e,{Triggers:function(){return u}});var e=o("jquery"),r=o.n(e),n=o("./foundation.core"),i=o("./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 a(e,o){e.data(o).split(" ").forEach(function(t){r()("#".concat(t))["close"===o?"trigger":"triggerHandler"]("".concat(o,".zf.trigger"),[e])})}var l=(()=>{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 c(t,e,o){var n,i=Array.prototype.slice.call(arguments,3);r()(window).on(e,function(){n&&clearTimeout(n),n=setTimeout(function(){o.apply(null,i)},t||10)})}u.Listeners.Basic={openListener:function(){a(r()(this),"open")},closeListener:function(){r()(this).data("close")?a(r()(this),"close"):r()(this).trigger("close.zf.trigger")},toggleListener:function(){r()(this).data("toggle")?a(r()(this),"toggle"):r()(this).trigger("toggle.zf.trigger")},closeableListener:function(t){var e=r()(this).data("closable");t.stopPropagation(),""!==e?i.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){l||t.each(function(){r()(this).triggerHandler("resizeme.zf.trigger")}),t.attr("data-events","resize")},scrollListener:function(t){l||t.each(function(){r()(this).triggerHandler("scrollme.zf.trigger")}),t.attr("data-events","scroll")},closeMeListener:function(t,e){t=t.namespace.split(".")[0];r()("[data-".concat(t,"]")).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]"),o=["dropdown","tooltip","reveal"];t&&("string"==typeof t?o.push(t):"object"===s(t)&&"string"==typeof t[0]?o=o.concat(t):console.error("Plugin names must be strings")),e.length&&(t=o.map(function(t){return"closeme.zf.".concat(t)}).join(" "),r()(window).off(t).on(t,u.Listeners.Global.closeMeListener))},u.Initializers.addResizeListener=function(t){var e=r()("[data-resize]");e.length&&c(t,"resize.zf.trigger",u.Listeners.Global.resizeListener,e)},u.Initializers.addScrollListener=function(t){var e=r()("[data-scroll]");e.length&&c(t,"scroll.zf.trigger",u.Listeners.Global.scrollListener,e)},u.Initializers.addMutationEventsListener=function(t){if(!l)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 o=t.find("[data-resize], [data-scroll], [data-mutate]");if(o.length)for(var n=0;n<=o.length-1;n++)new l(e).observe(o[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(250),u.Initializers.addScrollListener(),u.Initializers.addClosemeListener()},u.init=function(t,e){(0,n.onLoad)(r()(window),function(){!0!==r().triggersInitialized&&(u.Initializers.addSimpleListeners(),u.Initializers.addGlobalListeners(),r().triggersInitialized=!0)}),e&&(e.Triggers=u,e.IHearYou=u.Initializers.addGlobalListeners)}},"./foundation.core":function(t){t.exports=e},"./foundation.util.box":function(t){t.exports=i},"./foundation.util.keyboard":function(t){t.exports=n},"./foundation.util.motion":function(t){t.exports=r},"./foundation.util.touch":function(t){t.exports=s},jquery:function(t){t.exports=o}},u={},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,{a:e}),e},a.d=function(t,e){for(var o in e)a.o(e,o)&&!a.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},f={},(a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})})(f),a.d(f,{Dropdown:function(){return c.Dropdown},Foundation:function(){return t.Foundation}}),t=a("./foundation.core"),c=a("./js/foundation.dropdown.js"),t.Foundation.plugin(c.Dropdown,"Dropdown"),f;function a(t){var e=u[t];return void 0!==e||(e=u[t]={exports:{}},l[t](e,e.exports,a)),e.exports}var l,u,t,c,f});
//# sourceMappingURL=foundation.dropdown.min.js.map