UNPKG

6.5 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 { getCorrectPropertyName } from '@material/animation/util';
25import { MDCComponent } from '@material/base/component';
26import { MDCTabBar } from '../tab-bar/component';
27import { MDCTabBarScrollerFoundation } from './foundation';
28var MDCTabBarScroller = /** @class */ (function (_super) {
29 tslib_1.__extends(MDCTabBarScroller, _super);
30 function MDCTabBarScroller() {
31 return _super !== null && _super.apply(this, arguments) || this;
32 }
33 MDCTabBarScroller.attachTo = function (root) {
34 return new MDCTabBarScroller(root);
35 };
36 Object.defineProperty(MDCTabBarScroller.prototype, "tabBar", {
37 get: function () {
38 return this.tabBar_;
39 },
40 enumerable: true,
41 configurable: true
42 });
43 MDCTabBarScroller.prototype.initialize = function (tabBarFactory) {
44 if (tabBarFactory === void 0) { tabBarFactory = function (el) { return new MDCTabBar(el); }; }
45 this.scrollFrame_ =
46 this.root_.querySelector(MDCTabBarScrollerFoundation.strings.FRAME_SELECTOR);
47 this.tabBarEl_ =
48 this.root_.querySelector(MDCTabBarScrollerFoundation.strings.TABS_SELECTOR);
49 this.forwardIndicator_ =
50 this.root_.querySelector(MDCTabBarScrollerFoundation.strings.INDICATOR_FORWARD_SELECTOR);
51 this.backIndicator_ =
52 this.root_.querySelector(MDCTabBarScrollerFoundation.strings.INDICATOR_BACK_SELECTOR);
53 this.tabBar_ = tabBarFactory(this.tabBarEl_);
54 };
55 MDCTabBarScroller.prototype.getDefaultFoundation = function () {
56 var _this = this;
57 // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
58 // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
59 // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
60 var adapter = {
61 addClass: function (className) { return _this.root_.classList.add(className); },
62 removeClass: function (className) { return _this.root_.classList.remove(className); },
63 eventTargetHasClass: function (target, className) { return target.classList.contains(className); },
64 addClassToForwardIndicator: function (className) { return _this.forwardIndicator_.classList.add(className); },
65 removeClassFromForwardIndicator: function (className) { return _this.forwardIndicator_.classList.remove(className); },
66 addClassToBackIndicator: function (className) { return _this.backIndicator_.classList.add(className); },
67 removeClassFromBackIndicator: function (className) { return _this.backIndicator_.classList.remove(className); },
68 isRTL: function () { return getComputedStyle(_this.root_).getPropertyValue('direction') === 'rtl'; },
69 registerBackIndicatorClickHandler: function (handler) { return _this.backIndicator_.addEventListener('click', handler); },
70 deregisterBackIndicatorClickHandler: function (handler) { return _this.backIndicator_.removeEventListener('click', handler); },
71 registerForwardIndicatorClickHandler: function (handler) { return _this.forwardIndicator_.addEventListener('click', handler); },
72 deregisterForwardIndicatorClickHandler: function (handler) { return _this.forwardIndicator_.removeEventListener('click', handler); },
73 registerCapturedInteractionHandler: function (evt, handler) { return _this.root_.addEventListener(evt, handler, true); },
74 deregisterCapturedInteractionHandler: function (evt, handler) { return _this.root_.removeEventListener(evt, handler, true); },
75 registerWindowResizeHandler: function (handler) { return window.addEventListener('resize', handler); },
76 deregisterWindowResizeHandler: function (handler) { return window.removeEventListener('resize', handler); },
77 getNumberOfTabs: function () { return _this.tabBar.tabs.length; },
78 getComputedWidthForTabAtIndex: function (index) { return _this.tabBar.tabs[index].computedWidth; },
79 getComputedLeftForTabAtIndex: function (index) { return _this.tabBar.tabs[index].computedLeft; },
80 getOffsetWidthForScrollFrame: function () { return _this.scrollFrame_.offsetWidth; },
81 getScrollLeftForScrollFrame: function () { return _this.scrollFrame_.scrollLeft; },
82 setScrollLeftForScrollFrame: function (scrollLeftAmount) { return _this.scrollFrame_.scrollLeft = scrollLeftAmount; },
83 getOffsetWidthForTabBar: function () { return _this.tabBarEl_.offsetWidth; },
84 setTransformStyleForTabBar: function (value) {
85 _this.tabBarEl_.style.setProperty(getCorrectPropertyName(window, 'transform'), value);
86 },
87 getOffsetLeftForEventTarget: function (target) { return target.offsetLeft; },
88 getOffsetWidthForEventTarget: function (target) { return target.offsetWidth; },
89 };
90 // tslint:enable:object-literal-sort-keys
91 return new MDCTabBarScrollerFoundation(adapter);
92 };
93 MDCTabBarScroller.prototype.layout = function () {
94 this.foundation_.layout();
95 };
96 return MDCTabBarScroller;
97}(MDCComponent));
98export { MDCTabBarScroller };
99//# sourceMappingURL=component.js.map
\No newline at end of file