diff --git a/src/app/theme/components/baCard/baCardBlur.directive.ts b/src/app/theme/components/baCard/baCardBlur.directive.ts index d70ac10f..7b0693a1 100644 --- a/src/app/theme/components/baCard/baCardBlur.directive.ts +++ b/src/app/theme/components/baCard/baCardBlur.directive.ts @@ -16,6 +16,7 @@ export class BaCardBlur { constructor(private _baConfig:BaThemeConfigProvider, private _baCardBlurHelper:BaCardBlurHelper, private _el:ElementRef) { if (this._isEnabled()) { + this._baCardBlurHelper.init(); this._getBodyImageSizesOnBgLoad(); this._recalculateCardStylesOnBgLoad(); diff --git a/src/app/theme/components/baCard/baCardBlurHelper.service.ts b/src/app/theme/components/baCard/baCardBlurHelper.service.ts index efed5e32..035a9c59 100644 --- a/src/app/theme/components/baCard/baCardBlurHelper.service.ts +++ b/src/app/theme/components/baCard/baCardBlurHelper.service.ts @@ -7,29 +7,12 @@ export class BaCardBlurHelper { private image:HTMLImageElement; private imageLoadSubject:Subject; - constructor() { + + public init() { this._genBgImage(); this._genImageLoadSubject(); } - private _genBgImage():void { - this.image = new Image(); - let computedStyle = getComputedStyle(document.body, ':before'); - this.image.src = computedStyle.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'); - } - - private _genImageLoadSubject():void { - this.imageLoadSubject = new Subject(); - this.image.onerror = () => { - this.imageLoadSubject.error(); - this.imageLoadSubject.complete(); - }; - this.image.onload = () => { - this.imageLoadSubject.next(null); - this.imageLoadSubject.complete(); - }; - } - public bodyBgLoad():Subject { return this.imageLoadSubject; } @@ -51,4 +34,22 @@ export class BaCardBlurHelper { } return { width: finalWidth, height: finalHeight, positionX: (elemW - finalWidth)/2, positionY: (elemH - finalHeight)/2}; } + + private _genBgImage():void { + this.image = new Image(); + let computedStyle = getComputedStyle(document.body, ':before'); + this.image.src = computedStyle.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'); + } + + private _genImageLoadSubject():void { + this.imageLoadSubject = new Subject(); + this.image.onerror = () => { + this.imageLoadSubject.error(); + this.imageLoadSubject.complete(); + }; + this.image.onload = () => { + this.imageLoadSubject.next(null); + this.imageLoadSubject.complete(); + }; + } }