UNPKG

ng2-http-loader

Version:

## ng2-http-loader [![Angular 2 Style Guide](https://mgechev.github.io/angular2-style-guide/images/badge.svg)](https://github.com/mgechev/angular2-style-guide)

74 lines (73 loc) 3.77 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require('@angular/core'); var ng2_http_loader_emitter_1 = require('./ng2-http-loader-emitter'); var Ng2HttpLoaderComponent = (function () { function Ng2HttpLoaderComponent(emitter) { var _this = this; this.emitter = emitter; this.progress = 0; this.totalRequests = 0; this.visibility = 'hidden'; this.thresHold = 60; this.anim1 = false; this.anim2 = false; if (!this.subscriber) { this.subscriber = this.emitter.getEmitter().subscribe(function (data) { _this.totalRequests = data.count; _this.startLoader(data.action); }); } } Ng2HttpLoaderComponent.prototype.ngOnInit = function () { this.color = this.color ? this.color : '#ff0000'; }; Ng2HttpLoaderComponent.prototype.startLoader = function (action) { if (action === 'init' && this.totalRequests === 1) { this.show(); this.progress = 60; } else if (action === 'end' && this.totalRequests === 0) { this.progress = 100; this.hide(); } }; Ng2HttpLoaderComponent.prototype.handleProgressPercentage = function (flag) { this.progress += 1; }; Ng2HttpLoaderComponent.prototype.show = function () { this.anim2 = false; this.anim1 = true; this.visibility = 'visible'; }; Ng2HttpLoaderComponent.prototype.hide = function () { var _this = this; this.anim1 = false; this.anim2 = true; setTimeout(function () { _this.visibility = 'hidden'; }, 4000); }; __decorate([ core_1.Input(), __metadata('design:type', String) ], Ng2HttpLoaderComponent.prototype, "color", void 0); Ng2HttpLoaderComponent = __decorate([ core_1.Component({ selector: 'ng2-http-loader', template: "\n <div class=\"ng2-http-loader-div\"\n [style.width]=\"progress + '%'\"\n [class.ng2-start-loader]=\"anim1\"\n [class.ng2-end-loader]=\"anim2\"\n [style.background]=\"color\"\n [style.box-shadow]=\"'0.5px 0.5px 2px 2px' + color\"\n [style.visibility]=\"visibility\"></div>\n ", styles: ["\n\n @keyframes ng2-anim1 {\n from { width: 0% }\n to { width: 60% }\n }\n @keyframes ng2-anim2 {\n from { width: 60% }\n to { width: 100% }\n }\n .ng2-http-loader-div{\n position: fixed;\n left: 0px;\n top: 0px;\n opacity: 0.5;\n z-index: 100000;\n }\n\n .ng2-start-loader{\n animation: ng2-anim1;\n animation-duration: 4s;\n }\n .ng2-end-loader{\n animation: ng2-anim2;\n animation-duration: 4s;\n }\n "] }), __metadata('design:paramtypes', [ng2_http_loader_emitter_1.Ng2HttpLoaderEmitter]) ], Ng2HttpLoaderComponent); return Ng2HttpLoaderComponent; }()); exports.Ng2HttpLoaderComponent = Ng2HttpLoaderComponent;