1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __assign, __extends } from "tslib";
|
24 | import { MDCComponent } from '@material/base/component';
|
25 | import { MDCRipple } from '@material/ripple/component';
|
26 | import { MDCRippleFoundation } from '@material/ripple/foundation';
|
27 | import { Selectors } from './constants';
|
28 | import { MDCSwitchRenderFoundation } from './foundation';
|
29 |
|
30 |
|
31 |
|
32 | var MDCSwitch = (function (_super) {
|
33 | __extends(MDCSwitch, _super);
|
34 | function MDCSwitch(root, foundation) {
|
35 | var _this = _super.call(this, root, foundation) || this;
|
36 | _this.root = root;
|
37 | return _this;
|
38 | }
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | MDCSwitch.attachTo = function (root) {
|
45 | return new MDCSwitch(root);
|
46 | };
|
47 | MDCSwitch.prototype.initialize = function () {
|
48 | this.ripple = new MDCRipple(this.root, this.createRippleFoundation());
|
49 | };
|
50 | MDCSwitch.prototype.initialSyncWithDOM = function () {
|
51 | var rippleElement = this.root.querySelector(Selectors.RIPPLE);
|
52 | if (!rippleElement) {
|
53 | throw new Error("Switch " + Selectors.RIPPLE + " element is required.");
|
54 | }
|
55 | this.rippleElement = rippleElement;
|
56 | this.root.addEventListener('click', this.foundation.handleClick);
|
57 | this.foundation.initFromDOM();
|
58 | };
|
59 | MDCSwitch.prototype.destroy = function () {
|
60 | _super.prototype.destroy.call(this);
|
61 | this.ripple.destroy();
|
62 | this.root.removeEventListener('click', this.foundation.handleClick);
|
63 | };
|
64 | MDCSwitch.prototype.getDefaultFoundation = function () {
|
65 | return new MDCSwitchRenderFoundation(this.createAdapter());
|
66 | };
|
67 | MDCSwitch.prototype.createAdapter = function () {
|
68 | var _this = this;
|
69 | return {
|
70 | addClass: function (className) {
|
71 | _this.root.classList.add(className);
|
72 | },
|
73 | hasClass: function (className) { return _this.root.classList.contains(className); },
|
74 | isDisabled: function () { return _this.root.disabled; },
|
75 | removeClass: function (className) {
|
76 | _this.root.classList.remove(className);
|
77 | },
|
78 | setAriaChecked: function (ariaChecked) {
|
79 | return _this.root.setAttribute('aria-checked', ariaChecked);
|
80 | },
|
81 | setDisabled: function (disabled) {
|
82 | _this.root.disabled = disabled;
|
83 | },
|
84 | state: this,
|
85 | };
|
86 | };
|
87 | MDCSwitch.prototype.createRippleFoundation = function () {
|
88 | return new MDCRippleFoundation(this.createRippleAdapter());
|
89 | };
|
90 | MDCSwitch.prototype.createRippleAdapter = function () {
|
91 | var _this = this;
|
92 | return __assign(__assign({}, MDCRipple.createAdapter(this)), { computeBoundingRect: function () { return _this.rippleElement.getBoundingClientRect(); }, isUnbounded: function () { return true; } });
|
93 | };
|
94 | return MDCSwitch;
|
95 | }(MDCComponent));
|
96 | export { MDCSwitch };
|
97 |
|
\ | No newline at end of file |