/** * @version $Id$ * @package DJ-MegaMenu * @copyright Copyright (C) 2017 DJ-Extensions.com, All rights reserved. * @license DJ-Extensions.com Proprietary Use License * @author url: http://dj-extensions.com * @author email contact@dj-extensions.com * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu */ !function(t){var s=function(t,s){this.options={openDelay:250,closeDelay:500,animIn:"fadeIn",animOut:"fadeOut",animSpeed:"normal",duration:450,wrap:null,direction:"ltr",event:"mouseenter",touch:"ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0,offset:0,wcag:1},this.init(t,s)};s.prototype.init=function(s,o){var i=this;if(jQuery.extend(i.options,o),s.length){switch(i.options.menu=s,i.options.blurTimer=null,i.options.animSpeed){case"fast":i.options.duration=250;break;case"slow":i.options.duration=650}s.addClass(i.options.animSpeed);var n=s.find("li.dj-up");i.kids=[],i.options.wrap=t("#"+i.options.wrap),i.options.wrap.length||(i.options.wrap=s.parents("div").last()),i.options.touch&&s.on("touchstart",function(t){t.stopPropagation()}),n.each(function(s){var o=t(this);i.kids[s]=new e(o,0,i,i.options)}),1==i.options.fixed&&t(window).one("load",i.makeSticky.bind(i,s)),1==i.options.wcag&&(i.focusable=s.find("a[href], [tabindex]"),s.on("keydown",function(t){i.focusNearest(t)}))}},s.prototype.focusNearest=function(s){var e=this,o=s.which,i=e.options.menu.find(":focus"),n=i.offset(),a={x:1024,y:1024},u=null;if(n){var r=function(t){if(!t.is(":hidden")&&t!=i){var s=t.offset(),e={x:Math.abs(s.left-n.left),y:Math.abs(s.top-n.top)};37==o&&s.leftn.left?(e.yn.top&&e.x");i.css({display:"none",opacity:0,height:s.height()}),i.attr("id",s.attr("id")+"placeholder"),i.insertBefore(o),t(window).scroll(e.scroll.bind(e,o,s,i,!1)),t(window).resize(e.scroll.bind(e,o,s,i,!0)),e.scroll(o,s,i,!1),t(window).on("orientationchange",function(){setTimeout(function(){t(window).trigger("resize")},500)})},s.prototype.scroll=function(s,e,o,i){var n=this;if(!e.is(":hidden")){var a=t(window).scrollTop(),u=(n.sticky?o.offset().top:e.offset().top)-parseInt(n.options.offset);if(n.sticky&&(a .dj-subwrap").css({"max-height":"","overflow-y":""}),n.sticky=!1),!n.sticky&&a>=u){s.css({position:"fixed",top:parseInt(n.options.offset),left:0,width:"100%",display:"block"}),o.css({"min-width":e.outerWidth(!0),display:""});var r=0,l=s.find(".dj-stickylogo");l.length&&(l.css("display",""),l.hasClass("dj-align-center")&&(r=l.outerHeight(!0),console.log(r))),e.css({position:"fixed",top:parseInt(n.options.offset)+r,background:"transparent",height:"auto"}),e.addClass("dj-megamenu-fixed"),e.css("width",o.width()?o.width()+1:"auto"),o.css("height",e.outerHeight()),s.css("height",r+e.outerHeight());var c=t(window).height()-parseInt(n.options.offset)-s.height();e.find(".dj-up > .dj-subwrap").each(function(){t(this).find(".dj-subwrap").length||t(this).css({"max-height":c,"overflow-y":"auto"})}),n.sticky=!0}}};var e=function(t,s,e,o){this.options={},this.init(t,s,e,o)};e.prototype.init=function(s,e,o,i){var n=this;jQuery.extend(n.options,i),n.menu=s,n.level=e,n.parent=o,n.timer=null,n.blurTimer=null,n.sub=n.menu.find("> .dj-subwrap").first(),n.menu.find(".dj-submenu > li, .dj-subtree > li").length||(n.sub.remove(),n.menu.removeClass("parent"),n.menu.find("span.dj-drop").removeClass("dj-drop"),n.menu.find("i.arrow").remove());var a="mouseenter";if(n.options.touch||"click_all"==n.options.event?(a="click_all"==n.options.event?"click":a,(u=n.menu.find("> a").first()).length&&(n.menu.hasClass("separator")&&u.css("cursor","pointer"),u.on("touchend click",function(t){n.sub.length&&!n.menu.hasClass("hover")&&(t.preventDefault(),"touchend"==t.type&&n.menu.trigger("click"))}))):"click"==n.options.event&&n.menu.hasClass("separator")&&((u=n.menu.find("> a").first()).length&&u.css("cursor","pointer"),a="click"),n.options.touch&&(n.menu.on("click",n.showSub.bind(n)),t(document).on("touchstart",function(){n.menu.hasClass("hover")&&n.menu.trigger("mouseleave")})),n.menu.on(a,n.showSub.bind(n)),n.menu.on("mouseleave",n.hideSub.bind(n)),1==n.options.wcag){var u=n.menu.find("> a").first();u.on("focus",n.showSub.bind(n)),u.on("blur",function(){n.blurTimer=setTimeout(function(){if(!n.options.menu.find(":focus").length){for(var t=n;t.level>0;)t.hideSub(),t=t.parent;t.hideSub()}},1e3)}),u.on("keydown",function(t){n.focusNearest(t)}),n.options.menu.on("click",function(){clearTimeout(n.blurTimer)})}n.sub.length&&(n.kids=[],n.initKids())},e.prototype.focusNearest=function(s){var e=this,o=s.which,i=e.menu.offset(),n={x:1024,y:1024},a=null,u=function(t){if(t.menu&&t.menu.find("> a").length){var s=t.menu.offset(),e={x:Math.abs(s.top-i.top),y:Math.abs(s.left-i.left)};37==o&&s.lefti.left?(e.xi.top)&&(e.y a").first().focus())},e.prototype.showSub=function(){var s=this;clearTimeout(s.timer),s.menu.hasClass("hover")&&!s.sub.hasClass(s.options.animOut)||(s.sub.length&&s.sub.css("display","none"),s.timer=setTimeout(function(){clearTimeout(s.animTimer),s.menu.addClass("hover"),s.hideOther(),s.sub.length&&(s.sub.css("display",""),s.sub.removeClass(s.options.animOut),s.checkDir(),s.sub.addClass(s.options.animIn),s.sub.find(".modules-wrap").length&&t(window).trigger("resize"))},s.options.openDelay))},e.prototype.hideSub=function(){var t=this;clearTimeout(t.timer),t.sub.length?t.timer=setTimeout(function(){t.menu.is(":hover")||(t.sub.removeClass(t.options.animIn),t.sub.addClass(t.options.animOut),t.animTimer=setTimeout(function(){t.menu.removeClass("hover")},t.options.duration))},t.options.closeDelay):t.menu.removeClass("hover")},e.prototype.checkDir=function(){var t=this;if(!t.menu.hasClass("fullsub")){t.sub.css("left",""),t.sub.css("right",""),t.sub.css("margin-left",""),t.sub.css("margin-right","");var s=t.sub.offset(),e=t.options.wrap.offset();if("ltr"==t.options.direction)((o=s.left+t.sub.outerWidth()-t.options.wrap.outerWidth()-e.left)>0||t.sub.hasClass("open-left"))&&(t.level?(t.sub.css("right",t.menu.outerWidth()),t.sub.css("left","auto")):t.sub.hasClass("open-left")?(t.sub.css("right",t.sub.css("left")),t.sub.css("left","auto")):t.sub.css("margin-left",-o));else if("rtl"==t.options.direction){var o=s.left-e.left;(o<0||t.sub.hasClass("open-right"))&&(t.level?(t.sub.css("left",t.menu.outerWidth()),t.sub.css("right","auto")):t.sub.hasClass("open-right")?(t.sub.css("left",t.sub.css("right")),t.sub.css("right","auto")):t.sub.css("margin-right",o))}}},e.prototype.initKids=function(){var s=this;s.sub.find("> .dj-subwrap-in > .dj-subcol > ul.dj-submenu > li").each(function(o){var i=t(this);s.kids[o]=new e(i,s.level+1,s,s.options)})},e.prototype.hideOther=function(){var s=this;t.each(s.parent.kids,function(t,e){e.menu.hasClass("hover")&&e!=s&&(e.sub.length?(e.hideOtherSub(),e.sub.removeClass(e.options.animIn),e.sub.addClass(e.options.animOut),e.animTimer=setTimeout(function(){e.menu.removeClass("hover")},s.options.duration)):e.menu.removeClass("hover"))})},e.prototype.hideOtherSub=function(){var s=this;t.each(s.kids,function(t,s){s.sub.length&&(s.hideOtherSub(),s.sub.removeClass(s.options.animIn),s.sub.removeClass(s.options.animOut)),s.menu.removeClass("hover")})},t(document).ready(function(){t(".dj-megamenu[data-options]").each(function(){var e=t(this);e.find(".dj-hideitem").remove(),e.data();var o=e.data("options");e.removeAttr("data-options"),e.find(".modules-wrap ul.nav li.current").each(function(){t(this).parents("ul.dj-submenu > li, li.dj-up").each(function(){t(this).addClass("active"),t(this).find("> a").addClass("active")})}),new s(e,o)})})}(jQuery);