1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __metadata = (this && this.__metadata) || function (k, v) {
|
8 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9 | };
|
10 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
11 | return function (target, key) { decorator(target, key, paramIndex); }
|
12 | };
|
13 | (function (dependencies, factory) {
|
14 | if (typeof module === 'object' && typeof module.exports === 'object') {
|
15 | var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
16 | }
|
17 | else if (typeof define === 'function' && define.amd) {
|
18 | define(dependencies, factory);
|
19 | }
|
20 | })(["require", "exports", "@angular/core"], function (require, exports) {
|
21 | "use strict";
|
22 | var core_1 = require("@angular/core");
|
23 | var CountUpDirective = (function () {
|
24 | function CountUpDirective(el) {
|
25 | this.el = el;
|
26 | }
|
27 | Object.defineProperty(CountUpDirective.prototype, "endVal", {
|
28 | get: function () {
|
29 | return this._endVal;
|
30 | },
|
31 | set: function (value) {
|
32 | this._endVal = value;
|
33 | if (isNaN(value)) {
|
34 | return;
|
35 | }
|
36 | if (!this._countUp) {
|
37 | return;
|
38 | }
|
39 | this._countUp.update(value);
|
40 | },
|
41 | enumerable: true,
|
42 | configurable: true
|
43 | });
|
44 | CountUpDirective.prototype.ngOnInit = function () {
|
45 | this._countUp = this.createCountUp(this.startVal, this.endVal, this.decimals, this.duration);
|
46 | this.animate();
|
47 | };
|
48 | CountUpDirective.prototype.onClick = function () {
|
49 | if (this.reanimateOnClick) {
|
50 | this.animate();
|
51 | }
|
52 | };
|
53 | CountUpDirective.prototype.createCountUp = function (sta, end, dec, dur) {
|
54 | sta = sta || 0;
|
55 | if (isNaN(sta))
|
56 | sta = Number(sta.match(/[\d\-\.]+/g).join(''));
|
57 | end = end || 0;
|
58 | if (isNaN(end))
|
59 | end = Number(end.match(/[\d\-\.]+/g).join(''));
|
60 | dur = Number(dur) || 2;
|
61 | dec = Number(dec) || 0;
|
62 | var countUp = new CountUp(this.el.nativeElement, sta, end, dec, dur, this.options);
|
63 | if (end > 999) {
|
64 | countUp = new CountUp(this.el.nativeElement, sta, end - 100, dec, dur / 2, this.options);
|
65 | }
|
66 | return countUp;
|
67 | };
|
68 | CountUpDirective.prototype.animate = function () {
|
69 | var _this = this;
|
70 | this._countUp.reset();
|
71 | if (this.endVal > 999) {
|
72 | this._countUp.start(function () { return _this._countUp.update(_this.endVal); });
|
73 | }
|
74 | else {
|
75 | this._countUp.start();
|
76 | }
|
77 | };
|
78 | return CountUpDirective;
|
79 | }());
|
80 | __decorate([
|
81 | core_1.Input('countUp'),
|
82 | __metadata("design:type", Object)
|
83 | ], CountUpDirective.prototype, "options", void 0);
|
84 | __decorate([
|
85 | core_1.Input(),
|
86 | __metadata("design:type", Number)
|
87 | ], CountUpDirective.prototype, "startVal", void 0);
|
88 | __decorate([
|
89 | core_1.Input(),
|
90 | __metadata("design:type", Number),
|
91 | __metadata("design:paramtypes", [])
|
92 | ], CountUpDirective.prototype, "endVal", null);
|
93 | __decorate([
|
94 | core_1.Input(),
|
95 | __metadata("design:type", Number)
|
96 | ], CountUpDirective.prototype, "duration", void 0);
|
97 | __decorate([
|
98 | core_1.Input(),
|
99 | __metadata("design:type", Number)
|
100 | ], CountUpDirective.prototype, "decimals", void 0);
|
101 | __decorate([
|
102 | core_1.Input(),
|
103 | __metadata("design:type", Boolean)
|
104 | ], CountUpDirective.prototype, "reanimateOnClick", void 0);
|
105 | __decorate([
|
106 | core_1.HostListener('click'),
|
107 | __metadata("design:type", Function),
|
108 | __metadata("design:paramtypes", []),
|
109 | __metadata("design:returntype", void 0)
|
110 | ], CountUpDirective.prototype, "onClick", null);
|
111 | CountUpDirective = __decorate([
|
112 | core_1.Directive({
|
113 | selector: '[countUp]'
|
114 | }),
|
115 | __param(0, core_1.Inject(core_1.ElementRef)),
|
116 | __metadata("design:paramtypes", [core_1.ElementRef])
|
117 | ], CountUpDirective);
|
118 | exports.CountUpDirective = CountUpDirective;
|
119 | var CountUpModule = (function () {
|
120 | function CountUpModule() {
|
121 | }
|
122 | return CountUpModule;
|
123 | }());
|
124 | CountUpModule = __decorate([
|
125 | core_1.NgModule({
|
126 | declarations: [CountUpDirective],
|
127 | exports: [CountUpDirective]
|
128 | }),
|
129 | __metadata("design:paramtypes", [])
|
130 | ], CountUpModule);
|
131 | exports.CountUpModule = CountUpModule;
|
132 | });
|