UNPKG

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