a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { isActivatedDisabled } from './activator-base';
  2. export class Activator {
  3. constructor(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. clickAction(ev, activatableEle, _startCoord) {
  13. if (isActivatedDisabled(ev, activatableEle)) {
  14. return;
  15. }
  16. // a click happened, so immediately deactive all activated elements
  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. // then immediately activate this element
  24. if (activatableEle && activatableEle.parentNode) {
  25. this._active.push(activatableEle);
  26. activatableEle.classList.add(this._css);
  27. }
  28. }
  29. downAction(ev, activatableEle, _startCoord) {
  30. // the user just pressed down
  31. if (isActivatedDisabled(ev, activatableEle)) {
  32. return;
  33. }
  34. this.unscheduleClear();
  35. this.deactivate(true);
  36. // queue to have this element activated
  37. this._queue.push(activatableEle);
  38. this._activeDefer = this.dom.write(() => {
  39. this._activeDefer = null;
  40. let activatableEle;
  41. for (let i = 0; i < this._queue.length; i++) {
  42. activatableEle = this._queue[i];
  43. this._active.push(activatableEle);
  44. activatableEle.classList.add(this._css);
  45. }
  46. this._queue.length = 0;
  47. }, this.activatedDelay);
  48. }
  49. // the user was pressing down, then just let up
  50. upAction(_ev, _activatableEle, _startCoord) {
  51. this._scheduleClear();
  52. }
  53. _scheduleClear() {
  54. if (this._clearDefer) {
  55. return;
  56. }
  57. this._clearDefer = this.dom.write(() => {
  58. this.clearState(true);
  59. this._clearDefer = null;
  60. }, this.clearDelay);
  61. }
  62. unscheduleClear() {
  63. if (this._clearDefer) {
  64. this._clearDefer();
  65. this._clearDefer = null;
  66. }
  67. }
  68. // all states should return to normal
  69. clearState(animated) {
  70. if (!this.app.isEnabled()) {
  71. // the app is actively disabled, so don't bother deactivating anything.
  72. // this makes it easier on the GPU so it doesn't have to redraw any
  73. // buttons during a transition. This will retry in XX milliseconds.
  74. this.dom.write(() => {
  75. this.clearState(animated);
  76. }, 600);
  77. }
  78. else {
  79. // not actively transitioning, good to deactivate any elements
  80. this.deactivate(animated);
  81. }
  82. }
  83. // remove the active class from all active elements
  84. deactivate(animated) {
  85. this._clearDeferred();
  86. this._queue.length = 0;
  87. let ele;
  88. for (var i = 0; i < this._active.length; i++) {
  89. ele = this._active[i];
  90. ele.style[this.dom.plt.Css.transition] = animated ? '' : 'none';
  91. ele.classList.remove(this._css);
  92. }
  93. this._active.length = 0;
  94. }
  95. _clearDeferred() {
  96. // Clear any active deferral
  97. if (this._activeDefer) {
  98. this._activeDefer();
  99. this._activeDefer = null;
  100. }
  101. }
  102. }
  103. const ADD_ACTIVATED_DEFERS = 80;
  104. const CLEAR_STATE_DEFERS = 80;
  105. //# sourceMappingURL=activator.js.map