foundation-sites
Version:
The most advanced responsive front-end framework in the world.
3 lines (2 loc) • 13.7 kB
JavaScript
((e,t)=>{"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./foundation.core"),require("jquery"),require("./foundation.util.keyboard"),require("./foundation.util.nest"),require("./foundation.util.box")):"function"==typeof define&&define.amd?define(["./foundation.core","jquery","./foundation.util.keyboard","./foundation.util.nest","./foundation.util.box"],t):"object"==typeof exports?exports.__FOUNDATION_EXTERNAL__=t(require("./foundation.core"),require("jquery"),require("./foundation.util.keyboard"),require("./foundation.util.nest"),require("./foundation.util.box")):(e.__FOUNDATION_EXTERNAL__=e.__FOUNDATION_EXTERNAL__||{},e.__FOUNDATION_EXTERNAL__["foundation.drilldown"]=t(e.__FOUNDATION_EXTERNAL__["foundation.core"],e.jQuery,e.__FOUNDATION_EXTERNAL__["foundation.util.keyboard"],e.__FOUNDATION_EXTERNAL__["foundation.util.nest"],e.__FOUNDATION_EXTERNAL__["foundation.util.box"]))})(self,function(t,n,i,o,r){return a={"./js/foundation.drilldown.js":function(e,t,n){n.r(t),n.d(t,{Drilldown:function(){return i}});var t=n("jquery"),s=n.n(t),a=n("./foundation.util.keyboard"),o=n("./foundation.util.nest"),l=n("./foundation.core"),r=n("./foundation.util.box");function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function d(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(e=>(e=((e,t)=>{if("object"!=u(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);if("object"!=u(n=n.call(e,t||"default")))return n;throw new TypeError("@@toPrimitive must return a primitive value.")})(e,"string"),"symbol"==u(e)?e:e+""))(i.key),i)}}function c(e,t,n){t=h(t);var i=e,t=f()?Reflect.construct(t,n||[],h(e).constructor):t.apply(e,n);if(!t||"object"!=u(t)&&"function"!=typeof t){if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");if(void 0===(t=i))throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return t}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}var i=(e=>{function n(){var e=this,t=n;if(e instanceof t)return c(this,n,arguments);throw new TypeError("Cannot call a class as a function")}var t,i=n;if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),Object.defineProperty(i,"prototype",{writable:!1}),e&&p(i,e),i=n,(e=[{key:"_setup",value:function(e,t){this.$element=e,this.options=s().extend({},n.defaults,this.$element.data(),t),this.className="Drilldown",this._init(),a.Keyboard.register("Drilldown",{ENTER:"open",SPACE:"open",ARROW_RIGHT:"next",ARROW_UP:"up",ARROW_DOWN:"down",ARROW_LEFT:"previous",ESCAPE:"close"})}},{key:"_init",value:function(){o.Nest.Feather(this.$element,"drilldown"),this.options.autoApplyClass&&this.$element.addClass("drilldown"),this.$element.attr({"aria-multiselectable":!1}),this.$submenuAnchors=this.$element.find("li.is-drilldown-submenu-parent").children("a"),this.$submenus=this.$submenuAnchors.parent("li").children("[data-submenu]").attr("role","group"),this.$menuItems=this.$element.find("li").not(".js-drilldown-back").find("a"),this.$currentMenu=this.$element,this.$element.attr("data-mutate",this.$element.attr("data-drilldown")||(0,l.GetYoDigits)(6,"drilldown")),this._prepareMenu(),this._registerEvents(),this._keyboardEvents()}},{key:"_prepareMenu",value:function(){var n=this;this.$submenuAnchors.each(function(){var e=s()(this),t=e.parent();n.options.parentLink&&e.clone().prependTo(t.children("[data-submenu]")).wrap('<li data-is-parent-link class="is-submenu-parent-item is-submenu-item is-drilldown-submenu-item" role="none"></li>'),e.data("savedHref",e.attr("href")).removeAttr("href").attr("tabindex",0),e.children("[data-submenu]").attr({"aria-hidden":!0,tabindex:0,role:"group"}),n._events(e)}),this.$submenus.each(function(){var e=s()(this);if(!e.find(".js-drilldown-back").length)switch(n.options.backButtonPosition){case"bottom":e.append(n.options.backButton);break;case"top":e.prepend(n.options.backButton);break;default:console.error("Unsupported backButtonPosition value '"+n.options.backButtonPosition+"'")}n._back(e)}),this.$submenus.addClass("invisible"),this.options.autoHeight||this.$submenus.addClass("drilldown-submenu-cover-previous"),this.$element.parent().hasClass("is-drilldown")||(this.$wrapper=s()(this.options.wrapper).addClass("is-drilldown"),this.options.animateHeight&&this.$wrapper.addClass("animate-height"),this.$element.wrap(this.$wrapper)),this.$wrapper=this.$element.parent(),this.$wrapper.css(this._getMaxDims())}},{key:"_resize",value:function(){this.$wrapper.css({"max-width":"none","min-height":"none"}),this.$wrapper.css(this._getMaxDims())}},{key:"_events",value:function(n){var i=this;n.off("click.zf.drilldown").on("click.zf.drilldown",function(e){var t;s()(e.target).parentsUntil("ul","li").hasClass("is-drilldown-submenu-parent")&&e.preventDefault(),i._show(n.parent("li")),i.options.closeOnClick&&(t=s()("body")).off(".zf.drilldown").on("click.zf.drilldown",function(e){e.target===i.$element[0]||s().contains(i.$element[0],e.target)||(e.preventDefault(),i._hideAll(),t.off(".zf.drilldown"))})})}},{key:"_registerEvents",value:function(){this.options.scrollTop&&(this._bindHandler=this._scrollTop.bind(this),this.$element.on("open.zf.drilldown hide.zf.drilldown close.zf.drilldown closed.zf.drilldown",this._bindHandler)),this.$element.on("mutateme.zf.trigger",this._resize.bind(this))}},{key:"_scrollTop",value:function(){var e=this,t=""!==e.options.scrollTopElement?s()(e.options.scrollTopElement):e.$element,t=parseInt(t.offset().top+e.options.scrollTopOffset,10);s()("html, body").stop(!0).animate({scrollTop:t},e.options.animationDuration,e.options.animationEasing,function(){this===s()("html")[0]&&e.$element.trigger("scrollme.zf.drilldown")})}},{key:"_keyboardEvents",value:function(){var e=this;this.$menuItems.add(this.$element.find(".js-drilldown-back > a, .is-submenu-parent-item > a")).on("keydown.zf.drilldown",function(t){var n,i,o=s()(this),r=o.parent("li").parent("ul").children("li").children("a");r.each(function(e){s()(this).is(o)&&(n=r.eq(Math.max(0,e-1)),i=r.eq(Math.min(e+1,r.length-1)))}),a.Keyboard.handleKey(t,"Drilldown",{next:function(){if(o.is(e.$submenuAnchors))return e._show(o.parent("li")),o.parent("li").one((0,l.transitionend)(o),function(){o.parent("li").find("ul li a").not(".js-drilldown-back a").first().focus()}),!0},previous:function(){return e._hide(o.parent("li").parent("ul")),o.parent("li").parent("ul").one((0,l.transitionend)(o),function(){setTimeout(function(){o.parent("li").parent("ul").parent("li").children("a").first().focus()},1)}),!0},up:function(){return n.focus(),!o.is(e.$element.find("> li:first-child > a"))},down:function(){return i.focus(),!o.is(e.$element.find("> li:last-child > a"))},close:function(){o.is(e.$element.find("> li > a"))||(e._hide(o.parent().parent()),o.parent().parent().siblings("a").focus())},open:function(){return(!e.options.parentLink||!o.attr("href"))&&(o.is(e.$menuItems)?o.is(e.$submenuAnchors)?(e._show(o.parent("li")),o.parent("li").one((0,l.transitionend)(o),function(){o.parent("li").find("ul li a").not(".js-drilldown-back a").first().focus()}),!0):void 0:(e._hide(o.parent("li").parent("ul")),o.parent("li").parent("ul").one((0,l.transitionend)(o),function(){setTimeout(function(){o.parent("li").parent("ul").parent("li").children("a").first().focus()},1)}),!0))},handled:function(e){e&&t.preventDefault()}})})}},{key:"_hideAll",value:function(){var e,t=this,n=this.$element.find(".is-drilldown-submenu.is-active");n.addClass("is-closing"),n.parent().closest("ul").removeClass("invisible"),this.options.autoHeight&&(e=n.parent().closest("ul").data("calcHeight"),this.$wrapper.css({height:e})),this.$element.trigger("close.zf.drilldown"),n.one((0,l.transitionend)(n),function(){n.removeClass("is-active is-closing"),t.$element.trigger("closed.zf.drilldown")})}},{key:"_back",value:function(t){var n=this;t.off("click.zf.drilldown"),t.children(".js-drilldown-back").on("click.zf.drilldown",function(){n._hide(t);var e=t.parent("li").parent("ul").parent("li");e.length?n._show(e):n.$currentMenu=n.$element})}},{key:"_menuLinkEvents",value:function(){var e=this;this.$menuItems.not(".is-drilldown-submenu-parent").off("click.zf.drilldown").on("click.zf.drilldown",function(){setTimeout(function(){e._hideAll()},0)})}},{key:"_setShowSubMenuClasses",value:function(e,t){e.addClass("is-active").removeClass("invisible").attr("aria-hidden",!1),e.parent("li").attr("aria-expanded",!0),!0===t&&this.$element.trigger("open.zf.drilldown",[e])}},{key:"_setHideSubMenuClasses",value:function(e,t){e.removeClass("is-active").addClass("invisible").attr("aria-hidden",!0),e.parent("li").attr("aria-expanded",!1),!0===t&&e.trigger("hide.zf.drilldown",[e])}},{key:"_showMenu",value:function(t,n){var i,o=this;this.$element.find('li[aria-expanded="true"] > ul[data-submenu]').each(function(){o._setHideSubMenuClasses(s()(this))}),(this.$currentMenu=t).is("[data-drilldown]")?(!0===n&&t.find("li > a").first().focus(),this.options.autoHeight&&this.$wrapper.css("height",t.data("calcHeight"))):(i=t.children().first().parentsUntil("[data-drilldown]","[data-submenu]")).each(function(e){0===e&&o.options.autoHeight&&o.$wrapper.css("height",s()(this).data("calcHeight"));e=e===i.length-1;!0==e&&s()(this).one((0,l.transitionend)(s()(this)),function(){!0===n&&t.find("li > a").first().focus()}),o._setShowSubMenuClasses(s()(this),e)})}},{key:"_show",value:function(e){var t=e.children("[data-submenu]");e.attr("aria-expanded",!0),this.$currentMenu=t,e.parent().closest("ul").addClass("invisible"),t.addClass("is-active visible").removeClass("invisible").attr("aria-hidden",!1),this.options.autoHeight&&this.$wrapper.css({height:t.data("calcHeight")}),this.$element.trigger("open.zf.drilldown",[e])}},{key:"_hide",value:function(e){this.options.autoHeight&&this.$wrapper.css({height:e.parent().closest("ul").data("calcHeight")}),e.parent().closest("ul").removeClass("invisible"),e.parent("li").attr("aria-expanded",!1),e.attr("aria-hidden",!0),e.addClass("is-closing").one((0,l.transitionend)(e),function(){e.removeClass("is-active is-closing visible"),e.blur().addClass("invisible")}),e.trigger("hide.zf.drilldown",[e])}},{key:"_getMaxDims",value:function(){var t=0,e={},n=this;return this.$submenus.add(this.$element).each(function(){var e=r.Box.GetDimensions(this).height;t=t<e?e:t,n.options.autoHeight&&s()(this).data("calcHeight",e)}),this.options.autoHeight?e.height=this.$currentMenu.data("calcHeight"):e["min-height"]="".concat(t,"px"),e["max-width"]="".concat(this.$element[0].getBoundingClientRect().width,"px"),e}},{key:"_destroy",value:function(){s()("body").off(".zf.drilldown"),this.options.scrollTop&&this.$element.off(".zf.drilldown",this._bindHandler),this._hideAll(),this.$element.off("mutateme.zf.trigger"),o.Nest.Burn(this.$element,"drilldown"),this.$element.unwrap().find(".js-drilldown-back, .is-submenu-parent-item").remove().end().find(".is-active, .is-closing, .is-drilldown-submenu").removeClass("is-active is-closing is-drilldown-submenu").off("transitionend otransitionend webkitTransitionEnd").end().find("[data-submenu]").removeAttr("aria-hidden tabindex role"),this.$submenuAnchors.each(function(){s()(this).off(".zf.drilldown")}),this.$element.find("[data-is-parent-link]").detach(),this.$submenus.removeClass("drilldown-submenu-cover-previous invisible"),this.$element.find("a").each(function(){var e=s()(this);e.removeAttr("tabindex"),e.data("savedHref")&&e.attr("href",e.data("savedHref")).removeData("savedHref")})}}])&&d(i.prototype,e),t&&d(i,t),Object.defineProperty(i,"prototype",{writable:!1}),i})(l.Plugin);i.defaults={autoApplyClass:!0,backButton:'<li class="js-drilldown-back"><a tabindex="0">Back</a></li>',backButtonPosition:"top",wrapper:"<div></div>",parentLink:!1,closeOnClick:!1,autoHeight:!1,animateHeight:!1,scrollTop:!1,scrollTopElement:"",scrollTopOffset:0,animationDuration:500,animationEasing:"swing"}},"./foundation.core":function(e){e.exports=t},"./foundation.util.box":function(e){e.exports=r},"./foundation.util.keyboard":function(e){e.exports=i},"./foundation.util.nest":function(e){e.exports=o},jquery:function(e){e.exports=n}},l={},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,{a:t}),t},s.d=function(e,t){for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},d={},(s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})(d),s.d(d,{Drilldown:function(){return u.Drilldown},Foundation:function(){return e.Foundation}}),e=s("./foundation.core"),u=s("./js/foundation.drilldown.js"),e.Foundation.plugin(u.Drilldown,"Drilldown"),d;function s(e){var t=l[e];return void 0!==t||(t=l[e]={exports:{}},a[e](t,t.exports,s)),t.exports}var a,l,e,u,d});
//# sourceMappingURL=foundation.drilldown.min.js.map