You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 lines
19 KiB

  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.0-master-2b98560
  6. */
  7. !function(t,e,n){"use strict";function o(t,n,o,i){this._defaultConfigOptions={bindToController:!0,clickOutsideToClose:!1,disableParentScroll:!1,escapeToClose:!1,focusOnOpen:!0,fullscreen:!1,hasBackdrop:!1,propagateContainerEvents:!1,transformTemplate:e.bind(this,this._wrapTemplate),trapFocus:!1,zIndex:l},this._config={},this._$rootElement=t,this._$rootScope=n,this._$injector=o,this._$window=i,this._trackedPanels={},this.animation=a.animation,this.xPosition=s.xPosition,this.yPosition=s.yPosition}function i(t,e){this._$q=e.get("$q"),this._$mdCompiler=e.get("$mdCompiler"),this._$mdConstant=e.get("$mdConstant"),this._$mdUtil=e.get("$mdUtil"),this._$rootScope=e.get("$rootScope"),this._$animate=e.get("$animate"),this._$mdPanel=e.get("$mdPanel"),this._$log=e.get("$log"),this._$window=e.get("$window"),this._$$rAF=e.get("$$rAF"),this.id=t.id,this.config=t,this.panelContainer,this.panelEl,this.isAttached=!1,this._removeListeners=[],this._topFocusTrap,this._bottomFocusTrap,this._backdropRef,this._restoreScroll=null}function s(t){this._$window=t.get("$window"),this._isRTL="rtl"===t.get("$mdUtil").bidi(),this._absolute=!1,this._relativeToEl,this._top="",this._bottom="",this._left="",this._right="",this._translateX=[],this._translateY=[],this._positions=[],this._actualPosition}function a(t){this._$mdUtil=t.get("$mdUtil"),this._openFrom,this._closeTo,this._animationClass=""}function r(t){var n=e.isString(t)?document.querySelector(t):t;return e.element(n)}o.$inject=["$rootElement","$rootScope","$injector","$window"],e.module("material.components.panel",["material.core","material.components.backdrop"]).service("$mdPanel",o);var l=80,h="_md-panel-hidden",c=e.element('<div class="_md-panel-focus-trap" tabindex="0"></div>');o.prototype.create=function(t){if(t=t||{},e.isDefined(t.id)&&this._trackedPanels[t.id])return this._trackedPanels[t.id];this._config={id:t.id||"panel_"+this._$injector.get("$mdUtil").nextUid(),scope:this._$rootScope.$new(!0),attachTo:this._$rootElement},e.extend(this._config,this._defaultConfigOptions,t);var n=new i(this._config,this._$injector);return this._trackedPanels[t.id]=n,n},o.prototype.open=function(t){var e=this.create(t);return e.open().then(function(){return e})},o.prototype.newPanelPosition=function(){return new s(this._$injector)},o.prototype.newPanelAnimation=function(){return new a(this._$injector)},o.prototype._wrapTemplate=function(t){var e=t||"";return'<div class="md-panel-outer-wrapper"> <div class="md-panel" style="left: -9999px;">'+e+"</div></div>"},i.prototype.open=function(){var t=this;return this._$q(function(e,n){var o=t._done(e,t),i=t._simpleBind(t.show,t);t.attach().then(i).then(o)["catch"](n)})},i.prototype.close=function(){var t=this;return this._$q(function(e,n){var o=t._done(e,t),i=t._simpleBind(t.detach,t);t.hide().then(i).then(o)["catch"](n)})},i.prototype.attach=function(){if(this.isAttached&&this.panelEl)return this._$q.when(this);var t=this;return this._$q(function(n,o){var i=t._done(n,t),s=t.config.onDomAdded||e.noop,a=function(e){return t.isAttached=!0,t._addEventListeners(),e};t._$q.all([t._createBackdrop(),t._createPanel().then(a)["catch"](o)]).then(s).then(i)["catch"](o)})},i.prototype.detach=function(){if(!this.isAttached)return this._$q.when(this);var t=this,n=t.config.onDomRemoved||e.noop,o=function(){return t._removeEventListeners(),t._topFocusTrap&&t._topFocusTrap.parentNode&&t._topFocusTrap.parentNode.removeChild(t._topFocusTrap),t._bottomFocusTrap&&t._bottomFocusTrap.parentNode&&t._bottomFocusTrap.parentNode.removeChild(t._bottomFocusTrap),t.panelContainer.remove(),t.isAttached=!1,t._$q.when(t)};return this._restoreScroll&&(this._restoreScroll(),this._restoreScroll=null),this._$q(function(e,i){var s=t._done(e,t);t._$q.all([o(),!t._backdropRef||t._backdropRef.detach()]).then(n).then(s)["catch"](i)})},i.prototype.destroy=function(){this.config.scope.$destroy(),this.config.locals=null},i.prototype.show=function(){if(!this.panelContainer)return this._$q(function(t,e){e("Panel does not exist yet. Call open() or attach().")});if(!this.panelContainer.hasClass(h))return this._$q.when(this);var t=this,n=function(){return t.panelContainer.removeClass(h),t._animateOpen()};return this._$q(function(o,i){var s=t._done(o,t),a=t.config.onOpenComplete||e.noop;t._$q.all([t._backdropRef?t._backdropRef.show():t,n().then(function(){t._focusOnOpen()},i)]).then(a).then(s)["catch"](i)})},i.prototype.hide=function(){if(!this.panelContainer)return this._$q(function(t,e){e("Panel does not exist yet. Call open() or attach().")});if(this.panelContainer.hasClass(h))return this._$q.when(this);var t=this;return this._$q(function(n,o){var i=t._done(n,t),s=t.config.onRemoving||e.noop,a=function(){var e=t.config.origin;e&&r(e).focus()},l=function(){t.panelContainer.addClass(h)};t._$q.all([t._backdropRef?t._backdropRef.hide():t,t._animateClose().then(s).then(l).then(a)["catch"](o)]).then(i,o)})},i.prototype.addClass=function(t,e){if(this._$log.warn("The addClass method is in the process of being deprecated. Full deprecation is scheduled for the Angular Material 1.2 release. To achieve the same results, use the panelContainer or panelEl JQLite elements that are referenced in MdPanelRef."),!this.panelContainer)throw new Error("Panel does not exist yet. Call open() or attach().");e||this.panelContainer.hasClass(t)?e&&!this.panelEl.hasClass(t)&&this.panelEl.addClass(t):this.panelContainer.addClass(t)},i.prototype.removeClass=function(t,e){if(this._$log.warn("The removeClass method is in the process of being deprecated. Full deprecation is scheduled for the Angular Material 1.2 release. To achieve the same results, use the panelContainer or panelEl JQLite elements that are referenced in MdPanelRef."),!this.panelContainer)throw new Error("Panel does not exist yet. Call open() or attach().");!e&&this.panelContainer.hasClass(t)?this.panelContainer.removeClass(t):e&&this.panelEl.hasClass(t)&&this.panelEl.removeClass(t)},i.prototype.toggleClass=function(t,e){if(this._$log.warn("The toggleClass method is in the process of being deprecated. Full deprecation is scheduled for the Angular Material 1.2 release. To achieve the same results, use the panelContainer or panelEl JQLite elements that are referenced in MdPanelRef."),!this.panelContainer)throw new Error("Panel does not exist yet. Call open() or attach().");e?this.panelEl.toggleClass(t):this.panelContainer.toggleClass(t)},i.prototype._createPanel=function(){var t=this;return this._$q(function(n,o){t.config.locals||(t.config.locals={}),t.config.locals.mdPanelRef=t,t._$mdCompiler.compile(t.config).then(function(i){t.panelContainer=i.link(t.config.scope),r(t.config.attachTo).append(t.panelContainer),t.config.disableParentScroll&&(t._restoreScroll=t._$mdUtil.disableScrollAround(null,t.panelContainer,{disableScrollMask:!0})),t.panelEl=e.element(t.panelContainer[0].querySelector(".md-panel")),t.config.panelClass&&t.panelEl.addClass(t.config.panelClass),t.config.propagateContainerEvents&&t.panelContainer.css("pointer-events","none"),t._$animate.pin&&t._$animate.pin(t.panelContainer,r(t.config.attachTo)),t._configureTrapFocus(),t._addStyles().then(function(){n(t)},o)},o)})},i.prototype._addStyles=function(){var t=this;return this._$q(function(e){t.panelContainer.css("z-index",t.config.zIndex),t.panelEl.css("z-index",t.config.zIndex+1);var n=function(){t.panelEl.css("left",""),t.panelContainer.addClass(h),e(t)};if(t.config.fullscreen)return t.panelEl.addClass("_md-panel-fullscreen"),void n();var o=t.config.position;return o?void t._$rootScope.$$postDigest(function(){t._updatePosition(!0),e(t)}):void n()})},i.prototype.updatePosition=function(t){if(!this.panelContainer)throw new Error("Panel does not exist yet. Call open() or attach().");this.config.position=t,this._updatePosition()},i.prototype._updatePosition=function(t){var e=this.config.position;if(e){e._setPanelPosition(this.panelEl),t&&this.panelContainer.addClass(h),this.panelEl.css(s.absPosition.TOP,e.getTop()),this.panelEl.css(s.absPosition.BOTTOM,e.getBottom()),this.panelEl.css(s.absPosition.LEFT,e.getLeft()),this.panelEl.css(s.absPosition.RIGHT,e.getRight());var n=this._$mdConstant.CSS.TRANSFORM;this.panelEl.css(n,e.getTransform())}},i.prototype._focusOnOpen=function(){if(this.config.focusOnOpen){var t=this;this._$rootScope.$$postDigest(function(){var e=t._$mdUtil.findFocusTarget(t.panelEl)||t.panelEl;e.focus()})}},i.prototype._createBackdrop=function(){if(this.config.hasBackdrop){if(!this._backdropRef){var t=this._$mdPanel.newPanelAnimation().openFrom(this.config.attachTo).withAnimation({open:"_md-opaque-enter",close:"_md-opaque-leave"}),e={animation:t,attachTo:this.config.attachTo,focusOnOpen:!1,panelClass:"_md-panel-backdrop",zIndex:this.config.zIndex-1};this._backdropRef=this._$mdPanel.create(e)}if(!this._backdropRef.isAttached)return this._backdropRef.attach()}},i.prototype._addEventListeners=function(){this._configureEscapeToClose(),this._configureClickOutsideToClose(),this._configureScrollListener()},i.prototype._removeEventListeners=function(){this._removeListeners&&this._removeListeners.forEach(function(t){t()}),this._removeListeners=[]},i.prototype._configureEscapeToClose=function(){if(this.config.escapeToClose){var t=r(this.config.attachTo),e=this,n=function(t){t.keyCode===e._$mdConstant.KEY_CODE.ESCAPE&&(t.stopPropagation(),t.preventDefault(),e.close())};this.panelContainer.on("keydown",n),t.on("keydown",n),this._removeListeners.push(function(){e.panelContainer.off("keydown",n),t.off("keydown",n)})}},i.prototype._configureClickOutsideToClose=function(){if(this.config.clickOutsideToClose){var t,e=this.panelContainer,n=function(e){t=e.target},o=this,i=function(n){t===e[0]&&n.target===e[0]&&(n.stopPropagation(),n.preventDefault(),o.close())};e.on("mousedown",n),e.on("mouseup",i),this._removeListeners.push(function(){e.off("mousedown",n),e.off("mouseup",i)})}},i.prototype._configureScrollListener=function(){var t=e.bind(this,this._updatePosition),n=this._$$rAF.throttle(t),o=this,i=function(){o.config.disableParentScroll||n()};this._$window.addEventListener("scroll",i,!0),this._removeListeners.push(function(){o._$window.removeEventListener("scroll",i,!0)})},i.prototype._configureTrapFocus=function(){if(this.panelEl.attr("tabIndex","-1"),this.config.trapFocus){var t=this.panelEl;this._topFocusTrap=c.clone()[0],this._bottomFocusTrap=c.clone()[0];var e=function(){t.focus()};this._topFocusTrap.addEventListener("focus",e),this._bottomFocusTrap.addEventListener("focus",e),this._removeListeners.push(this._simpleBind(function(){this._topFocusTrap.removeEventListener("focus",e),this._bottomFocusTrap.removeEventListener("focus",e)},this)),t[0].parentNode.insertBefore(this._topFocusTrap,t[0]),t.after(this._bottomFocusTrap)}},i.prototype._animateOpen=function(){this.panelContainer.addClass("md-panel-is-showing");var t=this.config.animation;if(!t)return this.panelContainer.addClass("_md-panel-shown"),this._$q.when(this);var e=this;return this._$q(function(n){var o=e._done(n,e),i=function(){e._$log.warn("MdPanel Animations failed. Showing panel without animating."),o()};t.animateOpen(e.panelEl).then(o,i)})},i.prototype._animateClose=function(){var t=this.config.animation;if(!t)return this.panelContainer.removeClass("md-panel-is-showing"),this.panelContainer.removeClass("_md-panel-shown"),this._$q.when(this);var e=this;return this._$q(function(n){var o=function(){e.panelContainer.removeClass("md-panel-is-showing"),n(e)},i=function(){e._$log.warn("MdPanel Animations failed. Hiding panel without animating."),o()};t.animateClose(e.panelEl).then(o,i)})},i.prototype._simpleBind=function(t,e){return function(n){return t.apply(e,n)}},i.prototype._done=function(t,e){return function(){t(e)}},s.xPosition={CENTER:"center",ALIGN_START:"align-start",ALIGN_END:"align-end",OFFSET_START:"offset-start",OFFSET_END:"offset-end"},s.yPosition={CENTER:"center",ALIGN_TOPS:"align-tops",ALIGN_BOTTOMS:"align-bottoms",ABOVE:"above",BELOW:"below"},s.absPosition={TOP:"top",RIGHT:"right",BOTTOM:"bottom",LEFT:"left"},s.prototype.absolute=function(){return this._absolute=!0,this},s.prototype._setPosition=function(t,n){if(t===s.absPosition.RIGHT||t===s.absPosition.LEFT)this._left=this._right="";else{if(t!==s.absPosition.BOTTOM&&t!==s.absPosition.TOP){var o=Object.keys(s.absPosition).join().toLowerCase();throw new Error("Position must be one of "+o+".")}this._top=this._bottom=""}return this["_"+t]=e.isString(n)?n:"0",this},s.prototype.top=function(t){return this._setPosition(s.absPosition.TOP,t)},s.prototype.bottom=function(t){return this._setPosition(s.absPosition.BOTTOM,t)},s.prototype.start=function(t){var e=this._isRTL?s.absPosition.RIGHT:s.absPosition.LEFT;return this._setPosition(e,t)},s.prototype.end=function(t){var e=this._isRTL?s.absPosition.LEFT:s.absPosition.RIGHT;return this._setPosition(e,t)},s.prototype.left=function(t){return this._setPosition(s.absPosition.LEFT,t)},s.prototype.right=function(t){return this._setPosition(s.absPosition.RIGHT,t)},s.prototype.centerHorizontally=function(){return this._left="50%",this._right="",this._translateX=["-50%"],this},s.prototype.centerVertically=function(){return this._top="50%",this._bottom="",this._translateY=["-50%"],this},s.prototype.center=function(){return this.centerHorizontally().centerVertically()},s.prototype.relativeTo=function(t){return this._absolute=!1,this._relativeToEl=r(t),this},s.prototype.addPanelPosition=function(t,e){if(!this._relativeToEl)throw new Error("addPanelPosition can only be used with relative positioning. Set relativeTo first.");return this._validateXPosition(t),this._validateYPosition(e),this._positions.push({x:t,y:e}),this},s.prototype._validateYPosition=function(t){if(null!=t){for(var e,n=Object.keys(s.yPosition),o=[],i=0;e=n[i];i++){var a=s.yPosition[e];if(o.push(a),a===t)return}throw new Error("Panel y position only accepts the following values:\n"+o.join(" | "))}},s.prototype._validateXPosition=function(t){if(null!=t){for(var e,n=Object.keys(s.xPosition),o=[],i=0;e=n[i];i++){var a=s.xPosition[e];if(o.push(a),a===t)return}throw new Error("Panel x Position only accepts the following values:\n"+o.join(" | "))}},s.prototype.withOffsetX=function(t){return this._translateX.push(t),this},s.prototype.withOffsetY=function(t){return this._translateY.push(t),this},s.prototype.getTop=function(){return this._top},s.prototype.getBottom=function(){return this._bottom},s.prototype.getLeft=function(){return this._left},s.prototype.getRight=function(){return this._right},s.prototype.getTransform=function(){var t=this._reduceTranslateValues("translateX",this._translateX),e=this._reduceTranslateValues("translateY",this._translateY);return(t+" "+e).trim()},s.prototype._isOnscreen=function(t){var e=parseInt(this.getLeft()),n=parseInt(this.getTop()),o=e+t[0].offsetWidth,i=n+t[0].offsetHeight;return e>=0&&n>=0&&i<=this._$window.innerHeight&&o<=this._$window.innerWidth},s.prototype.getActualPosition=function(){return this._actualPosition},s.prototype._reduceTranslateValues=function(t,e){return e.map(function(e){return t+"("+e+")"}).join(" ")},s.prototype._setPanelPosition=function(t){if(!this._absolute){if(this._actualPosition)return void this._calculatePanelPosition(t,this._actualPosition);for(var e=0;e<this._positions.length&&(this._actualPosition=this._positions[e],this._calculatePanelPosition(t,this._actualPosition),!this._isOnscreen(t));e++);}},s.prototype._reverseXPosition=function(t){if(t!==s.xPosition.CENTER){var e="start",n="end";return t.indexOf(e)>-1?t.replace(e,n):t.replace(n,e)}},s.prototype._bidi=function(t){return this._isRTL?this._reverseXPosition(t):t},s.prototype._calculatePanelPosition=function(t,e){var n=t[0].getBoundingClientRect(),o=n.width,i=n.height,a=this._relativeToEl[0].getBoundingClientRect(),r=a.left,l=a.right,h=a.width;switch(this._bidi(e.x)){case s.xPosition.OFFSET_START:this._left=r-o+"px";break;case s.xPosition.ALIGN_END:this._left=l-o+"px";break;case s.xPosition.CENTER:var c=r+.5*h-.5*o;this._left=c+"px";break;case s.xPosition.ALIGN_START:this._left=r+"px";break;case s.xPosition.OFFSET_END:this._left=l+"px"}var p=a.top,u=a.bottom,f=a.height;switch(e.y){case s.yPosition.ABOVE:this._top=p-i+"px";break;case s.yPosition.ALIGN_BOTTOMS:this._top=u-i+"px";break;case s.yPosition.CENTER:var _=p+.5*f-.5*i;this._top=_+"px";break;case s.yPosition.ALIGN_TOPS:this._top=p+"px";break;case s.yPosition.BELOW:this._top=u+"px"}},a.animation={SLIDE:"md-panel-animate-slide",SCALE:"md-panel-animate-scale",FADE:"md-panel-animate-fade"},a.prototype.openFrom=function(t){return t=t.target?t.target:t,this._openFrom=this._getPanelAnimationTarget(t),this._closeTo||(this._closeTo=this._openFrom),this},a.prototype.closeTo=function(t){return this._closeTo=this._getPanelAnimationTarget(t),this},a.prototype._getPanelAnimationTarget=function(t){return e.isDefined(t.top)||e.isDefined(t.left)?{element:n,bounds:{top:t.top||0,left:t.left||0}}:this._getBoundingClientRect(r(t))},a.prototype.withAnimation=function(t){return this._animationClass=t,this},a.prototype.animateOpen=function(t){var n=this._$mdUtil.dom.animator;this._fixBounds(t);var o={},i=t[0].style.transform||"",s=n.toTransformCss(i),r=n.toTransformCss(i);switch(this._animationClass){case a.animation.SLIDE:t.css("opacity","1"),o={transitionInClass:"_md-panel-animate-enter"};var l=n.calculateSlideToOrigin(t,this._openFrom)||"";s=n.toTransformCss(l+" "+i);break;case a.animation.SCALE:o={transitionInClass:"_md-panel-animate-enter"};var h=n.calculateZoomToOrigin(t,this._openFrom)||"";s=n.toTransformCss(h+" "+i);break;case a.animation.FADE:o={transitionInClass:"_md-panel-animate-enter"};break;default:o=e.isString(this._animationClass)?{transitionInClass:this._animationClass}:{transitionInClass:this._animationClass.open,transitionOutClass:this._animationClass.close}}return n.translate3d(t,s,r,o)},a.prototype.animateClose=function(t){var n=this._$mdUtil.dom.animator,o={},i=t[0].style.transform||"",s=n.toTransformCss(i),r=n.toTransformCss(i);switch(this._animationClass){case a.animation.SLIDE:t.css("opacity","1"),o={transitionInClass:"_md-panel-animate-leave"};var l=n.calculateSlideToOrigin(t,this._closeTo)||"";r=n.toTransformCss(l+" "+i);break;case a.animation.SCALE:o={transitionInClass:"_md-panel-animate-scale-out _md-panel-animate-leave"};var h=n.calculateZoomToOrigin(t,this._closeTo)||"";r=n.toTransformCss(h+" "+i);break;case a.animation.FADE:o={transitionInClass:"_md-panel-animate-fade-out _md-panel-animate-leave"};break;default:o=e.isString(this._animationClass)?{transitionOutClass:this._animationClass}:{transitionInClass:this._animationClass.close,transitionOutClass:this._animationClass.open}}return n.translate3d(t,s,r,o)},a.prototype._fixBounds=function(t){var e=t[0].offsetWidth,n=t[0].offsetHeight;this._openFrom&&null==this._openFrom.bounds.height&&(this._openFrom.bounds.height=n),this._openFrom&&null==this._openFrom.bounds.width&&(this._openFrom.bounds.width=e),this._closeTo&&null==this._closeTo.bounds.height&&(this._closeTo.bounds.height=n),this._closeTo&&null==this._closeTo.bounds.width&&(this._closeTo.bounds.width=e)},a.prototype._getBoundingClientRect=function(t){if(t instanceof e.element)return{element:t,bounds:t[0].getBoundingClientRect()}}}(window,window.angular);