1 | import { isActivatedDisabled } from './activator-base';
|
2 | var Activator = (function () {
|
3 | function Activator(app, config, dom) {
|
4 | this.app = app;
|
5 | this.dom = dom;
|
6 | this._queue = [];
|
7 | this._active = [];
|
8 | this.activatedDelay = ADD_ACTIVATED_DEFERS;
|
9 | this.clearDelay = CLEAR_STATE_DEFERS;
|
10 | this._css = config.get('activatedClass', 'activated');
|
11 | }
|
12 | Activator.prototype.clickAction = function (ev, activatableEle, _startCoord) {
|
13 | if (isActivatedDisabled(ev, activatableEle)) {
|
14 | return;
|
15 | }
|
16 |
|
17 | this._scheduleClear();
|
18 | this._queue.length = 0;
|
19 | for (var i = 0; i < this._active.length; i++) {
|
20 | this._active[i].classList.remove(this._css);
|
21 | }
|
22 | this._active.length = 0;
|
23 |
|
24 | if (activatableEle && activatableEle.parentNode) {
|
25 | this._active.push(activatableEle);
|
26 | activatableEle.classList.add(this._css);
|
27 | }
|
28 | };
|
29 | Activator.prototype.downAction = function (ev, activatableEle, _startCoord) {
|
30 | var _this = this;
|
31 |
|
32 | if (isActivatedDisabled(ev, activatableEle)) {
|
33 | return;
|
34 | }
|
35 | this.unscheduleClear();
|
36 | this.deactivate(true);
|
37 |
|
38 | this._queue.push(activatableEle);
|
39 | this._activeDefer = this.dom.write(function () {
|
40 | _this._activeDefer = null;
|
41 | var activatableEle;
|
42 | for (var i = 0; i < _this._queue.length; i++) {
|
43 | activatableEle = _this._queue[i];
|
44 | _this._active.push(activatableEle);
|
45 | activatableEle.classList.add(_this._css);
|
46 | }
|
47 | _this._queue.length = 0;
|
48 | }, this.activatedDelay);
|
49 | };
|
50 |
|
51 | Activator.prototype.upAction = function (_ev, _activatableEle, _startCoord) {
|
52 | this._scheduleClear();
|
53 | };
|
54 | Activator.prototype._scheduleClear = function () {
|
55 | var _this = this;
|
56 | if (this._clearDefer) {
|
57 | return;
|
58 | }
|
59 | this._clearDefer = this.dom.write(function () {
|
60 | _this.clearState(true);
|
61 | _this._clearDefer = null;
|
62 | }, this.clearDelay);
|
63 | };
|
64 | Activator.prototype.unscheduleClear = function () {
|
65 | if (this._clearDefer) {
|
66 | this._clearDefer();
|
67 | this._clearDefer = null;
|
68 | }
|
69 | };
|
70 |
|
71 | Activator.prototype.clearState = function (animated) {
|
72 | var _this = this;
|
73 | if (!this.app.isEnabled()) {
|
74 |
|
75 |
|
76 |
|
77 | this.dom.write(function () {
|
78 | _this.clearState(animated);
|
79 | }, 600);
|
80 | }
|
81 | else {
|
82 |
|
83 | this.deactivate(animated);
|
84 | }
|
85 | };
|
86 |
|
87 | Activator.prototype.deactivate = function (animated) {
|
88 | this._clearDeferred();
|
89 | this._queue.length = 0;
|
90 | var ele;
|
91 | for (var i = 0; i < this._active.length; i++) {
|
92 | ele = this._active[i];
|
93 | ele.style[this.dom.plt.Css.transition] = animated ? '' : 'none';
|
94 | ele.classList.remove(this._css);
|
95 | }
|
96 | this._active.length = 0;
|
97 | };
|
98 | Activator.prototype._clearDeferred = function () {
|
99 |
|
100 | if (this._activeDefer) {
|
101 | this._activeDefer();
|
102 | this._activeDefer = null;
|
103 | }
|
104 | };
|
105 | return Activator;
|
106 | }());
|
107 | export { Activator };
|
108 | var ADD_ACTIVATED_DEFERS = 80;
|
109 | var CLEAR_STATE_DEFERS = 80;
|
110 |
|
\ | No newline at end of file |