@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines (2 loc) • 11.1 kB
JavaScript
!function(e){"function"==typeof define&&define.amd?define(["kendo.core.min"],e):e()}((function(){!function(e,t){var o=window.kendo,n=o.ui,i=n.Widget,s=o.Class,r=o.support,a=o.getOffset,l=o._outerWidth,d=o._outerHeight,p="open",c="close",f="deactivate",u="activate",h="center",m="right",g="top",v="bottom",w="absolute",b="hidden",_="body",y="location",k="position",x="effects",z="k-active",T="k-state-border",C=/k-state-border-(\w+)/,P=".k-picker-wrap, .k-dropdown-wrap, .k-link",S=e(document.documentElement),E=e(window),I="scroll",O=r.transitions.css+"transform",R=e.extend,A=".kendoPopup",D=["font-size","font-family","font-stretch","font-style","font-weight","line-height"];function N(t,o){return!(!t||!o)&&(t===o||e.contains(t,o))}var F=i.extend({init:function(t,n){var s,a=this;(n=n||{}).isRtl&&(n.origin=n.origin||"bottom right",n.position=n.position||"top right"),i.fn.init.call(a,t,n),t=a.element,n=a.options,a.collisions=n.collision?n.collision.split(" "):[],a.downEvent=o.applyEventMap("down",o.guid()),1===a.collisions.length&&a.collisions.push(a.collisions[0]),s=e(a.options.anchor).closest(".k-popup,.k-group").filter(":not([class^=km-])"),n.appendTo=e(e(n.appendTo)[0]||s[0]||document.body),a.element.hide().addClass("k-popup k-group k-reset").toggleClass("k-rtl",!!n.isRtl).appendTo(n.appendTo).attr("aria-hidden",!0).on("mouseenter"+A,(function(){a._hovered=!0})).on("wheel"+A,(function(t){var o=e(t.target).find(".k-list"),n=o.parent();o.length&&o.is(":visible")&&(0===n.scrollTop()&&t.originalEvent.deltaY<0||n.scrollTop()===n.prop("scrollHeight")-n.prop("offsetHeight")&&t.originalEvent.deltaY>0)&&t.preventDefault()})).on("mouseleave"+A,(function(){a._hovered=!1})),a.wrapper=e(),!1===n.animation&&(n.animation={open:{effects:{}},close:{hide:!0,effects:{}}}),R(n.animation.open,{complete:function(){a.wrapper.addClass("k-animation-container-shown"),a.wrapper.css("overflow",""),a._activated=!0,a._trigger(u)}}),R(n.animation.close,{complete:function(){a._animationClose()}}),a._mousedownProxy=function(e){a._mousedown(e)},r.mobileOS.android?a._resizeProxy=function(e){setTimeout((function(){a._resize(e)}),600)}:a._resizeProxy=function(e){a._resize(e)},n.toggleTarget&&e(n.toggleTarget).on(n.toggleEvent+A,a.toggle.bind(a))},events:[p,u,c,f],options:{name:"Popup",toggleEvent:"click",origin:"bottom left",position:"top left",anchor:_,appendTo:null,collision:"flip fit",viewport:window,copyAnchorStyles:!0,autosize:!1,modal:!1,adjustSize:{width:0,height:0},animation:{open:{effects:"slideIn:down",transition:!0,duration:200},close:{duration:100,hide:!0}},omitOriginOffsets:!1},_animationClose:function(){var e=this,t=e.wrapper.data(y);e.wrapper.hide(),t&&e.wrapper.css(t),e.options.anchor!=_&&e._hideDirClass(),e._closing=!1,e._trigger(f)},destroy:function(){var t,n=this,s=n.options,r=n.element.off(A);i.fn.destroy.call(n),s.toggleTarget&&e(s.toggleTarget).off(A),s.modal||(S.off(n.downEvent,n._mousedownProxy),n._toggleResize(!1)),o.destroy(n.element.children()),r.removeData(),s.appendTo[0]===document.body&&((t=r.closest(".k-animation-container"))[0]?t.remove():r.remove())},open:function(t,n){var i,s,a,l=this,d={isFixed:!isNaN(parseInt(n,10)),x:t,y:n},c=l.element,f=l.options,u=e(f.anchor),h=c[0]&&c.hasClass("km-widget"),m=c.find("[role='listbox']");if(!l.visible()){if(f.copyAnchorStyles&&(h&&"font-size"==D[0]&&D.shift(),c.css(o.getComputedStyles(u[0],D))),l.element.parent().data("animating")||l._trigger(p))return;l._activated=!1,f.modal||(S.off(l.downEvent,l._mousedownProxy).on(l.downEvent,l._mousedownProxy),l._toggleResize(!1),l._toggleResize(!0)),l.wrapper=s=o.wrap(c,f.autosize).css({overflow:b,display:"block",position:w}).attr("aria-hidden",!1),a=c.parent(),m.attr("aria-label")?s.attr("aria-label",m.attr("aria-label")):m.attr("aria-labelledby")&&s.attr("aria-labelledby",m.attr("aria-labelledby")),r.mobileOS.android&&a.css(O,"translatez(0)"),s.css(k),e(f.appendTo)[0]==document.body&&s.css(g,"-10000px"),l.flipped=l._position(d),i=l._openAnimation(),f.anchor==_||l.element.hasClass("k-tooltip")||l._showDirClass(i),a.hide(),c.show(),l.wrapper.show(),a.data(x,i.effects).kendoStop(!0).kendoAnimate(i),c.attr("aria-hidden",!1)}},_location:function(t){var n,i=this,s=i.element,a=i.options,l=e(a.anchor),d=s[0]&&s.hasClass("km-widget");a.copyAnchorStyles&&(d&&"font-size"==D[0]&&D.shift(),s.css(o.getComputedStyles(l[0],D))),i.wrapper=n=o.wrap(s,a.autosize).css({overflow:b,display:"block",position:w}),r.mobileOS.android&&n.css(O,"translatez(0)"),n.css(k),e(a.appendTo)[0]==document.body&&n.css(g,"-10000px"),i._position(t||{});var p=n.offset();return{width:o._outerWidth(n),height:o._outerHeight(n),left:p.left,top:p.top}},_openAnimation:function(){var e=R(!0,{},this.options.animation.open);return e.effects=o.parseEffects(e.effects,this.flipped),e},_hideDirClass:function(){var t=e(this.options.anchor),n=((t.attr("class")||"").match(C)||["","down"])[1],i=T+"-"+n;t.removeClass(i).children(P).removeClass(z).removeClass(i),this.element.removeClass(T+"-"+o.directions[n].reverse)},_showDirClass:function(t){var o=t.effects.slideIn?t.effects.slideIn.direction:"down",n=T+"-"+o;e(this.options.anchor).addClass(n).children(P).addClass(z).addClass(n)},position:function(){this.visible()&&(this.flipped=this._position())},toggle:function(){this[this.visible()?c:p]()},visible:function(){return this.wrapper.is(":visible")&&this.element.is(":visible")},close:function(t){var n,i,s,r,a=this,l=a.element.parent(),d=a.options;if(a.visible()){if(n=a.wrapper[0]?a.wrapper:o.wrap(a.element).hide(),a.wrapper.removeClass("k-animation-container-shown"),a._toggleResize(!1),a._closing||a._trigger(c))return void a._toggleResize(!0);a.element.find(".k-popup").each((function(){var o=e(this).data("kendoPopup");o&&o.close(t)})),S.off(a.downEvent,a._mousedownProxy),t?i={hide:!0,effects:{}}:(i=R(!0,{},d.animation.close),s=l.data(x),!(r=i.effects)&&!o.size(r)&&s&&o.size(s)&&(i.effects=s,i.reverse=!0),a._closing=!0),l.kendoStop(!0),a.element.attr("aria-hidden",!0),n.css({overflow:b}).attr("aria-hidden",!0),l.kendoAnimate(i),t&&a._animationClose()}},_trigger:function(e){return this.trigger(e,{type:e})},_resize:function(e){var t=this;-1!==r.resize.indexOf(e.type)?(clearTimeout(t._resizeTimeout),t._resizeTimeout=setTimeout((function(){t._position(),t._resizeTimeout=null}),50)):(!t._hovered||t._activated&&t.element.find(".k-list").length>0)&&t.close()},_toggleResize:function(e){var t=e?"on":"off",o=r.resize;r.mobileOS.ios||r.mobileOS.android||r.browser.safari||(o+=" scroll"),e&&!this.scrollableParents&&(this.scrollableParents=this._scrollableParents()),this.scrollableParents&&this.scrollableParents.length&&this.scrollableParents[t](I,this._resizeProxy),E[t](o,this._resizeProxy)},_mousedown:function(t){var n=this,i=n.element[0],s=n.options,r=e(s.anchor)[0],a=s.toggleTarget,l=o.eventTarget(t),d=e(l).closest(".k-popup"),p=d.parent().parent(".km-shim").length;d=d[0],!p&&d&&d!==n.element[0]||"popover"!==e(t.target).closest("a").data("rel")&&(N(i,l)||N(r,l)||a&&N(e(a)[0],l)||n.close())},_fit:function(e,t,o){var n=0;return e+t>o&&(n=o-(e+t)),e<0&&(n=-e),n},_flip:function(e,t,o,n,i,s,r){var a=0;return r=r||t,s!==i&&s!==h&&i!==h&&(e+r>n&&(a+=-(o+t)),e+a<0&&(a+=o+t)),a},_scrollableParents:function(){return e(this.options.anchor).parentsUntil("body").filter((function(e,t){return o.isScrollable(t)}))},_position:function(t){var n,i,s,p,c,f,u,h=this,m=h.element,g=h.wrapper,v=h.options,w=e(v.viewport),b=r.zoomLevel(),_=!!(w[0]==window&&window.innerWidth&&b<=1.02),x=e(v.anchor),z=v.origin.toLowerCase().split(" "),T=v.position.toLowerCase().split(" "),C=h.collisions,P=10002,S=0,E=document.documentElement;(c=v.viewport===window?{top:window.pageYOffset||document.documentElement.scrollTop||0,left:window.pageXOffset||document.documentElement.scrollLeft||0}:w.offset(),_?(f=window.innerWidth,u=window.innerHeight):(f=w.width(),u=w.height()),_&&E.scrollHeight-E.clientHeight>0)&&(f-=(v.isRtl?-1:1)*o.support.scrollbar());if((n=x.parents().filter(g.siblings()))[0])if(s=Math.max(Number(n.css("zIndex")),0))P=s+10;else for(p=(i=x.parentsUntil(n)).length;S<p;S++)(s=Number(e(i[S]).css("zIndex")))&&P<s&&(P=s+10);g.css("zIndex",P),t&&t.isFixed?g.css({left:t.x,top:t.y}):g.css(h._align(z,T));var I=a(g,k,x[0]===g.offsetParent()[0]),O=a(g);x.offsetParent().parent(".k-animation-container,.k-popup,.k-group").length&&(I=a(g,k,!0),O=a(g)),O.top-=c.top,O.left-=c.left,h.wrapper.data(y)||g.data(y,R({},I));var A=R({},O),D=R({},I),N=v.adjustSize;"fit"===C[0]&&(D.top+=h._fit(A.top,d(g)+N.height,u/b)),"fit"===C[1]&&(D.left+=h._fit(A.left,l(g)+N.width,f/b));var F=R({},D),H=d(m),W=d(g);return!g.height()&&H&&(W+=H),"flip"===C[0]&&(D.top+=h._flip(A.top,H,d(x),u/b,z[0],T[0],W)),"flip"===C[1]&&(D.left+=h._flip(A.left,l(m),l(x),f/b,z[1],T[1],l(g))),g.css(D),D.left!=F.left||D.top!=F.top},_align:function(t,o){var n,i=this,s=i.wrapper,r=e(i.options.anchor),p=t[0],c=t[1],f=o[0],u=o[1],g=a(r),w=e(i.options.appendTo),b=l(s),_=d(s)||d(s.find(".k-child-animation-container").children().first()),y=l(r),k=d(r),x=i.options.omitOriginOffsets?0:g.top,z=i.options.omitOriginOffsets?0:g.left,T=Math.round;return w[0]!=document.body&&(x-=(n=a(w)).top,z-=n.left),p===v&&(x+=k),p===h&&(x+=T(k/2)),f===v&&(x-=_),f===h&&(x-=T(_/2)),c===m&&(z+=y),c===h&&(z+=T(y/2)),u===m&&(z-=b),u===h&&(z-=T(b/2)),{top:x,left:z}}});n.plugin(F);var H=o.support.stableSort,W="kendoTabKeyTrap",L=s.extend({init:function(t){this.element=e(t),this.element.autoApplyNS(W)},trap:function(){this.element.on("keydown",this._keepInTrap.bind(this))},removeTrap:function(){this.element.kendoDestroy(W)},destroy:function(){this.element.kendoDestroy(W),this.element=undefined},shouldTrap:function(){return!0},_keepInTrap:function(e){if(9===e.which&&this.shouldTrap()&&!e.isDefaultPrevented()){var t=this._focusableElements(),o=this._sortFocusableElements(t),n=this._nextFocusable(e,o);this._focus(n),e.preventDefault()}},_focusableElements:function(){var t=this.element.find("a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex], *[contenteditable]").filter((function(t,o){return o.tabIndex>=0&&e(o).is(":visible")&&!e(o).is("[disabled]")}));return this.element.is("[tabindex]")&&t.push(this.element[0]),t},_sortFocusableElements:function(e){var t;if(H)t=e.sort((function(e,t){return e.tabIndex-t.tabIndex}));else{var o="__k_index";e.each((function(e,t){t.setAttribute(o,e)})),t=e.sort((function(e,t){return e.tabIndex===t.tabIndex?parseInt(e.getAttribute(o),10)-parseInt(t.getAttribute(o),10):e.tabIndex-t.tabIndex})),e.removeAttr(o)}return t},_nextFocusable:function(e,t){var o=t.length,n=t.index(e.target);return t.get((n+(e.shiftKey?-1:1))%o)},_focus:function(e){"IFRAME"!=e.nodeName?(e.focus(),"INPUT"==e.nodeName&&e.setSelectionRange&&this._haveSelectionRange(e)&&e.setSelectionRange(0,e.value.length)):e.contentWindow.document.body.focus()},_haveSelectionRange:function(e){var t=e.type.toLowerCase();return"text"===t||"search"===t||"url"===t||"tel"===t||"password"===t}});n.Popup.TabKeyTrap=L}(window.kendo.jQuery)}));
//# sourceMappingURL=kendo.popup.min.js.map