1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __extends } from "tslib";
|
24 | import { MDCComponent } from '@material/base/component';
|
25 | import { closest } from '@material/dom/ponyfill';
|
26 | import { strings } from './constants';
|
27 | import { MDCSnackbarFoundation } from './foundation';
|
28 | import * as util from './util';
|
29 | var SURFACE_SELECTOR = strings.SURFACE_SELECTOR, LABEL_SELECTOR = strings.LABEL_SELECTOR, ACTION_SELECTOR = strings.ACTION_SELECTOR, DISMISS_SELECTOR = strings.DISMISS_SELECTOR, OPENING_EVENT = strings.OPENING_EVENT, OPENED_EVENT = strings.OPENED_EVENT, CLOSING_EVENT = strings.CLOSING_EVENT, CLOSED_EVENT = strings.CLOSED_EVENT;
|
30 | var MDCSnackbar = (function (_super) {
|
31 | __extends(MDCSnackbar, _super);
|
32 | function MDCSnackbar() {
|
33 | return _super !== null && _super.apply(this, arguments) || this;
|
34 | }
|
35 | MDCSnackbar.attachTo = function (root) {
|
36 | return new MDCSnackbar(root);
|
37 | };
|
38 | MDCSnackbar.prototype.initialize = function (announcerFactory) {
|
39 | if (announcerFactory === void 0) { announcerFactory = function () { return util.announce; }; }
|
40 | this.announce = announcerFactory();
|
41 | };
|
42 | MDCSnackbar.prototype.initialSyncWithDOM = function () {
|
43 | var _this = this;
|
44 | this.surfaceEl = this.root.querySelector(SURFACE_SELECTOR);
|
45 | this.labelEl = this.root.querySelector(LABEL_SELECTOR);
|
46 | this.actionEl = this.root.querySelector(ACTION_SELECTOR);
|
47 | this.handleKeyDown = function (evt) {
|
48 | _this.foundation.handleKeyDown(evt);
|
49 | };
|
50 | this.handleSurfaceClick = function (evt) {
|
51 | var target = evt.target;
|
52 | if (_this.isActionButton(target)) {
|
53 | _this.foundation.handleActionButtonClick(evt);
|
54 | }
|
55 | else if (_this.isActionIcon(target)) {
|
56 | _this.foundation.handleActionIconClick(evt);
|
57 | }
|
58 | };
|
59 | this.registerKeyDownHandler(this.handleKeyDown);
|
60 | this.registerSurfaceClickHandler(this.handleSurfaceClick);
|
61 | };
|
62 | MDCSnackbar.prototype.destroy = function () {
|
63 | _super.prototype.destroy.call(this);
|
64 | this.deregisterKeyDownHandler(this.handleKeyDown);
|
65 | this.deregisterSurfaceClickHandler(this.handleSurfaceClick);
|
66 | };
|
67 | MDCSnackbar.prototype.open = function () {
|
68 | this.foundation.open();
|
69 | };
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | MDCSnackbar.prototype.close = function (reason) {
|
76 | if (reason === void 0) { reason = ''; }
|
77 | this.foundation.close(reason);
|
78 | };
|
79 | MDCSnackbar.prototype.getDefaultFoundation = function () {
|
80 | var _this = this;
|
81 |
|
82 |
|
83 | var adapter = {
|
84 | addClass: function (className) {
|
85 | _this.root.classList.add(className);
|
86 | },
|
87 | announce: function () {
|
88 | _this.announce(_this.labelEl);
|
89 | },
|
90 | notifyClosed: function (reason) { return _this.emit(CLOSED_EVENT, reason ? { reason: reason } : {}); },
|
91 | notifyClosing: function (reason) { return _this.emit(CLOSING_EVENT, reason ? { reason: reason } : {}); },
|
92 | notifyOpened: function () { return _this.emit(OPENED_EVENT, {}); },
|
93 | notifyOpening: function () { return _this.emit(OPENING_EVENT, {}); },
|
94 | removeClass: function (className) { return _this.root.classList.remove(className); },
|
95 | };
|
96 | return new MDCSnackbarFoundation(adapter);
|
97 | };
|
98 | Object.defineProperty(MDCSnackbar.prototype, "timeoutMs", {
|
99 | get: function () {
|
100 | return this.foundation.getTimeoutMs();
|
101 | },
|
102 | set: function (timeoutMs) {
|
103 | this.foundation.setTimeoutMs(timeoutMs);
|
104 | },
|
105 | enumerable: false,
|
106 | configurable: true
|
107 | });
|
108 | Object.defineProperty(MDCSnackbar.prototype, "closeOnEscape", {
|
109 | get: function () {
|
110 | return this.foundation.getCloseOnEscape();
|
111 | },
|
112 | set: function (closeOnEscape) {
|
113 | this.foundation.setCloseOnEscape(closeOnEscape);
|
114 | },
|
115 | enumerable: false,
|
116 | configurable: true
|
117 | });
|
118 | Object.defineProperty(MDCSnackbar.prototype, "isOpen", {
|
119 | get: function () {
|
120 | return this.foundation.isOpen();
|
121 | },
|
122 | enumerable: false,
|
123 | configurable: true
|
124 | });
|
125 | Object.defineProperty(MDCSnackbar.prototype, "labelText", {
|
126 | get: function () {
|
127 |
|
128 |
|
129 | return this.labelEl.textContent;
|
130 | },
|
131 | set: function (labelText) {
|
132 | this.labelEl.textContent = labelText;
|
133 | },
|
134 | enumerable: false,
|
135 | configurable: true
|
136 | });
|
137 | Object.defineProperty(MDCSnackbar.prototype, "actionButtonText", {
|
138 | get: function () {
|
139 | return this.actionEl.textContent;
|
140 | },
|
141 | set: function (actionButtonText) {
|
142 | this.actionEl.textContent = actionButtonText;
|
143 | },
|
144 | enumerable: false,
|
145 | configurable: true
|
146 | });
|
147 | MDCSnackbar.prototype.registerKeyDownHandler = function (handler) {
|
148 | this.listen('keydown', handler);
|
149 | };
|
150 | MDCSnackbar.prototype.deregisterKeyDownHandler = function (handler) {
|
151 | this.unlisten('keydown', handler);
|
152 | };
|
153 | MDCSnackbar.prototype.registerSurfaceClickHandler = function (handler) {
|
154 | this.surfaceEl.addEventListener('click', handler);
|
155 | };
|
156 | MDCSnackbar.prototype.deregisterSurfaceClickHandler = function (handler) {
|
157 | this.surfaceEl.removeEventListener('click', handler);
|
158 | };
|
159 | MDCSnackbar.prototype.isActionButton = function (target) {
|
160 | return Boolean(closest(target, ACTION_SELECTOR));
|
161 | };
|
162 | MDCSnackbar.prototype.isActionIcon = function (target) {
|
163 | return Boolean(closest(target, DISMISS_SELECTOR));
|
164 | };
|
165 | return MDCSnackbar;
|
166 | }(MDCComponent));
|
167 | export { MDCSnackbar };
|
168 |
|
\ | No newline at end of file |