UNPKG

5.52 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2017 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 * as tslib_1 from "tslib";
24import { MDCComponent } from '@material/base/component';
25import { MDCRipple } from '@material/ripple/component';
26import { MDCToolbarFoundation } from './foundation';
27var strings = MDCToolbarFoundation.strings;
28var MDCToolbar = /** @class */ (function (_super) {
29 tslib_1.__extends(MDCToolbar, _super);
30 function MDCToolbar() {
31 return _super !== null && _super.apply(this, arguments) || this;
32 }
33 MDCToolbar.attachTo = function (root) {
34 return new MDCToolbar(root);
35 };
36 MDCToolbar.prototype.initialize = function () {
37 var _this = this;
38 this.ripples_ = [];
39 this.fixedAdjustElement_ = null;
40 this.titleElement_ = this.root_.querySelector(strings.TITLE_SELECTOR);
41 var firstRowElement = this.root_.querySelector(strings.FIRST_ROW_SELECTOR);
42 if (!firstRowElement) {
43 throw new Error("MDCToolbar: Required sub-element '" + strings.FIRST_ROW_SELECTOR + "' is missing");
44 }
45 this.firstRowElement_ = firstRowElement;
46 [].forEach.call(this.root_.querySelectorAll(strings.ICON_SELECTOR), function (icon) {
47 var ripple = MDCRipple.attachTo(icon);
48 ripple.unbounded = true;
49 _this.ripples_.push(ripple);
50 });
51 };
52 MDCToolbar.prototype.destroy = function () {
53 this.ripples_.forEach(function (ripple) {
54 ripple.destroy();
55 });
56 _super.prototype.destroy.call(this);
57 };
58 Object.defineProperty(MDCToolbar.prototype, "fixedAdjustElement", {
59 get: function () {
60 return this.fixedAdjustElement_;
61 },
62 set: function (element) {
63 this.fixedAdjustElement_ = element;
64 this.foundation_.updateAdjustElementStyles();
65 },
66 enumerable: true,
67 configurable: true
68 });
69 MDCToolbar.prototype.getDefaultFoundation = function () {
70 var _this = this;
71 // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
72 // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
73 // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
74 var adapter = {
75 hasClass: function (className) { return _this.root_.classList.contains(className); },
76 addClass: function (className) { return _this.root_.classList.add(className); },
77 removeClass: function (className) { return _this.root_.classList.remove(className); },
78 registerScrollHandler: function (handler) { return window.addEventListener('scroll', handler); },
79 deregisterScrollHandler: function (handler) { return window.removeEventListener('scroll', handler); },
80 registerResizeHandler: function (handler) { return window.addEventListener('resize', handler); },
81 deregisterResizeHandler: function (handler) { return window.removeEventListener('resize', handler); },
82 getViewportWidth: function () { return window.innerWidth; },
83 getViewportScrollY: function () { return window.pageYOffset; },
84 getOffsetHeight: function () { return _this.root_.offsetHeight; },
85 getFirstRowElementOffsetHeight: function () { return _this.firstRowElement_.offsetHeight; },
86 notifyChange: function (evtData) { return _this.emit(strings.CHANGE_EVENT, evtData); },
87 setStyle: function (property, value) { return _this.root_.style.setProperty(property, value); },
88 setStyleForTitleElement: function (property, value) {
89 if (_this.titleElement_) {
90 _this.titleElement_.style.setProperty(property, value);
91 }
92 },
93 setStyleForFlexibleRowElement: function (property, value) { return _this.firstRowElement_.style.setProperty(property, value); },
94 setStyleForFixedAdjustElement: function (property, value) {
95 if (_this.fixedAdjustElement) {
96 _this.fixedAdjustElement.style.setProperty(property, value);
97 }
98 },
99 };
100 // tslint:enable:object-literal-sort-keys
101 return new MDCToolbarFoundation(adapter);
102 };
103 return MDCToolbar;
104}(MDCComponent));
105export { MDCToolbar };
106//# sourceMappingURL=component.js.map
\No newline at end of file