UNPKG

4.38 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23import { __extends } from "tslib";
24import { cssClasses } from '../constants';
25import { MDCTopAppBarBaseFoundation } from '../foundation';
26var MDCShortTopAppBarFoundation = /** @class */ (function (_super) {
27 __extends(MDCShortTopAppBarFoundation, _super);
28 /* istanbul ignore next: optional argument is not a branch statement */
29 function MDCShortTopAppBarFoundation(adapter) {
30 var _this = _super.call(this, adapter) || this;
31 _this.collapsed = false;
32 _this.isAlwaysCollapsed = false;
33 return _this;
34 }
35 Object.defineProperty(MDCShortTopAppBarFoundation.prototype, "isCollapsed", {
36 // Public visibility for backward compatibility.
37 get: function () {
38 return this.collapsed;
39 },
40 enumerable: false,
41 configurable: true
42 });
43 MDCShortTopAppBarFoundation.prototype.init = function () {
44 _super.prototype.init.call(this);
45 if (this.adapter.getTotalActionItems() > 0) {
46 this.adapter.addClass(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS);
47 }
48 // If initialized with SHORT_COLLAPSED_CLASS, the bar should always be collapsed
49 this.setAlwaysCollapsed(this.adapter.hasClass(cssClasses.SHORT_COLLAPSED_CLASS));
50 };
51 /**
52 * Set if the short top app bar should always be collapsed.
53 *
54 * @param value When `true`, bar will always be collapsed. When `false`, bar may collapse or expand based on scroll.
55 */
56 MDCShortTopAppBarFoundation.prototype.setAlwaysCollapsed = function (value) {
57 this.isAlwaysCollapsed = !!value;
58 if (this.isAlwaysCollapsed) {
59 this.collapse();
60 }
61 else {
62 // let maybeCollapseBar determine if the bar should be collapsed
63 this.maybeCollapseBar();
64 }
65 };
66 MDCShortTopAppBarFoundation.prototype.getAlwaysCollapsed = function () {
67 return this.isAlwaysCollapsed;
68 };
69 /**
70 * Scroll handler for applying/removing the collapsed modifier class on the short top app bar.
71 */
72 MDCShortTopAppBarFoundation.prototype.handleTargetScroll = function () {
73 this.maybeCollapseBar();
74 };
75 MDCShortTopAppBarFoundation.prototype.maybeCollapseBar = function () {
76 if (this.isAlwaysCollapsed) {
77 return;
78 }
79 var currentScroll = this.adapter.getViewportScrollY();
80 if (currentScroll <= 0) {
81 if (this.collapsed) {
82 this.uncollapse();
83 }
84 }
85 else {
86 if (!this.collapsed) {
87 this.collapse();
88 }
89 }
90 };
91 MDCShortTopAppBarFoundation.prototype.uncollapse = function () {
92 this.adapter.removeClass(cssClasses.SHORT_COLLAPSED_CLASS);
93 this.collapsed = false;
94 };
95 MDCShortTopAppBarFoundation.prototype.collapse = function () {
96 this.adapter.addClass(cssClasses.SHORT_COLLAPSED_CLASS);
97 this.collapsed = true;
98 };
99 return MDCShortTopAppBarFoundation;
100}(MDCTopAppBarBaseFoundation));
101export { MDCShortTopAppBarFoundation };
102// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
103export default MDCShortTopAppBarFoundation;
104//# sourceMappingURL=foundation.js.map
\No newline at end of file