UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 9.71 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@material/menu-surface")):"function"==typeof define&&define.amd?define("@angular-mdc/web/menu-surface",["exports","@angular/core","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@material/menu-surface"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.menuSurface={}),e.ng.core,e.ng.cdk.coercion,e.ng.cdk.platform,e.rxjs,e.rxjs.operators,e.ng.web.base,e.mdc.menuSurface)}(this,(function(e,t,n,o,r,i,s,c){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var l={topEnd:c.Corner.TOP_END,topStart:c.Corner.TOP_START,bottomEnd:c.Corner.BOTTOM_END,bottomStart:c.Corner.BOTTOM_START},f=function(e){function s(n,o,i,s){var c=e.call(this,s)||this;return c.changeDetectorRef=n,c.platform=o,c._ngZone=i,c.elementRef=s,c._destroy=new r.Subject,c._open=!1,c._anchorCorner="topStart",c._quickOpen=!1,c._fixed=!1,c._coordinates={x:0,y:0},c._anchorMargin={},c._hoistToBody=!1,c.opened=new t.EventEmitter,c.closed=new t.EventEmitter,c._windowClickSubscription=null,c}return a(s,e),Object.defineProperty(s.prototype,"open",{get:function(){return this._open},set:function(e){n.coerceBooleanProperty(e)!==this._open&&(this._open=n.coerceBooleanProperty(e),this._open?this._foundation.open():this._foundation.close())},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"anchorElement",{get:function(){return this._anchorElement},set:function(e){this._anchorElement=e},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"anchorCorner",{get:function(){return this._anchorCorner},set:function(e){this._anchorCorner=null!=e?e:"topStart",this._foundation.setAnchorCorner(l[this._anchorCorner])},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"quickOpen",{get:function(){return this._quickOpen},set:function(e){this._quickOpen=n.coerceBooleanProperty(e),this._foundation.setQuickOpen(this._quickOpen)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"fixed",{get:function(){return this._fixed},set:function(e){this._fixed=n.coerceBooleanProperty(e),this._fixed?this._getHostElement().classList.add("mdc-menu-surface--fixed"):this._getHostElement().classList.remove("mdc-menu-surface--fixed"),this._foundation.setFixedPosition(this._fixed)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"coordinates",{get:function(){return this._coordinates},set:function(e){this._coordinates=e,this._foundation.setAbsolutePosition(e.x,e.y)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"anchorMargin",{get:function(){return this._anchorMargin},set:function(e){this._anchorMargin=e,this._foundation.setAnchorMargin(this._anchorMargin)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"hoistToBody",{get:function(){return this._hoistToBody},set:function(e){this._hoistToBody=n.coerceBooleanProperty(e),this._hoistToBody&&this.setHoistToBody()},enumerable:!0,configurable:!0}),s.prototype.getDefaultFoundation=function(){var e=this,t={addClass:function(t){return e._getHostElement().classList.add(t)},removeClass:function(t){return e._getHostElement().classList.remove(t)},hasClass:function(t){return e._getHostElement().classList.contains(t)},hasAnchor:function(){return!!e.anchorElement},notifyClose:function(){e.closed.emit(),e._deregisterWindowClickListener()},notifyOpen:function(){e.opened.emit(),e._registerWindowClickListener()},isElementInContainer:function(t){return e._getHostElement()===t||e._getHostElement().contains(t)},isRtl:function(){return!!e.platform.isBrowser&&"rtl"===window.getComputedStyle(e._getHostElement()).getPropertyValue("direction")},setTransformOrigin:function(t){return!!e.platform.isBrowser&&(e._getHostElement().style[c.util.getTransformPropertyName(window)+"-origin"]=t)},isFocused:function(){var t,n;return null!=(n=(null===(t=document)||void 0===t?void 0:t.activeElement)===e._getHostElement())&&n},saveFocus:function(){var t,n;return e._previousFocus=null!=(n=null===(t=document)||void 0===t?void 0:t.activeElement)?n:void 0},restoreFocus:function(){var t;e.platform.isBrowser&&e._getHostElement().contains(document.activeElement)&&(null===(t=e._previousFocus)||void 0===t||t.focus())},getInnerDimensions:function(){return{width:e._getHostElement().offsetWidth,height:e._getHostElement().offsetHeight}},getAnchorDimensions:function(){return e.platform.isBrowser||!e.anchorElement?e._anchorElement.getBoundingClientRect():{top:0,right:0,bottom:0,left:0,width:0,height:0}},getWindowDimensions:function(){return{width:e.platform.isBrowser?window.innerWidth:0,height:e.platform.isBrowser?window.innerHeight:0}},getBodyDimensions:function(){return{width:e.platform.isBrowser?document.body.clientWidth:0,height:e.platform.isBrowser?document.body.clientHeight:0}},getWindowScroll:function(){return{x:e.platform.isBrowser?window.pageXOffset:0,y:e.platform.isBrowser?window.pageYOffset:0}},setPosition:function(t){e._getHostElement().style.left="left"in t?t.left+"px":"",e._getHostElement().style.right="right"in t?t.right+"px":"",e._getHostElement().style.top="top"in t?t.top+"px":"",e._getHostElement().style.bottom="bottom"in t?t.bottom+"px":""},setMaxHeight:function(t){return e._getHostElement().style.maxHeight=t}};return new c.MDCMenuSurfaceFoundation(t)},s.prototype.initMenuSurface=function(){var e;this._foundation.init(),this.anchorElement=null!=(e=this._getHostElement().parentElement)?e:this.anchorElement,this._registerKeydownListener()},s.prototype.destroyMenuSurface=function(){this._destroy.next(),this._destroy.complete(),this._deregisterWindowClickListener(),this.platform.isBrowser&&this._foundation.destroy(),this.hoistToBody&&document.body.removeChild(this._getHostElement())},s.prototype.setHoistToBody=function(){if(this.platform.isBrowser){var e=this._getHostElement().parentElement;e&&(document.body.appendChild(e.removeChild(this._getHostElement())),this._foundation.setIsHoisted(!0))}},s.prototype._registerKeydownListener=function(){var e=this;r.fromEvent(this._getHostElement(),"keydown").pipe(i.takeUntil(this._destroy)).subscribe((function(t){e._foundation.handleKeydown(t),e._open=e._foundation.isOpen()}))},s.prototype._registerWindowClickListener=function(){var e=this;this.platform.isBrowser&&(this._windowClickSubscription=this._ngZone.runOutsideAngular((function(){return r.fromEvent(window,"click").subscribe((function(t){return e._ngZone.run((function(){e._foundation.handleBodyClick(t),e._open=e._foundation.isOpen()}))}))})))},s.prototype._deregisterWindowClickListener=function(){var e;null===(e=this._windowClickSubscription)||void 0===e||e.unsubscribe()},s.prototype._getHostElement=function(){return this.elementRef.nativeElement},s.decorators=[{type:t.Directive}],s.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:o.Platform},{type:t.NgZone,decorators:[{type:t.Optional}]},{type:t.ElementRef}]},s.propDecorators={open:[{type:t.Input}],anchorElement:[{type:t.Input}],anchorCorner:[{type:t.Input}],quickOpen:[{type:t.Input}],fixed:[{type:t.Input}],coordinates:[{type:t.Input}],anchorMargin:[{type:t.Input}],hoistToBody:[{type:t.Input}],opened:[{type:t.Output}],closed:[{type:t.Output}]},s}(s.MDCComponent),p=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return a(n,e),n.prototype.ngOnInit=function(){this.initMenuSurface()},n.prototype.ngOnDestroy=function(){this.destroyMenuSurface()},n.decorators=[{type:t.Component,args:[{selector:"mdc-menu-surface",exportAs:"mdcMenuSurface",host:{class:"mdc-menu-surface"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],n}(f),d=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcMenuSurfaceAnchor], mdc-menu-surface-anchor",host:{class:"mdc-menu-surface--anchor"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),h=[p,d],m=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{exports:[h],declarations:[h]}]}],e}();e.MdcMenuSurface=p,e.MdcMenuSurfaceAnchor=d,e.MdcMenuSurfaceBase=f,e.MdcMenuSurfaceModule=m,Object.defineProperty(e,"__esModule",{value:!0})}));