UI for Zipcoin Blue

click-block.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Directive, ElementRef, Inject, Renderer, forwardRef } from '@angular/core';
  2. import { App } from '../app/app';
  3. import { Config } from '../../config/config';
  4. import { Platform } from '../../platform/platform';
  5. /**
  6. * @hidden
  7. */
  8. var ClickBlock = (function () {
  9. function ClickBlock(app, config, plt, elementRef, renderer) {
  10. this.plt = plt;
  11. this.elementRef = elementRef;
  12. this.renderer = renderer;
  13. this._showing = false;
  14. app._clickBlock = this;
  15. var enabled = this.isEnabled = config.getBoolean('clickBlock', true);
  16. if (enabled) {
  17. this._setElementClass('click-block-enabled', true);
  18. }
  19. }
  20. ClickBlock.prototype.activate = function (shouldShow, expire, minDuration) {
  21. if (expire === void 0) { expire = 100; }
  22. if (minDuration === void 0) { minDuration = 0; }
  23. if (this.isEnabled) {
  24. this.plt.cancelTimeout(this._tmr);
  25. if (shouldShow) {
  26. // remember when we started the click block
  27. this._start = Date.now();
  28. // figure out the minimum time it should be showing until
  29. // this is useful for transitions that are less than 300ms
  30. this._minEnd = this._start + (minDuration || 0);
  31. this._activate(true);
  32. }
  33. this._tmr = this.plt.timeout(this._activate.bind(this, false), expire);
  34. }
  35. };
  36. /** @internal */
  37. ClickBlock.prototype._activate = function (shouldShow) {
  38. if (this._showing !== shouldShow) {
  39. if (!shouldShow) {
  40. // check if it was enabled before the minimum duration
  41. // this is useful for transitions that are less than 300ms
  42. var now = Date.now();
  43. if (now < this._minEnd) {
  44. this._tmr = this.plt.timeout(this._activate.bind(this, false), this._minEnd - now);
  45. return;
  46. }
  47. }
  48. this._setElementClass('click-block-active', shouldShow);
  49. this._showing = shouldShow;
  50. }
  51. };
  52. ClickBlock.prototype._setElementClass = function (className, add) {
  53. this.renderer.setElementClass(this.elementRef.nativeElement, className, add);
  54. };
  55. ClickBlock.decorators = [
  56. { type: Directive, args: [{
  57. selector: '.click-block'
  58. },] },
  59. ];
  60. /** @nocollapse */
  61. ClickBlock.ctorParameters = function () { return [
  62. { type: App, decorators: [{ type: Inject, args: [forwardRef(function () { return App; }),] },] },
  63. { type: Config, },
  64. { type: Platform, },
  65. { type: ElementRef, },
  66. { type: Renderer, },
  67. ]; };
  68. return ClickBlock;
  69. }());
  70. export { ClickBlock };
  71. //# sourceMappingURL=click-block.js.map