/*! * AngularJS Material Design * https://github.com/angular/material * @license MIT * v1.1.18-master-97a1616 */ goog.provide("ngmaterial.components.panel"),goog.require("ngmaterial.components.backdrop"),goog.require("ngmaterial.core"),MdPanelService.$inject=["presets","$rootElement","$rootScope","$injector","$window"],angular.module("material.components.panel",["material.core","material.components.backdrop"]).provider("$mdPanel",MdPanelProvider);var MD_PANEL_Z_INDEX=80,MD_PANEL_HIDDEN="_md-panel-hidden",FOCUS_TRAP_TEMPLATE=angular.element('
'),_presets={};function MdPanelProvider(){return{definePreset:definePreset,getAllPresets:getAllPresets,clearPresets:clearPresets,$get:$getProvider()}}function definePreset(t,e){if(!t||!e)throw new Error("mdPanelProvider: The panel preset definition is malformed. The name and preset object are required.");if(_presets.hasOwnProperty(t))throw new Error("mdPanelProvider: The panel preset you have requested has already been defined.");delete e.id,delete e.position,delete e.animation,_presets[t]=e}function getAllPresets(){return angular.copy(_presets)}function clearPresets(){_presets={}}function $getProvider(){return["$rootElement","$rootScope","$injector","$window",function(t,e,n,o){return new MdPanelService(_presets,t,e,n,o)}]}function MdPanelService(t,e,n,o,i){this._defaultConfigOptions={bindToController:!0,clickOutsideToClose:!1,disableParentScroll:!1,escapeToClose:!1,focusOnOpen:!0,fullscreen:!1,hasBackdrop:!1,propagateContainerEvents:!1,transformTemplate:angular.bind(this,this._wrapTemplate),trapFocus:!1,zIndex:MD_PANEL_Z_INDEX},this._config={},this._presets=t,this._$rootElement=e,this._$rootScope=n,this._$injector=o,this._$window=i,this._$mdUtil=this._$injector.get("$mdUtil"),this._trackedPanels={},this._groups=Object.create(null),this.animation=MdPanelAnimation.animation,this.xPosition=MdPanelPosition.xPosition,this.yPosition=MdPanelPosition.yPosition,this.interceptorTypes=MdPanelRef.interceptorTypes,this.closeReasons=MdPanelRef.closeReasons,this.absPosition=MdPanelPosition.absPosition}function MdPanelRef(t,e){this._$q=e.get("$q"),this._$mdCompiler=e.get("$mdCompiler"),this._$mdConstant=e.get("$mdConstant"),this._$mdUtil=e.get("$mdUtil"),this._$mdTheming=e.get("$mdTheming"),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,this._interceptors=Object.create(null),this._compilerCleanup=null,this._restoreCache={styles:"",classes:""}}function MdPanelPosition(t){this._$window=t.get("$window"),this._isRTL="rtl"===t.get("$mdUtil").bidi(),this._$mdConstant=t.get("$mdConstant"),this._absolute=!1,this._relativeToEl,this._top="",this._bottom="",this._left="",this._right="",this._translateX=[],this._translateY=[],this._positions=[],this._actualPosition}function MdPanelAnimation(t){this._$mdUtil=t.get("$mdUtil"),this._openFrom,this._closeTo,this._animationClass="",this._openDuration,this._closeDuration,this._rawDuration}function getElement(t){var e=angular.isString(t)?document.querySelector(t):t;return angular.element(e)}function getComputedTranslations(t,e){var n=getComputedStyle(t[0]||t)[e],o=n.indexOf("("),i=n.lastIndexOf(")"),s={x:0,y:0};if(-1e.maxOpen}return!1},MdPanelService.prototype._closeFirstOpenedPanel=function(t){this._groups[t].openPanels[0].close()},MdPanelService.prototype._wrapTemplate=function(t){return'
'+(t||"")+"
"},MdPanelService.prototype._wrapContentElement=function(t){var e=angular.element('
');return t.addClass("md-panel _md-panel-offscreen"),e.append(t),e},MdPanelRef.interceptorTypes={CLOSE:"onClose"},MdPanelRef.prototype.open=function(){var i=this;return this._$q(function(t,e){var n=i._done(t,i),o=i._simpleBind(i.show,i);i.attach().then(o).then(function(){i.config.groupName&&angular.forEach(i.config.groupName,function(t){i._$mdPanel._openCountExceedsMaxOpen(t)&&i._$mdPanel._closeFirstOpenedPanel(t)})}).then(n).catch(e)})},MdPanelRef.prototype.close=function(s){var a=this;return this._$q(function(o,i){a._callInterceptors(MdPanelRef.interceptorTypes.CLOSE).then(function(){var t=a._done(o,a),e=a._simpleBind(a.detach,a),n=a.config.onCloseSuccess||angular.noop;n=angular.bind(a,n,a,s),a.hide().then(e).then(t).then(n).catch(i)},i)})},MdPanelRef.prototype.attach=function(){if(this.isAttached&&this.panelEl)return this._$q.when(this);var i=this;return this._$q(function(t,e){var n=i._done(t,i),o=i.config.onDomAdded||angular.noop;i._$q.all([i._createBackdrop(),i._createPanel().then(function(t){return i.isAttached=!0,i._addEventListeners(),t}).catch(e)]).then(o).then(n).catch(e)})},MdPanelRef.prototype.detach=function(){if(!this.isAttached)return this._$q.when(this);var o=this,i=o.config.onDomRemoved||angular.noop;return this._restoreScroll&&(this._restoreScroll(),this._restoreScroll=null),this._$q(function(t,e){var n=o._done(t,o);o._$q.all([(o._removeEventListeners(),o._topFocusTrap&&o._topFocusTrap.parentNode&&o._topFocusTrap.parentNode.removeChild(o._topFocusTrap),o._bottomFocusTrap&&o._bottomFocusTrap.parentNode&&o._bottomFocusTrap.parentNode.removeChild(o._bottomFocusTrap),o._restoreCache.classes&&(o.panelEl[0].className=o._restoreCache.classes),o.panelEl[0].style.cssText=o._restoreCache.styles||"",o._compilerCleanup(),o.panelContainer.remove(),o.isAttached=!1,o._$q.when(o)),!o._backdropRef||o._backdropRef.detach()]).then(i).then(n).catch(e)})},MdPanelRef.prototype.destroy=function(){var e=this;this.config.groupName&&angular.forEach(this.config.groupName,function(t){e.removeFromGroup(t)}),this.config.scope.$destroy(),this.config.locals=null,this.config.onDomAdded=null,this.config.onDomRemoved=null,this.config.onRemoving=null,this.config.onOpenComplete=null,this._interceptors=null},MdPanelRef.prototype.show=function(){if(!this.panelContainer)return this._$q(function(t,e){e("mdPanel: Panel does not exist yet. Call open() or attach().")});if(!this.panelContainer.hasClass(MD_PANEL_HIDDEN))return this._$q.when(this);var i=this;return this._$q(function(t,e){var n=i._done(t,i),o=i.config.onOpenComplete||angular.noop;i._$q.all([i._backdropRef?i._backdropRef.show():i,(i.panelContainer.removeClass(MD_PANEL_HIDDEN),i._animateOpen()).then(function(){i._focusOnOpen()},e)]).then(o).then(function(){i.config.groupName&&angular.forEach(i.config.groupName,function(t){i._$mdPanel._groups[t].openPanels.push(i)})}).then(n).catch(e)})},MdPanelRef.prototype.hide=function(){if(!this.panelContainer)return this._$q(function(t,e){e("mdPanel: Panel does not exist yet. Call open() or attach().")});if(this.panelContainer.hasClass(MD_PANEL_HIDDEN))return this._$q.when(this);var i=this;return this._$q(function(t,e){var n=i._done(t,i),o=i.config.onRemoving||angular.noop;i._$q.all([i._backdropRef?i._backdropRef.hide():i,i._animateClose().then(o).then(function(){i.panelContainer.addClass(MD_PANEL_HIDDEN)}).then(function(){var e;i.config.groupName&&angular.forEach(i.config.groupName,function(t){t=i._$mdPanel._groups[t],-1<(e=t.openPanels.indexOf(i))&&t.openPanels.splice(e,1)})}).then(function(){var t=i.config.origin;t&&getElement(t).focus()}).catch(e)]).then(n,e)})},MdPanelRef.prototype.addClass=function(t,e){if(this._$log.warn("mdPanel: The addClass method is in the process of being deprecated. Full deprecation is scheduled for the AngularJS 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("mdPanel: 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)},MdPanelRef.prototype.removeClass=function(t,e){if(this._$log.warn("mdPanel: The removeClass method is in the process of being deprecated. Full deprecation is scheduled for the AngularJS 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("mdPanel: 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)},MdPanelRef.prototype.toggleClass=function(t,e){if(this._$log.warn("mdPanel: The toggleClass method is in the process of being deprecated. Full deprecation is scheduled for the AngularJS 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("mdPanel: Panel does not exist yet. Call open() or attach().");e?this.panelEl.toggleClass(t):this.panelContainer.toggleClass(t)},MdPanelRef.prototype._compile=function(){var o=this;return o._$mdCompiler.compile(o.config).then(function(t){var e=o.config;if(e.contentElement){var n=t.element;o._restoreCache.styles=n[0].style.cssText,o._restoreCache.classes=n[0].className,o.panelContainer=o._$mdPanel._wrapContentElement(n),o.panelEl=n}else o.panelContainer=t.link(e.scope),o.panelEl=angular.element(o.panelContainer[0].querySelector(".md-panel"));return o._compilerCleanup=t.cleanup,getElement(o.config.attachTo).append(o.panelContainer),o})},MdPanelRef.prototype._createPanel=function(){var n=this;return this._$q(function(t,e){n.config.locals||(n.config.locals={}),(n.config.locals.mdPanelRef=n)._compile().then(function(){n.config.disableParentScroll&&(n._restoreScroll=n._$mdUtil.disableScrollAround(null,n.panelContainer,{disableScrollMask:!0})),n.config.panelClass&&n.panelEl.addClass(n.config.panelClass),n.config.propagateContainerEvents&&(n.panelContainer.css("pointer-events","none"),n.panelEl.css("pointer-events","all")),n._$animate.pin&&n._$animate.pin(n.panelContainer,getElement(n.config.attachTo)),n._configureTrapFocus(),n._addStyles().then(function(){t(n)},e)},e)})},MdPanelRef.prototype._addStyles=function(){var n=this;return this._$q(function(t){n.panelContainer.css("z-index",n.config.zIndex),n.panelEl.css("z-index",n.config.zIndex+1);function e(){n._setTheming(),n.panelEl.removeClass("_md-panel-offscreen"),n.panelContainer.addClass(MD_PANEL_HIDDEN),t(n)}if(n.config.fullscreen)return n.panelEl.addClass("_md-panel-fullscreen"),void e();n.config.position?n._$rootScope.$$postDigest(function(){n._updatePosition(!0),n._setTheming(),t(n)}):e()})},MdPanelRef.prototype._setTheming=function(){this._$mdTheming(this.panelEl),this._$mdTheming(this.panelContainer)},MdPanelRef.prototype.updatePosition=function(t){if(!this.panelContainer)throw new Error("mdPanel: Panel does not exist yet. Call open() or attach().");this.config.position=t,this._updatePosition()},MdPanelRef.prototype._updatePosition=function(t){var e=this.config.position;e&&(e._setPanelPosition(this.panelEl),t&&(this.panelEl.removeClass("_md-panel-offscreen"),this.panelContainer.addClass(MD_PANEL_HIDDEN)),this.panelEl.css(MdPanelPosition.absPosition.TOP,e.getTop()),this.panelEl.css(MdPanelPosition.absPosition.BOTTOM,e.getBottom()),this.panelEl.css(MdPanelPosition.absPosition.LEFT,e.getLeft()),this.panelEl.css(MdPanelPosition.absPosition.RIGHT,e.getRight()))},MdPanelRef.prototype._focusOnOpen=function(){if(this.config.focusOnOpen){var t=this;this._$rootScope.$$postDigest(function(){(t._$mdUtil.findFocusTarget(t.panelEl)||t.panelEl).focus()})}},MdPanelRef.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"});this.config.animation&&t.duration(this.config.animation._rawDuration);var 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()}},MdPanelRef.prototype._addEventListeners=function(){this._configureEscapeToClose(),this._configureClickOutsideToClose(),this._configureScrollListener()},MdPanelRef.prototype._removeEventListeners=function(){this._removeListeners&&this._removeListeners.forEach(function(t){t()}),this._removeListeners=[]},MdPanelRef.prototype._configureEscapeToClose=function(){if(this.config.escapeToClose){function t(t){t.keyCode===n._$mdConstant.KEY_CODE.ESCAPE&&(t.stopPropagation(),t.preventDefault(),n.close(MdPanelRef.closeReasons.ESCAPE))}var e=getElement(this.config.attachTo),n=this;this.panelContainer.on("keydown",t),e.on("keydown",t),this._removeListeners.push(function(){n.panelContainer.off("keydown",t),e.off("keydown",t)})}},MdPanelRef.prototype._configureClickOutsideToClose=function(){if(this.config.clickOutsideToClose){function t(t){n=t.target}function e(t){i.config.propagateContainerEvents?n===i.panelEl[0]||i.panelEl[0].contains(n)||i.close():n===o[0]&&t.target===o[0]&&(t.stopPropagation(),t.preventDefault(),i.close(MdPanelRef.closeReasons.CLICK_OUTSIDE))}var n,o=this.config.propagateContainerEvents?angular.element(document.body):this.panelContainer,i=this;o.on("mousedown",t),o.on("mouseup",e),this._removeListeners.push(function(){o.off("mousedown",t),o.off("mouseup",e)})}},MdPanelRef.prototype._configureScrollListener=function(){if(!this.config.disableParentScroll){function t(){n()}var e=angular.bind(this,this._updatePosition),n=this._$$rAF.throttle(e),o=this;this._$window.addEventListener("scroll",t,!0),this._removeListeners.push(function(){o._$window.removeEventListener("scroll",t,!0)})}},MdPanelRef.prototype._configureTrapFocus=function(){if(this.panelEl.attr("tabIndex","-1"),this.config.trapFocus){var t=this.panelEl;this._topFocusTrap=FOCUS_TRAP_TEMPLATE.clone()[0],this._bottomFocusTrap=FOCUS_TRAP_TEMPLATE.clone()[0];function e(){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)}},MdPanelRef.prototype.updateAnimation=function(t){this.config.animation=t,this._backdropRef&&this._backdropRef.config.animation.duration(t._rawDuration)},MdPanelRef.prototype._animateOpen=function(){this.panelContainer.addClass("md-panel-is-showing");var n=this.config.animation;if(!n)return this.panelContainer.addClass("_md-panel-shown"),this._$q.when(this);var o=this;return this._$q(function(t){var e=o._done(t,o);n.animateOpen(o.panelEl).then(e,function(){o._$log.warn("mdPanel: MdPanel Animations failed. Showing panel without animating."),e()})})},MdPanelRef.prototype._animateClose=function(){var n=this.config.animation;if(!n)return this.panelContainer.removeClass("md-panel-is-showing"),this.panelContainer.removeClass("_md-panel-shown"),this._$q.when(this);var o=this;return this._$q(function(t){function e(){o.panelContainer.removeClass("md-panel-is-showing"),t(o)}n.animateClose(o.panelEl).then(e,function(){o._$log.warn("mdPanel: MdPanel Animations failed. Hiding panel without animating."),e()})})},MdPanelRef.prototype.registerInterceptor=function(t,e){var n=null;if(angular.isString(t)?angular.isFunction(e)||(n="Interceptor callback must be a function, instead got "+typeof e):n="Interceptor type must be a string, instead got "+typeof t,n)throw new Error("MdPanel: "+n);var o=this._interceptors[t]=this._interceptors[t]||[];return-1===o.indexOf(e)&&o.push(e),this},MdPanelRef.prototype.removeInterceptor=function(t,e){var n=this._interceptors[t]?this._interceptors[t].indexOf(e):-1;return-1