bacard directive fix

This commit is contained in:
nixa 2016-05-16 17:46:49 +03:00
parent 5fa1b335c6
commit cd6290219f
2 changed files with 21 additions and 19 deletions

View file

@ -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();

View file

@ -7,29 +7,12 @@ export class BaCardBlurHelper {
private image:HTMLImageElement;
private imageLoadSubject:Subject<void>;
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<void>();
this.image.onerror = () => {
this.imageLoadSubject.error();
this.imageLoadSubject.complete();
};
this.image.onload = () => {
this.imageLoadSubject.next(null);
this.imageLoadSubject.complete();
};
}
public bodyBgLoad():Subject<void> {
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<void>();
this.image.onerror = () => {
this.imageLoadSubject.error();
this.imageLoadSubject.complete();
};
this.image.onload = () => {
this.imageLoadSubject.next(null);
this.imageLoadSubject.complete();
};
}
}