From 5d0566dc96c176164c4bdb025641ab2fb4ed94ae Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Tue, 18 Apr 2017 16:42:35 -0400 Subject: [PATCH] feat(): add ability to customize spinner closes #38 --- src/components/img-loader.ts | 12 +++++++++++- src/providers/image-loader-config.ts | 20 ++++++++++++++++++++ src/providers/image-loader.ts | 22 +++++++++++++--------- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/components/img-loader.ts b/src/components/img-loader.ts index 00a8c29..c88255d 100644 --- a/src/components/img-loader.ts +++ b/src/components/img-loader.ts @@ -4,7 +4,7 @@ import { ImageLoaderConfig } from '../providers/image-loader-config'; @Component({ selector: 'img-loader', - template: '', + template: '', styles: ['ion-spinner { float: none; margin-left: auto; margin-right: auto; display: block; }'] }) export class ImgLoader implements OnInit { @@ -89,6 +89,16 @@ export class ImgLoader implements OnInit { */ @Input() backgroundRepeat: string = this._config.backgroundRepeat; + /** + * Name of the spinner + */ + @Input() spinnerName: string = this._config.spinnerName; + + /** + * Color of the spinner + */ + @Input() spinnerColor: string = this._config.spinnerColor; + /** * Notify on image load.. */ diff --git a/src/providers/image-loader-config.ts b/src/providers/image-loader-config.ts index bc0db57..7637185 100644 --- a/src/providers/image-loader-config.ts +++ b/src/providers/image-loader-config.ts @@ -31,6 +31,10 @@ export class ImageLoaderConfig { imageReturnType: string = 'uri'; + spinnerName: string; + + spinnerColor: string; + private _cacheDirectoryName: string = 'image-loader-cache'; set cacheDirectoryName(name: string) { @@ -162,4 +166,20 @@ export class ImageLoaderConfig { this.imageReturnType = imageReturnType; } + /** + * Set the default spinnern ame + * @param name + */ + setSpinnerName(name: string): void { + this.spinnerName = name; + } + + /** + * Set the default spinner color + * @param color + */ + setSpinnerColor(color: string): void { + this.spinnerColor = color; + } + } diff --git a/src/providers/image-loader.ts b/src/providers/image-loader.ts index b8e9a3e..20baa73 100644 --- a/src/providers/image-loader.ts +++ b/src/providers/image-loader.ts @@ -68,15 +68,19 @@ export class ImageLoader { private transfer: Transfer, private platform: Platform ) { - if (window.location.protocol === 'http:' || window.location.protocol === 'https:') { - // we are running on a browser, or using livereload - // plugin will not function in this case - this.isInit = true; - this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.'); - } else { - this.platform.ready() - .then(() => this.initCache()); - } + platform.ready().then(() => { + + if (( File).installed()) { + this.platform.ready() + .then(() => this.initCache()); + } else { + // we are running on a browser, or using livereload + // plugin will not function in this case + this.isInit = true; + this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.'); + } + + }); } /**