@angular-mdc/web
Version:
22 lines (20 loc) • 13.9 kB
JavaScript
/**
* @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(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@material/ripple"),require("@angular-mdc/web/ripple"),require("@material/top-app-bar")):"function"==typeof define&&define.amd?define("@angular-mdc/web/top-app-bar",["exports","@angular/core","@angular/common","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@material/ripple","@angular-mdc/web/ripple","@material/top-app-bar"],e):e(((t=t||self).ng=t.ng||{},t.ng.web=t.ng.web||{},t.ng.web.topAppBar={}),t.ng.core,t.ng.common,t.ng.cdk.coercion,t.ng.cdk.platform,t.rxjs,t.rxjs.operators,t.ng.web.base,t.mdc.ripple,t.ng.web.ripple,t.mdc.topAppBar)}(this,(function(t,e,o,n,s,r,i,p,a,c,l){"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 d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};var u=function(){return(u=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var s in e=arguments[o])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)},h=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"[mdcTopAppBarFixedAdjust]",host:{class:"mdc-top-app-bar--fixed-adjust"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),f=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"mdc-top-app-bar-row, [mdcTopAppBarRow]",exportAs:"mdcTopAppBarRow",host:{class:"mdc-top-app-bar__row"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),m=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Component,args:[{selector:"mdc-top-app-bar-section, [mdcTopAppBarSection]",exportAs:"mdcTopAppBarSection",host:{role:"toolbar",class:"mdc-top-app-bar__section","[class.mdc-top-app-bar__section--align-start]":'align === "start"',"[class.mdc-top-app-bar__section--align-end]":'align === "end"'},template:'\n <ng-content></ng-content>\n <span class="mdc-top-app-bar__title" *ngIf="title">{{title}}</span>',changeDetection:e.ChangeDetectionStrategy.OnPush}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t.propDecorators={title:[{type:e.Input}],align:[{type:e.Input}]},t}(),_=function(){function t(t,e){this.elementRef=t,this._ripple=e,this._root=t.nativeElement,(e=this._createRipple()).init()}return t.prototype.ngOnDestroy=function(){this._ripple.destroy()},t.prototype._createRipple=function(){var t=u(u({},c.MdcRipple.createAdapter(this)),{isUnbounded:function(){return!0}});return new c.MdcRipple(this.elementRef,new a.MDCRippleFoundation(t))},t.decorators=[{type:e.Directive,args:[{selector:"[mdcTopAppBarActionItem], mdc-top-app-bar-action-item",exportAs:"mdcTopAppBarActionItem",host:{role:"button",class:"mdc-top-app-bar__action-item mdc-icon-button"},providers:[c.MdcRipple]}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:c.MdcRipple}]},t}(),g=function(){function t(t,e){this.elementRef=t,this._ripple=e,this._root=t.nativeElement,(e=this._createRipple()).init()}return t.prototype.ngOnDestroy=function(){this._ripple.destroy()},t.prototype._createRipple=function(){var t=u(u({},c.MdcRipple.createAdapter(this)),{isUnbounded:function(){return!0}});return new c.MdcRipple(this.elementRef,new a.MDCRippleFoundation(t))},t.decorators=[{type:e.Directive,args:[{selector:"[mdcTopAppBarNavIcon], mdc-icon[mdcTopAppBarNavigationIcon]",exportAs:"mdcTopAppBarNavigationIcon",host:{role:"button",class:"mdc-top-app-bar__navigation-icon mdc-icon-button"},providers:[c.MdcRipple]}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:c.MdcRipple}]},t}(),y=function(){function t(t){this.elementRef=t}return t.decorators=[{type:e.Directive,args:[{selector:"mdc-top-app-bar-title, [mdcTopAppBarTitle]",exportAs:"mdcTopAppBarTitle",host:{class:"mdc-top-app-bar__title"}}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t}(),b=function(t){this.source=t},A=function(t){function o(o,n,s,i){var p=t.call(this,i)||this;return p._ngZone=o,p._platform=n,p._changeDetectorRef=s,p.elementRef=i,p._destroyed=new r.Subject,p._fixed=!1,p._prominent=!1,p._short=!1,p._shortCollapsed=!1,p._dense=!1,p._fixedAdjustElement=null,p._scrollTarget=p._platform.isBrowser?p.scrollTarget||window:void 0,p.navigationSelected=new e.EventEmitter,p._scrollTargetSubscription=null,p}return function(t,e){function o(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}(o,t),Object.defineProperty(o.prototype,"fixed",{get:function(){return this._fixed},set:function(t){t!==this._fixed&&this.setFixed(t)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"prominent",{get:function(){return this._prominent},set:function(t){t!==this._prominent&&this.setProminent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"short",{get:function(){return this._short},set:function(t){t!==this._short&&this.setShort(t)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"shortCollapsed",{get:function(){return this._shortCollapsed},set:function(t){t!==this._shortCollapsed&&this.setShortCollapsed(t)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"dense",{get:function(){return this._dense},set:function(t){t!==this._dense&&this.setDense(t)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"fixedAdjustElement",{get:function(){return this._fixedAdjustElement},set:function(t){this._fixedAdjustElement!==t&&(this._fixedAdjustElement=t,this._initTopAppBar())},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"scrollTarget",{get:function(){return this._scrollTarget},set:function(t){t!==this._scrollTarget&&(this._scrollTarget=t||(this._platform.isBrowser?window:void 0),this._initScrollHandler())},enumerable:!0,configurable:!0}),o.prototype.getDefaultFoundation=function(){var t=this,e={hasClass:function(e){return t._getHostElement().classList.contains(e)},addClass:function(e){return t._getHostElement().classList.add(e)},removeClass:function(e){e===l.cssClasses.SHORT_COLLAPSED_CLASS&&t.shortCollapsed||t._getHostElement().classList.remove(e)},setStyle:function(e,o){return t._getHostElement().style.setProperty(e,o)},getTopAppBarHeight:function(){return t._getHostElement().clientHeight},notifyNavigationIconClicked:function(){return t.navigationSelected.emit({source:t})},getViewportScrollY:function(){return t._platform.isBrowser?t._scrollTarget[t._scrollTarget===window?"pageYOffset":"scrollTop"]:0},getTotalActionItems:function(){return t.actions?t.actions.length:0}};return this.elementRef?this.short?new l.MDCShortTopAppBarFoundation(e):this.fixed?new l.MDCFixedTopAppBarFoundation(e):new l.MDCTopAppBarFoundation(e):new l.MDCTopAppBarBaseFoundation(e)},o.prototype.ngAfterContentInit=function(){var t=this;this.actions.changes.pipe(i.startWith(null),i.takeUntil(this._destroyed)).subscribe((function(){t.short&&t.actions.length&&t._getHostElement().classList.toggle(l.cssClasses.SHORT_HAS_ACTION_ITEM_CLASS)}))},o.prototype.ngAfterViewInit=function(){this._initFoundation()},o.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete(),this._scrollTargetSubscription&&this._scrollTargetSubscription.unsubscribe(),this._destroyFoundation()},o.prototype.setFixed=function(t,e){void 0===e&&(e=!1),this._fixed=n.coerceBooleanProperty(t),this.fixed&&this.short&&this.setShort(!1),e&&this._initFoundation()},o.prototype.setProminent=function(t,e){void 0===e&&(e=!1),this._prominent=n.coerceBooleanProperty(t),this.prominent&&this.short&&this.setShort(!1),e&&this._initFoundation()},o.prototype.setDense=function(t,e){void 0===e&&(e=!1),this._dense=n.coerceBooleanProperty(t),this.dense&&this.short&&this.setShort(!1),e&&this._initFoundation()},o.prototype.setShort=function(t,e){void 0===e&&(e=!1),this._short=n.coerceBooleanProperty(t),this.short?(this.setProminent(!1),this.setDense(!1),this.setFixed(!1)):this.setShortCollapsed(!1),e&&this._initFoundation()},o.prototype.setShortCollapsed=function(t,e){void 0===e&&(e=!1),this._shortCollapsed=n.coerceBooleanProperty(t),this.shortCollapsed&&!this.short&&this.setShort(!0),e&&this._initFoundation()},o.prototype.isCollapsed=function(){return this._getHostElement().classList.contains(l.cssClasses.SHORT_COLLAPSED_CLASS)},o.prototype._initFoundation=function(){this._destroyFoundation(),this._getHostElement().style.top="0px",this._resetFixedShort(),this._foundation=this.getDefaultFoundation(),this._foundation.init(),this._initTopAppBar(),this._initScrollHandler(),this._changeDetectorRef.markForCheck()},o.prototype._resetFixedShort=function(){this._getHostElement().classList.remove(l.cssClasses.SHORT_HAS_ACTION_ITEM_CLASS),this._getHostElement().classList.remove(l.cssClasses.SHORT_COLLAPSED_CLASS),this._getHostElement().classList.remove(l.cssClasses.FIXED_SCROLLED_CLASS)},o.prototype._initTopAppBar=function(){this.fixed||this._getHostElement().classList.remove(l.cssClasses.FIXED_SCROLLED_CLASS),this.fixed&&this._getScrollOffset()>0&&this._getHostElement().classList.add(l.cssClasses.FIXED_SCROLLED_CLASS),this.short||(this._getHostElement().classList.remove(l.cssClasses.SHORT_HAS_ACTION_ITEM_CLASS),this._getHostElement().classList.remove(l.cssClasses.SHORT_COLLAPSED_CLASS)),this.short&&this._getScrollOffset()>0&&this._getHostElement().classList.add(l.cssClasses.SHORT_COLLAPSED_CLASS),this.shortCollapsed&&this._getHostElement().classList.add(l.cssClasses.SHORT_COLLAPSED_CLASS),this.fixedAdjustElement&&(this._removeFixedAdjustClasses(),this._addFixedAdjustClass())},o.prototype._removeFixedAdjustClasses=function(){this.fixedAdjustElement.classList.remove("mdc-top-app-bar--short-fixed-adjust"),this.fixedAdjustElement.classList.remove("mdc-top-app-bar--fixed-adjust"),this.fixedAdjustElement.classList.remove("mdc-top-app-bar--dense-fixed-adjust"),this.fixedAdjustElement.classList.remove("mdc-top-app-bar--prominent-fixed-adjust"),this.fixedAdjustElement.classList.remove("mdc-top-app-bar--dense-prominent-fixed-adjust")},o.prototype._addFixedAdjustClass=function(){this._short?this.fixedAdjustElement.classList.add("mdc-top-app-bar--short-fixed-adjust"):this._dense&&this._prominent?this.fixedAdjustElement.classList.add("mdc-top-app-bar--dense-prominent-fixed-adjust"):this._dense?this.fixedAdjustElement.classList.add("mdc-top-app-bar--dense-fixed-adjust"):this._prominent?this.fixedAdjustElement.classList.add("mdc-top-app-bar--prominent-fixed-adjust"):this.fixedAdjustElement.classList.add("mdc-top-app-bar--fixed-adjust")},o.prototype._destroyFoundation=function(){var t;null===(t=this._foundation)||void 0===t||t.destroy()},o.prototype._initScrollHandler=function(){var t=this;this._scrollTargetSubscription&&this._scrollTargetSubscription.unsubscribe(),this._platform.isBrowser&&(this._scrollTargetSubscription=this._ngZone.runOutsideAngular((function(){return r.fromEvent(t.scrollTarget||window,"scroll").subscribe((function(){return t._ngZone.run((function(){return t._foundation.handleTargetScroll()}))}))})))},o.prototype._getScrollOffset=function(){return this._platform.isBrowser?this.scrollTarget?this.scrollTarget.scrollTop:window.pageYOffset:0},o.prototype._getHostElement=function(){return this.elementRef.nativeElement},o.decorators=[{type:e.Component,args:[{selector:"mdc-top-app-bar, [mdc-top-app-bar]",exportAs:"mdcTopAppBar",host:{class:"mdc-top-app-bar","[class.mdc-top-app-bar--prominent]":"prominent","[class.mdc-top-app-bar--dense]":"dense","[class.mdc-top-app-bar--short]":"short","[class.mdc-top-app-bar--fixed]":"fixed"},template:"<ng-content></ng-content>",changeDetection:e.ChangeDetectionStrategy.OnPush,encapsulation:e.ViewEncapsulation.None}]}],o.ctorParameters=function(){return[{type:e.NgZone},{type:s.Platform},{type:e.ChangeDetectorRef},{type:e.ElementRef}]},o.propDecorators={fixed:[{type:e.Input}],prominent:[{type:e.Input}],short:[{type:e.Input}],shortCollapsed:[{type:e.Input}],dense:[{type:e.Input}],fixedAdjustElement:[{type:e.Input}],scrollTarget:[{type:e.Input}],navigationSelected:[{type:e.Output}],navigationIcon:[{type:e.ContentChild,args:[g,{static:!1}]}],actions:[{type:e.ContentChildren,args:[_,{descendants:!0}]}]},o}(p.MDCComponent),S=[A,_,h,g,f,m,y],C=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[o.CommonModule],exports:S,declarations:S}]}],t}();t.MdcTopAppBar=A,t.MdcTopAppBarActionItem=_,t.MdcTopAppBarFixedAdjust=h,t.MdcTopAppBarModule=C,t.MdcTopAppBarNavSelected=b,t.MdcTopAppBarNavigationIcon=g,t.MdcTopAppBarRow=f,t.MdcTopAppBarSection=m,t.MdcTopAppBarTitle=y,Object.defineProperty(t,"__esModule",{value:!0})}));