assets/angular/shared/loadable.component.ts
Convenience class to wrap JQuery calls ...
Author: Shilo Banihit
Properties |
Methods |
constructor()
|
Public checkIfHasLoaded |
checkIfHasLoaded()
|
Returns :
void
|
hasLoaded |
hasLoaded()
|
Returns :
boolean
|
initTranslator | ||||||||
initTranslator(translationService: TranslationService)
|
||||||||
Parameters :
Returns :
void
|
setLoading | ||||||||
setLoading(loading: boolean)
|
||||||||
Parameters :
Returns :
void
|
synchLoading |
synchLoading()
|
Returns :
void
|
translatorLoaded |
translatorLoaded()
|
Returns :
void
|
isLoading |
isLoading:
|
Type : boolean
|
spinnerElem |
spinnerElem:
|
Type : string
|
Default value : <i class="fa fa-spinner fa-pulse fa-1x fa-fw"></i>
|
translationService |
translationService:
|
Type : any
|
translatorReady |
translatorReady:
|
Type : boolean
|
import { TranslationService } from './translation-service';
declare var jQuery: any;
/**
* Convenience class to wrap JQuery calls ...
*
* Author: <a href='https://github.com/shilob' target='_blank'>Shilo Banihit</a>
*
*/
export class LoadableComponent {
isLoading: boolean;
translatorReady: boolean;
translationService: any;
spinnerElem: string = `<i class="fa fa-spinner fa-pulse fa-1x fa-fw"></i>`;
constructor() {
this.isLoading = true;
this.synchLoading();
}
initTranslator(translationService: TranslationService) {
this.translationService = translationService;
translationService.isReady((tService:any) => {
this.translatorReady = true;
});
}
translatorLoaded() {
this.translatorReady = true;
this.checkIfHasLoaded();
}
public checkIfHasLoaded() {
if (this.hasLoaded()) {
this.setLoading(false);
}
}
hasLoaded() {
return this.isLoading && (this.translationService ? this.translatorReady : true);
}
setLoading(loading: boolean=true) {
this.isLoading = loading;
this.synchLoading();
}
synchLoading() {
if (this.isLoading) {
jQuery("#loading").show();
} else {
jQuery("#loading").hide();
}
}
}