component.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  23. import * as tslib_1 from "tslib";
  24. import { MDCComponent } from '@material/base/component';
  25. import { applyPassive } from '@material/dom/events';
  26. import { matches } from '@material/dom/ponyfill';
  27. import { MDCRippleFoundation } from './foundation';
  28. import * as util from './util';
  29. var MDCRipple = /** @class */ (function (_super) {
  30. tslib_1.__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_.removeEventListener(evtType, handler, applyPassive());
  56. },
  57. deregisterResizeHandler: function (handler) { return window.removeEventListener('resize', handler); },
  58. getWindowPageOffset: function () { return ({ x: window.pageXOffset, y: window.pageYOffset }); },
  59. isSurfaceActive: function () { return matches(instance.root_, ':active'); },
  60. isSurfaceDisabled: function () { return Boolean(instance.disabled); },
  61. isUnbounded: function () { return Boolean(instance.unbounded); },
  62. registerDocumentInteractionHandler: function (evtType, handler) {
  63. return document.documentElement.addEventListener(evtType, handler, applyPassive());
  64. },
  65. registerInteractionHandler: function (evtType, handler) {
  66. return instance.root_.addEventListener(evtType, handler, applyPassive());
  67. },
  68. registerResizeHandler: function (handler) { return window.addEventListener('resize', handler); },
  69. removeClass: function (className) { return instance.root_.classList.remove(className); },
  70. updateCssVariable: function (varName, value) { return instance.root_.style.setProperty(varName, value); },
  71. };
  72. };
  73. Object.defineProperty(MDCRipple.prototype, "unbounded", {
  74. get: function () {
  75. return Boolean(this.unbounded_);
  76. },
  77. set: function (unbounded) {
  78. this.unbounded_ = Boolean(unbounded);
  79. this.setUnbounded_();
  80. },
  81. enumerable: true,
  82. configurable: true
  83. });
  84. MDCRipple.prototype.activate = function () {
  85. this.foundation_.activate();
  86. };
  87. MDCRipple.prototype.deactivate = function () {
  88. this.foundation_.deactivate();
  89. };
  90. MDCRipple.prototype.layout = function () {
  91. this.foundation_.layout();
  92. };
  93. MDCRipple.prototype.getDefaultFoundation = function () {
  94. return new MDCRippleFoundation(MDCRipple.createAdapter(this));
  95. };
  96. MDCRipple.prototype.initialSyncWithDOM = function () {
  97. var root = this.root_;
  98. this.unbounded = 'mdcRippleIsUnbounded' in root.dataset;
  99. };
  100. /**
  101. * Closure Compiler throws an access control error when directly accessing a
  102. * protected or private property inside a getter/setter, like unbounded above.
  103. * By accessing the protected property inside a method, we solve that problem.
  104. * That's why this function exists.
  105. */
  106. MDCRipple.prototype.setUnbounded_ = function () {
  107. this.foundation_.setUnbounded(Boolean(this.unbounded_));
  108. };
  109. return MDCRipple;
  110. }(MDCComponent));
  111. export { MDCRipple };
  112. //# sourceMappingURL=component.js.map