UNPKG

5.25 kBJavaScriptView Raw
1import { isActivatedDisabled } from './activator-base';
2var Activator = (function () {
3 /**
4 * @param {?} app
5 * @param {?} config
6 * @param {?} dom
7 */
8 function Activator(app, config, dom) {
9 this.app = app;
10 this.dom = dom;
11 this._queue = [];
12 this._active = [];
13 this.activatedDelay = ADD_ACTIVATED_DEFERS;
14 this.clearDelay = CLEAR_STATE_DEFERS;
15 this._css = config.get('activatedClass', 'activated');
16 }
17 /**
18 * @param {?} ev
19 * @param {?} activatableEle
20 * @param {?} _startCoord
21 * @return {?}
22 */
23 Activator.prototype.clickAction = function (ev, activatableEle, _startCoord) {
24 if (isActivatedDisabled(ev, activatableEle)) {
25 return;
26 }
27 // a click happened, so immediately deactive all activated elements
28 this._scheduleClear();
29 this._queue.length = 0;
30 for (var /** @type {?} */ i = 0; i < this._active.length; i++) {
31 this._active[i].classList.remove(this._css);
32 }
33 this._active.length = 0;
34 // then immediately activate this element
35 if (activatableEle && activatableEle.parentNode) {
36 this._active.push(activatableEle);
37 activatableEle.classList.add(this._css);
38 }
39 };
40 /**
41 * @param {?} ev
42 * @param {?} activatableEle
43 * @param {?} _startCoord
44 * @return {?}
45 */
46 Activator.prototype.downAction = function (ev, activatableEle, _startCoord) {
47 var _this = this;
48 // the user just pressed down
49 if (isActivatedDisabled(ev, activatableEle)) {
50 return;
51 }
52 this.unscheduleClear();
53 this.deactivate(true);
54 // queue to have this element activated
55 this._queue.push(activatableEle);
56 this._activeDefer = this.dom.write(function () {
57 _this._activeDefer = null;
58 var /** @type {?} */ activatableEle;
59 for (var /** @type {?} */ i = 0; i < _this._queue.length; i++) {
60 activatableEle = _this._queue[i];
61 _this._active.push(activatableEle);
62 activatableEle.classList.add(_this._css);
63 }
64 _this._queue.length = 0;
65 }, this.activatedDelay);
66 };
67 /**
68 * @param {?} _ev
69 * @param {?} _activatableEle
70 * @param {?} _startCoord
71 * @return {?}
72 */
73 Activator.prototype.upAction = function (_ev, _activatableEle, _startCoord) {
74 this._scheduleClear();
75 };
76 /**
77 * @return {?}
78 */
79 Activator.prototype._scheduleClear = function () {
80 var _this = this;
81 if (this._clearDefer) {
82 return;
83 }
84 this._clearDefer = this.dom.write(function () {
85 _this.clearState(true);
86 _this._clearDefer = null;
87 }, this.clearDelay);
88 };
89 /**
90 * @return {?}
91 */
92 Activator.prototype.unscheduleClear = function () {
93 if (this._clearDefer) {
94 this._clearDefer();
95 this._clearDefer = null;
96 }
97 };
98 /**
99 * @param {?} animated
100 * @return {?}
101 */
102 Activator.prototype.clearState = function (animated) {
103 var _this = this;
104 if (!this.app.isEnabled()) {
105 // the app is actively disabled, so don't bother deactivating anything.
106 // this makes it easier on the GPU so it doesn't have to redraw any
107 // buttons during a transition. This will retry in XX milliseconds.
108 this.dom.write(function () {
109 _this.clearState(animated);
110 }, 600);
111 }
112 else {
113 // not actively transitioning, good to deactivate any elements
114 this.deactivate(animated);
115 }
116 };
117 /**
118 * @param {?} animated
119 * @return {?}
120 */
121 Activator.prototype.deactivate = function (animated) {
122 this._clearDeferred();
123 this._queue.length = 0;
124 var /** @type {?} */ ele;
125 for (var /** @type {?} */ i = 0; i < this._active.length; i++) {
126 ele = this._active[i];
127 ((ele.style))[this.dom.plt.Css.transition] = animated ? '' : 'none';
128 ele.classList.remove(this._css);
129 }
130 this._active.length = 0;
131 };
132 /**
133 * @return {?}
134 */
135 Activator.prototype._clearDeferred = function () {
136 // Clear any active deferral
137 if (this._activeDefer) {
138 this._activeDefer();
139 this._activeDefer = null;
140 }
141 };
142 return Activator;
143}());
144export { Activator };
145function Activator_tsickle_Closure_declarations() {
146 /** @type {?} */
147 Activator.prototype._queue;
148 /** @type {?} */
149 Activator.prototype._active;
150 /** @type {?} */
151 Activator.prototype._activeDefer;
152 /** @type {?} */
153 Activator.prototype._clearDefer;
154 /** @type {?} */
155 Activator.prototype._css;
156 /** @type {?} */
157 Activator.prototype.activatedDelay;
158 /** @type {?} */
159 Activator.prototype.clearDelay;
160 /** @type {?} */
161 Activator.prototype.app;
162 /** @type {?} */
163 Activator.prototype.dom;
164}
165var /** @type {?} */ ADD_ACTIVATED_DEFERS = 80;
166var /** @type {?} */ CLEAR_STATE_DEFERS = 80;
167//# sourceMappingURL=activator.js.map
\No newline at end of file