1 | import { isActivatedDisabled } from './activator-base';
|
2 | var Activator = (function () {
|
3 | |
4 |
|
5 |
|
6 |
|
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 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Activator.prototype.clickAction = function (ev, activatableEle, _startCoord) {
|
24 | if (isActivatedDisabled(ev, activatableEle)) {
|
25 | return;
|
26 | }
|
27 |
|
28 | this._scheduleClear();
|
29 | this._queue.length = 0;
|
30 | for (var i = 0; i < this._active.length; i++) {
|
31 | this._active[i].classList.remove(this._css);
|
32 | }
|
33 | this._active.length = 0;
|
34 |
|
35 | if (activatableEle && activatableEle.parentNode) {
|
36 | this._active.push(activatableEle);
|
37 | activatableEle.classList.add(this._css);
|
38 | }
|
39 | };
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | Activator.prototype.downAction = function (ev, activatableEle, _startCoord) {
|
47 | var _this = this;
|
48 |
|
49 | if (isActivatedDisabled(ev, activatableEle)) {
|
50 | return;
|
51 | }
|
52 | this.unscheduleClear();
|
53 | this.deactivate(true);
|
54 |
|
55 | this._queue.push(activatableEle);
|
56 | this._activeDefer = this.dom.write(function () {
|
57 | _this._activeDefer = null;
|
58 | var activatableEle;
|
59 | for (var 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 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | Activator.prototype.upAction = function (_ev, _activatableEle, _startCoord) {
|
74 | this._scheduleClear();
|
75 | };
|
76 | |
77 |
|
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 |
|
91 |
|
92 | Activator.prototype.unscheduleClear = function () {
|
93 | if (this._clearDefer) {
|
94 | this._clearDefer();
|
95 | this._clearDefer = null;
|
96 | }
|
97 | };
|
98 | |
99 |
|
100 |
|
101 |
|
102 | Activator.prototype.clearState = function (animated) {
|
103 | var _this = this;
|
104 | if (!this.app.isEnabled()) {
|
105 |
|
106 |
|
107 |
|
108 | this.dom.write(function () {
|
109 | _this.clearState(animated);
|
110 | }, 600);
|
111 | }
|
112 | else {
|
113 |
|
114 | this.deactivate(animated);
|
115 | }
|
116 | };
|
117 | |
118 |
|
119 |
|
120 |
|
121 | Activator.prototype.deactivate = function (animated) {
|
122 | this._clearDeferred();
|
123 | this._queue.length = 0;
|
124 | var ele;
|
125 | for (var 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 |
|
134 |
|
135 | Activator.prototype._clearDeferred = function () {
|
136 |
|
137 | if (this._activeDefer) {
|
138 | this._activeDefer();
|
139 | this._activeDefer = null;
|
140 | }
|
141 | };
|
142 | return Activator;
|
143 | }());
|
144 | export { Activator };
|
145 | function Activator_tsickle_Closure_declarations() {
|
146 |
|
147 | Activator.prototype._queue;
|
148 |
|
149 | Activator.prototype._active;
|
150 |
|
151 | Activator.prototype._activeDefer;
|
152 |
|
153 | Activator.prototype._clearDefer;
|
154 |
|
155 | Activator.prototype._css;
|
156 |
|
157 | Activator.prototype.activatedDelay;
|
158 |
|
159 | Activator.prototype.clearDelay;
|
160 |
|
161 | Activator.prototype.app;
|
162 |
|
163 | Activator.prototype.dom;
|
164 | }
|
165 | var ADD_ACTIVATED_DEFERS = 80;
|
166 | var CLEAR_STATE_DEFERS = 80;
|
167 |
|
\ | No newline at end of file |