/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","hammerjs","promise","ojs/ojjquery-hammer","ojs/ojcomponentcore"],function(a,g,c){a.q={};o_("OffcanvasUtils",a.q,a);a.q.iU="oj-offcanvasEdge";a.q.Qr="oj-offcanvas";a.q.jU="oj-mediaQueryListener";a.q.Y7="oj-offcanvasHammer";a.q.Z7="oj-offcanvasStyle";a.q.Sw="selector";a.q.iE="content";a.q.Fw="start";a.q.Ew="end";a.q.kE="top";a.q.dK="bottom";a.q.Aw="displayMode";a.q.Bw="push";a.q.$S="overlay";a.q.k6="pin";a.q.Xsa="modality";a.q.OVa="none";a.q.Ysa="modal";a.q.cK="_dismissHandler";
a.q.FT="_openPromise";a.q.hE="_closePromise";a.q.aA="_glassPane";a.q.i7="_surrogate";a.q.NT="data-oj-offcanvas-surrogate-id";a.q.jta="oj-offcanvas-outer-wrapper";a.q.uK="oj-offcanvas-open";a.q.gi="oj-offcanvas-transition";a.q.lta="oj-offcanvas-pin";a.q.kta="oj-offcanvas-pin-transition";a.q.Fsa="oj-offcanvas-glasspane";a.q.hK="oj-offcanvas-glasspane-dim";a.q.Qta="ojbeforeopen veto";a.q.Pta="ojbeforeclose veto";a.q.vNa={start:"oj-offcanvas-shift-start",end:"oj-offcanvas-shift-end",top:"oj-offcanvas-shift-down",
bottom:"oj-offcanvas-shift-up"};a.q.zBa={start:"oj-offcanvas-start",end:"oj-offcanvas-end",top:"oj-offcanvas-top",bottom:"oj-offcanvas-bottom"};a.q.RCa=function(b){b=b[a.q.Aw];b!==a.q.$S&&b!==a.q.Bw&&b!==a.q.k6&&(b=(a.wc.Kd("oj-offcanvas-option-defaults")||{}).displayMode);return b};a.q.pi=function(b){return g(b[a.q.Sw])};a.q.UG=function(b){return b[a.q.Xsa]===a.q.Ysa};a.q.So=function(b){return b.hasClass(a.q.uK)};a.q.Tx=function(b){return b.closest("."+a.q.jta)};a.q.fN=function(b){var c=a.q.pi(b);
return a.q.Jha(b)||b[a.q.Aw]===a.q.$S?c:c.parent()};a.q.fEa=function(b){var c=a.q.vNa[b];if(!c)throw"Invalid edge: "+b;return c};a.q.ih=function(){return"rtl"===a.Q.Wj()};a.q.qn=function(a,c){a.css({"-webkit-transform":c,transform:c})};a.q.RN=function(b,c,e){b=b===a.q.Ew;if(a.q.ih()||e)b=!b;return"translate3d("+(b?"-":"")+c+", 0, 0)"};a.q.$H=function(b,c,e){a.q.qn(b,a.q.RN(c,e,!1))};a.q.Nea=function(b,c){return"translate3d(0, "+(b===a.q.dK?"-":"")+c+", 0)"};a.q.kNa=function(b,c,e){a.q.qn(b,a.q.Nea(c,
e))};a.q.Oea=function(a,c){return"translate3d(0, "+(c?"-":"")+a+", 0)"};a.q.oMa=function(b,c,e){b.addClass(a.q.gi);a.q.qn(b,"translate3d(0, 0, 0)");c.addClass(a.q.gi);a.q.qn(c,e)};a.q.yja=function(b){var c=b.edge;b=a.q.pi(b);c&&c.length||(c=b.hasClass("oj-offcanvas-start")?a.q.Fw:b.hasClass("oj-offcanvas-end")?a.q.Ew:b.hasClass("oj-offcanvas-top")?a.q.kE:b.hasClass("oj-offcanvas-bottom")?a.q.dK:a.q.Fw);g.data(b[0],a.q.iU,c);return c};a.q.oY=function(b){return g.data(b[0],a.q.iU)};a.q.CC=function(b,
c,e){var f=b[a.q.Aw],g=a.q.pi(b),k=a.q.uK,f=f===a.q.$S?a.q.gi+" oj-offcanvas-overlay":a.q.gi;e?(g.addClass(k),c.addClass(f)):(b.makeFocusable&&a.Q.$R({element:g,remove:!0}),b=b.tabindex,void 0===b?g.removeAttr("tabindex"):g.attr("tabindex",b),g.removeClass(k),c.removeClass(f))};a.q.nm=function(b){var c=a.q.pi(b),e=c.find("[autofocus]");0==e.length&&(e=c.find(":tabbable"));0==e.length?(e=c.attr("tabindex"),void 0!==e&&(b.tabindex=e),c.attr("tabindex","-1"),e=c,a.Q.$R({element:c,applyHighlight:!0}),
b.makeFocusable=!0):e=e[0];a.cf.II(e)};a.q.KHa=function(a){return"none"!=a.autoDismiss};a.q.Iya=function(a){var c=a.css("transitionProperty").split(","),e=a.css("transitionDelay").split(",");a=a.css("transitionDuration").split(",");for(var f=0,g=0;g<c.length;g++){var k=a[g%a.length],k=-1<k.indexOf("ms")?parseFloat(k):1E3*parseFloat(k);if(0<k)var l=e[g%e.length],l=-1<l.indexOf("ms")?parseFloat(l):1E3*parseFloat(l),f=Math.max(f,l+k)}return f+100};a.q.hv=function(b,c){function e(){f&&(clearTimeout(f),
f=void 0);b.off("transitionend.oc webkitTransitionEnd.oc",e);c(b)}var f;b.on("transitionend.oc webkitTransitionEnd.oc",e);f=setTimeout(e,a.q.Iya(b))};a.q.Saa=function(b){a.q.close(b)["catch"](function(b){a.C.warn("Offcancas close failed: "+b)})};a.q.gP=function(b){a.q.e2(b);if(a.q.KHa(b)){var c=a.q.pi(b),e=b[a.q.cK]=function(e){var f=e.target;a.Q.$oa(e)||"focus"===e.type&&!g(f).is(":focusable")||(null==g.data(c[0],a.q.Qr)?a.q.e2(b):a.Q.aTa(c[0],f)||a.q.Saa(b))},f=document.documentElement;a.Q.Re()&&
f.addEventListener("touchstart",e,!0);f.addEventListener("mousedown",e,!0);f.addEventListener("focus",e,!0)}a.q.iC(b)};a.q.e2=function(b){var c=b[a.q.cK];if(c){var e=document.documentElement;a.Q.Re()&&e.removeEventListener("touchstart",c,!0);e.removeEventListener("mousedown",c,!0);e.removeEventListener("focus",c,!0);delete b[a.q.cK];b[a.q.cK]=null}a.q.SP(b)};a.q.iC=function(b){if(a.Q.Re()){var d=b[a.q.Sw],e=g(d),f=a.q.oY(e),h,k;f===a.q.Fw&&!a.q.ih()||f===a.q.Ew&&a.q.ih()?(k={recognizers:[[c.Swipe,
{direction:c.DIRECTION_LEFT}]]},h="swipeleft"):f===a.q.Fw&&a.q.ih()||f===a.q.Ew&&!a.q.ih()?(k={recognizers:[[c.Swipe,{direction:c.DIRECTION_RIGHT}]]},h="swiperight"):f===a.q.kE?(k={recognizers:[[c.Swipe,{direction:c.DIRECTION_UP}]]},h="swipeup"):f===a.q.dK&&(k={recognizers:[[c.Swipe,{direction:c.DIRECTION_DOWN}]]},h="swipedown");f=e.Ng(k).on(h,function(c){c.target===e[0]&&(c.preventDefault(),a.q.Saa(b))});g.data(g(d)[0],a.q.Y7,{event:h,hammer:f})}};a.q.SP=function(b){b=a.q.pi(b);0<b.length&&(b=g.data(b[0],
a.q.Y7))&&b.hammer.off(b.event)};a.q.VHa=function(b){return a.q.Tx(b).hasClass("oj-offcanvas-page")};a.q.p_=function(b){return b[a.q.Aw]===a.q.k6};a.q.Jha=function(b){return b[a.q.iE]||a.q.VHa(a.q.pi(b))||a.q.p_(b)};a.q.cXa=function(b){var c=b.attr("style");void 0!==c&&g.data(b[0],a.q.Z7,c)};a.q.WLa=function(b){var c=g.data(b[0],a.q.Z7);c?b.attr("style",c):b.removeAttr("style")};a.q.Uy=function(b,c){var e=a.q.oY(b),e=a.q.fEa(e),f=a.q.Tx(b);a.A.Ne(f,g);var h=f.hasClass(e);c||f.toggleClass(e,!h);return h};
a.q.ds=function(b){a.q.e2(b);var c=a.q.pi(b),e=a.q.p_(b),f=null;try{f=g.data(c[0],a.q.Qr)}catch(h){}f===b&&(a.q.oY(c),f=a.q.fN(b),e?c.removeClass(a.q.uK+" "+a.q.kta):a.q.CC(b,f,!1),a.q.lLa(b),e&&(a.q.Tx(c).removeClass(a.q.lta),a.q.WLa(c)),c.trigger("ojclose",b),g.removeData(c[0],a.q.Qr))};a.q.nka=function(b,c,e){var f=g(b);(c=!!c)&&a.q.So(f)&&a.q.ks(b,!1);f.toggleClass(a.q.zBa[e],!c)};a.q.bVa=function(b){var c=b.query;if(null!==c){var e=b[a.q.Sw],c=window.matchMedia(c),f=a.q.yja(b);b=function(b){a.q.nka(e,
b.matches,f)};c.addListener(b);a.q.nka(e,c.matches,f);g.data(g(e)[0],a.q.jU,{mqList:c,mqListener:b})}};o_("OffcanvasUtils.setupResponsive",a.q.bVa,a);a.q.qVa=function(b){b=a.q.pi(b);var c=g.data(b[0],a.q.jU);c&&(c.mqList.removeListener(c.mqListener),g.removeData(b[0],a.q.jU))};o_("OffcanvasUtils.tearDownResponsive",a.q.qVa,a);a.q.JJa=function(b,c,e){function f(e){e.removeClass(a.q.gi);l?l=!1:(a.q.nm(b),h.trigger("ojopen",b),a.q.gP(b),c(!0))}var h=a.q.pi(b),k=g(b[a.q.iE]);a.A.Ne(k,g);var l=!0,m=b.size,
p;h.addClass(a.q.uK);window.setTimeout(function(){e===a.q.Fw||e===a.q.Ew?(void 0===m&&(m=h.outerWidth(!0)+"px"),a.q.qn(h,a.q.RN(e,m,!0)),p=a.q.RN(e,m,!1)):(void 0===m&&(m=h.outerHeight(!0)+"px"),a.q.qn(h,a.q.Oea(m,e===a.q.kE)),p=a.q.Oea(m,e!==a.q.kE));window.setTimeout(function(){a.q.oMa(h,k,p);a.q.Uy(h,!1);a.q.hv(k,f);a.q.hv(h,f)},0)},0);a.q.SV(b,h)};a.q.FJa=function(b,c,e){var f=a.q.pi(b);a.q.CC(b,f,!0);var g=b.size;g&&(e===a.q.Fw||e===a.q.Ew?a.q.qn(f,a.q.RN(e,g,!0)):a.q.qn(f,a.q.Nea(e,g)));window.setTimeout(function(){a.q.Uy(f,
!1)},20);a.q.SV(b,f);a.q.hv(f,function(){f.removeClass(a.q.gi);a.q.nm(b);f.trigger("ojopen",b);a.q.gP(b);c(!0)})};a.q.jza=function(b,c,e,f){function h(){l||(k.removeClass(a.q.gi),a.q.qn(k,""),a.q.ds(b),c(!0));l=!1}var k=g(b[a.q.iE]),l=!0;a.q.qn(e,"");a.q.qn(k,"");a.q.Uy(e,!1);a.q.UG(b)&&b[a.q.aA].removeClass(a.q.hK);f?(k.addClass(a.q.gi),e.addClass(a.q.gi),a.q.hv(e,h),a.q.hv(k,h)):(l=!1,h())};a.q.iza=function(b,c,e,f){function g(){a.q.ds(b);c(!0)}a.q.Uy(e,!1);a.q.UG(b)&&b[a.q.aA].removeClass(a.q.hK);
f?(e.addClass(a.q.gi),a.q.hv(e,g)):g()};a.q.EJa=function(b,c,e,f){var h=a.q.pi(b),k=a.q.fN(b);a.A.Ne(k,g);a.q.CC(b,k,!0);var l;e===a.q.Fw||e===a.q.Ew?(l=void 0===l?h.outerWidth(!0)+"px":l,f===a.q.Bw&&a.q.$H(k,e,l)):(l=void 0===l?h.outerHeight(!0)+"px":l,f===a.q.Bw&&a.q.kNa(k,e,l));window.setTimeout(function(){a.q.Uy(h,!1)},10);a.q.SV(b,h);a.q.hv(k,function(){k.removeClass(a.q.gi);a.q.nm(b);h.trigger("ojopen",b);a.q.gP(b);c(!0)})};a.q.hza=function(b,c,e,f){function g(){a.q.ds(b);c(!0)}var k=b[a.q.Aw],
l=a.q.fN(b);k===a.q.Bw&&a.q.qn(l,"");a.q.Uy(e,!1);a.q.UG(b)&&b[a.q.aA].removeClass(a.q.hK);f?(l.addClass(a.q.gi),a.q.hv(l,g)):g()};a.q.open=function(b){var c=a.q.pi(b),e=g.data(c[0],a.q.Qr);if(e){if(e[a.q.hE])return e[a.q.hE];if(e[a.q.FT])return e[a.q.FT]}var f,h=!1,e=new Promise(function(e,k){a.A.Ne(c,g);var p=a.q.yja(b),t=g.Event("ojbeforeopen");c.trigger(t,b);if(!1===t.result)k(a.q.Qta),h=!0;else{var t=a.q.RCa(b),s=a.q.p_(b);!s||p!==a.q.kE&&p!==a.q.dK||(t=a.q.Bw);var n=g.extend({},b);n[a.q.Aw]=
t;g.data(c[0],a.q.Qr,n);if(b[a.q.iE]){if(!a.q.Jha(b))throw"Error: Both main content selector and the inner wrapper \x3cdiv class\x3d'oj-offcanvas-inner-wrapper'\x3e are provided. Please remove the inner wrapper.";f=a.Context.getContext(c[0]).ye().Ed({description:"The offcanvas selector \x3d'"+b[a.q.Sw]+"' doing the open animation."});s||(t===a.q.Bw?a.q.JJa(n,e,p):a.q.FJa(n,e,p))}else a.q.EJa(n,e,p,t)}}),e=e.then(function(a){f&&f();return a},function(a){f&&f();throw a;});if(!h){var k=g.data(c[0],a.q.Qr);
k&&(k[a.q.FT]=e,a.Components.zr(c[0]))}return e};o_("OffcanvasUtils.open",a.q.open,a);a.q.close=function(b){return a.q.ks(b[a.q.Sw],!0)};o_("OffcanvasUtils.close",a.q.close,a);a.q.ks=function(b,c){var e=g(b);a.A.Ne(e,g);var f=g.data(e[0],a.q.Qr);if(f&&f[a.q.hE])return f[a.q.hE];var h,k=!1,l=new Promise(function(l,p){if(a.q.So(e)){b!=f[a.q.Sw]&&l(!0);a.q.Uy(e,!0)||l(!0);var t=g.Event("ojbeforeclose");e.trigger(t,f);!1===t.result?(p(a.q.Pta),k=!0):(c&&(h=a.Context.getContext(e[0]).ye().Ed({description:"The offcanvas selector \x3d'"+
f[a.q.Sw]+"' doing the close animation."})),t=f[a.q.Aw],f[a.q.iE]?t===a.q.Bw?a.q.jza(f,l,e,c):a.q.iza(f,l,e,c):a.q.hza(f,l,e,c))}else l(!0)}),l=l.then(function(a){h&&h();return a},function(a){h&&h();throw a;});!k&&(f=g.data(e[0],a.q.Qr))&&(f[a.q.hE]=l,a.Components.yr(e[0]));return l};a.q.toggle=function(b){var c=a.q.pi(b);a.A.Ne(c,g);return a.q.So(c)?a.q.close(b):a.q.open(b)};o_("OffcanvasUtils.toggle",a.q.toggle,a);a.q.mxa=function(b){var c=g("\x3cdiv\x3e");c.addClass(a.q.Fsa);c.attr("role","presentation");
c.attr("aria-hidden","true");c.appendTo(b.parent());c.on("keydown keyup keypress mousedown mouseup mouseover mouseout click focusin focus",function(a){a.stopPropagation();a.preventDefault()});return c};a.q.ZW=function(b){var c=g("\x3cspan style\x3d'display:none'\x3e");c.attr("aria-hidden","true");var e=b.attr("id");e?(e=[e,"surrogate"].join("_"),c.attr("id",e)):e=c.uniqueId();c.insertBefore(b);b.attr(a.q.NT,e);return c};a.q.RNa=function(b,c){b[a.q.i7]=a.q.ZW(c);c.appendTo(c.parent())};a.q.ULa=function(b){var c=
a.q.pi(b);b=b[a.q.i7];c&&b&&c.attr(a.q.NT)===b.attr("id")&&(c.insertAfter(b),c.removeAttr(a.q.NT),b.remove())};a.q.SV=function(b,c){a.q.UG(b)&&(b[a.q.aA]=a.q.mxa(c),a.q.RNa(b,c),window.setTimeout(function(){b[a.q.aA].addClass(a.q.hK)},0))};a.q.lLa=function(b){a.q.UG(b)&&(b[a.q.aA].remove(),a.q.ULa(b))};a.q.sra=function(b){var d,e,f,h,k,l,m,p,t,s,n,r;null==g(b).attr("oj-data-pansetup")&&(g(b).attr("oj-data-pansetup","true"),b.displayMode="push",d=a.q.pi(b),e=b.size,null==e&&(e=d.outerWidth()),f=a.q.Tx(d),
h=a.q.fN(b),k={recognizers:[[c.Pan,{direction:c.DIRECTION_HORIZONTAL}]]},l=!1,g(f).Ng(k).on("panstart",function(e){m=null;switch(e.gesture.direction){case c.DIRECTION_LEFT:Math.abs(e.gesture.deltaY)<Math.abs(e.gesture.deltaX)&&(m=a.q.ih()?"end":"start");break;case c.DIRECTION_RIGHT:Math.abs(e.gesture.deltaY)<Math.abs(e.gesture.deltaX)&&(m=a.q.ih()?"start":"end")}null!=m&&(p={direction:m,distance:Math.abs(e.gesture.deltaX)},t=g.Event("ojpanstart"),d.trigger(t,p),t.isDefaultPrevented()||(b._closePromise=
null,h.off(".oc"),a.q.CC(b,h,!0),l=!0,e.gesture.srcEvent.stopPropagation(),e.stopPropagation()))}).on("panmove",function(b){l&&(s=b.gesture.deltaX,"start"==m&&0<s||"end"==m&&0>s?a.q.$H(h,"start","0px"):(d.css("width",Math.abs(s)),h.removeClass(a.q.gi),a.q.$H(h,"start",s+"px"),p={direction:m,distance:Math.abs(s)},t=g.Event("ojpanmove"),d.trigger(t,p),b.gesture.srcEvent.stopPropagation(),b.stopPropagation()))}).on("panend",function(c){l&&(l=!1,s=Math.abs(c.gesture.deltaX),p={distance:s},t=g.Event("ojpanend"),
d.trigger(t,p),c.stopPropagation(),t.isDefaultPrevented()?(r=function(){a.q.CC(b,h,!1);h.removeClass(a.q.gi);h.off("transitionend webkitTransitionEnd otransitionend oTransitionEnd",r);d.trigger("ojclose",b)},h.on("transitionend webkitTransitionEnd otransitionend oTransitionEnd",r),h.addClass(a.q.gi),a.q.$H(h,"start","0px")):(n=b.edge,null==n&&(n=d.hasClass("oj-offcanvas-start")?"start":"end"),a.q.Vxa(h,d,n,e,b),g.data(d[0],a.q.Qr,b),g.data(d[0],a.q.iU,n),a.q.gP(b)))}))};o_("OffcanvasUtils.setupPanToReveal",
a.q.sra,a);a.q.Vxa=function(b,c,e,f,g){var k,l,m,p,t,s,n,r,q,u;b.removeClass(a.q.gi);k=Math.round(1E3/60);l=b.css("transform").split("(")[1].split(")")[0].split(",");m=parseInt(l[4],10);p="end"==e?0-f:f;s=Math.max(1,Math.abs(p-m)/(400/k));n=(new Date).getTime();r=function(){q=(new Date).getTime();u=Math.max(s,s*Math.max((q-n)/k));n=q;m<p?m=Math.min(p,m+u):m>p&&(m=Math.max(p,m-u));a.q.$H(b,e,Math.abs(m)+"px");c.css("width",Math.abs(m)+"px");m==p?(window.cancelAnimationFrame(t),b.addClass(a.q.gi),c.trigger("ojopen",
g)):t=window.requestAnimationFrame(r)};t=window.requestAnimationFrame(r)};a.q.Ira=function(b){b=a.q.pi(b);b=a.q.Tx(b);g(b).off("panstart panmove panend")};o_("OffcanvasUtils.tearDownPanToReveal",a.q.Ira,a)});