UNPKG

5.63 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2016 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 { MDCComponent } from '@material/base/component';
25import { applyPassive } from '@material/dom/events';
26import { matches } from '@material/dom/ponyfill';
27import { MDCRippleFoundation } from './foundation';
28import * as util from './util';
29var MDCRipple = /** @class */ (function (_super) {
30 __extends(MDCRipple, _super);
31 function MDCRipple() {
32 var _this = _super !== null && _super.apply(this, arguments) || this;
33 _this.disabled = false;
34 return _this;
35 }
36 MDCRipple.attachTo = function (root, opts) {
37 if (opts === void 0) { opts = { isUnbounded: undefined }; }
38 var ripple = new MDCRipple(root);
39 // Only override unbounded behavior if option is explicitly specified
40 if (opts.isUnbounded !== undefined) {
41 ripple.unbounded = opts.isUnbounded;
42 }
43 return ripple;
44 };
45 MDCRipple.createAdapter = function (instance) {
46 return {
47 addClass: function (className) { return instance.root.classList.add(className); },
48 browserSupportsCssVars: function () { return util.supportsCssVariables(window); },
49 computeBoundingRect: function () { return instance.root.getBoundingClientRect(); },
50 containsEventTarget: function (target) { return instance.root.contains(target); },
51 deregisterDocumentInteractionHandler: function (evtType, handler) {
52 return document.documentElement.removeEventListener(evtType, handler, applyPassive());
53 },
54 deregisterInteractionHandler: function (evtType, handler) {
55 return instance.root
56 .removeEventListener(evtType, handler, applyPassive());
57 },
58 deregisterResizeHandler: function (handler) {
59 return window.removeEventListener('resize', handler);
60 },
61 getWindowPageOffset: function () {
62 return ({ x: window.pageXOffset, y: window.pageYOffset });
63 },
64 isSurfaceActive: function () { return matches(instance.root, ':active'); },
65 isSurfaceDisabled: function () { return Boolean(instance.disabled); },
66 isUnbounded: function () { return Boolean(instance.unbounded); },
67 registerDocumentInteractionHandler: function (evtType, handler) {
68 return document.documentElement.addEventListener(evtType, handler, applyPassive());
69 },
70 registerInteractionHandler: function (evtType, handler) {
71 return instance.root
72 .addEventListener(evtType, handler, applyPassive());
73 },
74 registerResizeHandler: function (handler) {
75 return window.addEventListener('resize', handler);
76 },
77 removeClass: function (className) { return instance.root.classList.remove(className); },
78 updateCssVariable: function (varName, value) {
79 return instance.root.style.setProperty(varName, value);
80 },
81 };
82 };
83 Object.defineProperty(MDCRipple.prototype, "unbounded", {
84 get: function () {
85 return Boolean(this.unbounded_);
86 },
87 set: function (unbounded) {
88 this.unbounded_ = Boolean(unbounded);
89 this.setUnbounded_();
90 },
91 enumerable: false,
92 configurable: true
93 });
94 MDCRipple.prototype.activate = function () {
95 this.foundation.activate();
96 };
97 MDCRipple.prototype.deactivate = function () {
98 this.foundation.deactivate();
99 };
100 MDCRipple.prototype.layout = function () {
101 this.foundation.layout();
102 };
103 MDCRipple.prototype.getDefaultFoundation = function () {
104 return new MDCRippleFoundation(MDCRipple.createAdapter(this));
105 };
106 MDCRipple.prototype.initialSyncWithDOM = function () {
107 var root = this.root;
108 this.unbounded = 'mdcRippleIsUnbounded' in root.dataset;
109 };
110 /**
111 * Closure Compiler throws an access control error when directly accessing a
112 * protected or private property inside a getter/setter, like unbounded above.
113 * By accessing the protected property inside a method, we solve that problem.
114 * That's why this function exists.
115 */
116 MDCRipple.prototype.setUnbounded_ = function () {
117 this.foundation.setUnbounded(Boolean(this.unbounded_));
118 };
119 return MDCRipple;
120}(MDCComponent));
121export { MDCRipple };
122//# sourceMappingURL=component.js.map
\No newline at end of file