File

assets/angular/shared/loadable.component.ts

Description

Convenience class to wrap JQuery calls ...

Author: Shilo Banihit

Index

Properties
Methods

Constructor

constructor()

Methods

Public checkIfHasLoaded
checkIfHasLoaded()
Returns : void
hasLoaded
hasLoaded()
Returns : boolean
initTranslator
initTranslator(translationService: TranslationService)
Parameters :
Name Type Optional Description
translationService TranslationService
Returns : void
setLoading
setLoading(loading: boolean)
Parameters :
Name Type Optional Description
loading boolean
Returns : void
synchLoading
synchLoading()
Returns : void
translatorLoaded
translatorLoaded()
Returns : void

Properties

isLoading
isLoading: boolean
Type : boolean
spinnerElem
spinnerElem: string
Type : string
Default value : <i class="fa fa-spinner fa-pulse fa-1x fa-fw"></i>
translationService
translationService: any
Type : any
translatorReady
translatorReady: boolean
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();
    }
  }

}

results matching ""

    No results matching ""