baVard work still in progress

This commit is contained in:
smartapant 2016-05-04 16:43:04 +03:00
parent cb5739711c
commit a1a8875225
4 changed files with 20 additions and 14 deletions

View file

@ -1,8 +1,11 @@
import {Component, ViewEncapsulation, Input} from 'angular2/core';
import {BaCardBlur} from './baCardBlur.directive';
@Component({
selector: 'ba-card',
styles: [require('./baCard.scss')],
directives: [BaCardBlur],
template: require('./baCard.html'),
encapsulation: ViewEncapsulation.None
})

View file

@ -1,8 +1,8 @@
<div class="card {{cardType}} {{baCardClass || ''}}" zoom-in ba-panel-blur>
<div class="card {{cardType}} card-blur {{baCardClass || ''}}" zoom-in baCardBlur>
<div *ngIf="title" class="card-header clearfix">
<h3 class="card-title">{{title}}</h3>
</div>
<div class="card-body">
<ng-content></ng-content>
</div>
</div>
</div>

View file

@ -22,15 +22,15 @@ export class BaCardBlur {
}
private _getBodyImageSizesOnBgLoad():void {
this._baCardBlurHelper.bodyBgLoad().then(function() {
this._baCardBlurHelper.bodyBgLoad().subscribe(() => {
this._bodyBgSize = this._baCardBlurHelper.getBodyBgImageSizes();
});
}
private _recalculateCardStylesOnBgLoad():void {
this._baCardBlurHelper.bodyBgLoad().then(() => {
setTimeout(this._recalculateCardStyle);
});
this._baCardBlurHelper.bodyBgLoad().subscribe((event) => {
setTimeout(this._recalculateCardStyle.bind(this));
})
}
private _recalculateCardStyle():void {

View file

@ -1,15 +1,15 @@
import {Injectable} from 'angular2/core'
import {BgMetrics} from './bgMetrics';
import {Subject} from 'rxjs/Subject';
@Injectable()
export class BaCardBlurHelper {
private image:HTMLImageElement;
private imageLoadDeferred = Promise.defer(); //TODO: Promises or Observables refactor
private imageLoadSubject:Subject<void>;
constructor() {
this._genBgImage();
this._setImageLoadResolves()
this._genImageLoadSubject();
}
private _genBgImage():void {
@ -18,17 +18,20 @@ export class BaCardBlurHelper {
this.image.src = computedStyle.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2');
}
private _setImageLoadResolves():void {
private _genImageLoadSubject():void {
this.imageLoadSubject = new Subject<void>();
this.image.onerror = () => {
this.imageLoadDeferred.reject();
this.imageLoadSubject.error();
this.imageLoadSubject.complete();
};
this.image.onload = () => {
this.imageLoadDeferred.resolve();
this.imageLoadSubject.next(null);
this.imageLoadSubject.complete();
};
}
public bodyBgLoad():Promise {
return this.imageLoadDeferred.promise;
public bodyBgLoad():Subject<void> {
return this.imageLoadSubject;
}
public getBodyBgImageSizes():BgMetrics {