a zip code crypto-currency system good for red ONLY

activator.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "./activator-base"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var activator_base_1 = require("./activator-base");
  13. var Activator = (function () {
  14. function Activator(app, config, dom) {
  15. this.app = app;
  16. this.dom = dom;
  17. this._queue = [];
  18. this._active = [];
  19. this.activatedDelay = ADD_ACTIVATED_DEFERS;
  20. this.clearDelay = CLEAR_STATE_DEFERS;
  21. this._css = config.get('activatedClass', 'activated');
  22. }
  23. Activator.prototype.clickAction = function (ev, activatableEle, _startCoord) {
  24. if (activator_base_1.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 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. Activator.prototype.downAction = function (ev, activatableEle, _startCoord) {
  41. var _this = this;
  42. // the user just pressed down
  43. if (activator_base_1.isActivatedDisabled(ev, activatableEle)) {
  44. return;
  45. }
  46. this.unscheduleClear();
  47. this.deactivate(true);
  48. // queue to have this element activated
  49. this._queue.push(activatableEle);
  50. this._activeDefer = this.dom.write(function () {
  51. _this._activeDefer = null;
  52. var activatableEle;
  53. for (var i = 0; i < _this._queue.length; i++) {
  54. activatableEle = _this._queue[i];
  55. _this._active.push(activatableEle);
  56. activatableEle.classList.add(_this._css);
  57. }
  58. _this._queue.length = 0;
  59. }, this.activatedDelay);
  60. };
  61. // the user was pressing down, then just let up
  62. Activator.prototype.upAction = function (_ev, _activatableEle, _startCoord) {
  63. this._scheduleClear();
  64. };
  65. Activator.prototype._scheduleClear = function () {
  66. var _this = this;
  67. if (this._clearDefer) {
  68. return;
  69. }
  70. this._clearDefer = this.dom.write(function () {
  71. _this.clearState(true);
  72. _this._clearDefer = null;
  73. }, this.clearDelay);
  74. };
  75. Activator.prototype.unscheduleClear = function () {
  76. if (this._clearDefer) {
  77. this._clearDefer();
  78. this._clearDefer = null;
  79. }
  80. };
  81. // all states should return to normal
  82. Activator.prototype.clearState = function (animated) {
  83. var _this = this;
  84. if (!this.app.isEnabled()) {
  85. // the app is actively disabled, so don't bother deactivating anything.
  86. // this makes it easier on the GPU so it doesn't have to redraw any
  87. // buttons during a transition. This will retry in XX milliseconds.
  88. this.dom.write(function () {
  89. _this.clearState(animated);
  90. }, 600);
  91. }
  92. else {
  93. // not actively transitioning, good to deactivate any elements
  94. this.deactivate(animated);
  95. }
  96. };
  97. // remove the active class from all active elements
  98. Activator.prototype.deactivate = function (animated) {
  99. this._clearDeferred();
  100. this._queue.length = 0;
  101. var ele;
  102. for (var i = 0; i < this._active.length; i++) {
  103. ele = this._active[i];
  104. ele.style[this.dom.plt.Css.transition] = animated ? '' : 'none';
  105. ele.classList.remove(this._css);
  106. }
  107. this._active.length = 0;
  108. };
  109. Activator.prototype._clearDeferred = function () {
  110. // Clear any active deferral
  111. if (this._activeDefer) {
  112. this._activeDefer();
  113. this._activeDefer = null;
  114. }
  115. };
  116. return Activator;
  117. }());
  118. exports.Activator = Activator;
  119. var ADD_ACTIVATED_DEFERS = 80;
  120. var CLEAR_STATE_DEFERS = 80;
  121. });
  122. //# sourceMappingURL=activator.js.map