ng-imgcache
Version:
Angular 2+ module to cache images for offline use.
59 lines (58 loc) • 1.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var img_cache_service_1 = require("./img-cache.service");
var ImgCacheDirective = (function () {
function ImgCacheDirective(imgCache, el, renderer) {
this.imgCache = imgCache;
this.el = el;
this.renderer = renderer;
}
Object.defineProperty(ImgCacheDirective.prototype, "src", {
set: function (val) {
var _this = this;
if (val) {
this.imgCache
.fetchFromCache(val)
.then(function (cached) {
_this.renderer.setAttribute(_this.el.nativeElement, 'src', cached);
});
}
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(ImgCacheDirective.prototype, "bgUrl", {
set: function (val) {
var _this = this;
if (val) {
this.imgCache
.fetchFromCache(val)
.then(function (cached) {
_this.renderer.setStyle(_this.el.nativeElement, 'background-image', "url('" + cached + "')");
});
}
},
enumerable: true,
configurable: true
});
;
return ImgCacheDirective;
}());
ImgCacheDirective.decorators = [
{ type: core_1.Directive, args: [{
selector: '[img-cache]'
},] },
];
/** @nocollapse */
ImgCacheDirective.ctorParameters = function () { return [
{ type: img_cache_service_1.ImgCacheService, },
{ type: core_1.ElementRef, },
{ type: core_1.Renderer2, },
]; };
ImgCacheDirective.propDecorators = {
'src': [{ type: core_1.Input, args: ['img-cache-src',] },],
'bgUrl': [{ type: core_1.Input, args: ['img-cache-bg-url',] },],
};
exports.ImgCacheDirective = ImgCacheDirective;
;