Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,118 changes: 1,062 additions & 1,056 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { ImgCacheService } from '../global';
import { ImgCacheProvider} from "../providers/img-cache/img-cache";

@Component({
templateUrl: 'app.html'
Expand All @@ -15,7 +15,7 @@ export class OfflineApp {

public rootPage = 'TabsPage';

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, imgCacheService: ImgCacheService) {
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, imgCacheService: ImgCacheProvider) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
Expand Down
30 changes: 17 additions & 13 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { File } from '@ionic-native/file';
import {NgModule, ErrorHandler} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {File} from '@ionic-native/file';

import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {IonicApp, IonicModule, IonicErrorHandler} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import { OfflineApp } from './app.component';
import { CacheImgModule } from '../global';
import {OfflineApp} from './app.component';
import {ComponentsModule} from "../components/components.module";
import {DirectivesModule} from "../directives/directives.module";
import {ImgCacheProvider} from '../providers/img-cache/img-cache';

@NgModule({
declarations: [
OfflineApp,
],
imports: [
BrowserModule,
ComponentsModule,
DirectivesModule,
IonicModule.forRoot(OfflineApp),

CacheImgModule.forRoot(),
],
bootstrap: [ IonicApp ],
bootstrap: [IonicApp],
entryComponents: [
OfflineApp
],
providers: [
File,
StatusBar,
SplashScreen,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
{provide: ErrorHandler, useClass: IonicErrorHandler},
ImgCacheProvider
]
})
export class AppModule {}
export class AppModule {
}
14 changes: 14 additions & 0 deletions src/components/components.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {NgModule} from '@angular/core';
import {CommonModule} from "@angular/common"
import {LazyImgComponent} from './lazy-img/lazy-img';
import {DirectivesModule} from "../directives/directives.module";

@NgModule({
declarations: [LazyImgComponent],
imports: [
DirectivesModule,
CommonModule],
exports: [LazyImgComponent]
})
export class ComponentsModule {
}
3 changes: 3 additions & 0 deletions src/components/lazy-img/lazy-img.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div text-center [ngClass]="{ 'placeholder': placeholderActive }">
<img op-lazy-img [source]="source" (loaded)="placeholderActive = false"/>
</div>
5 changes: 5 additions & 0 deletions src/components/lazy-img/lazy-img.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lazy-img {
op-lazy-img {
display: block;
}
}
20 changes: 20 additions & 0 deletions src/components/lazy-img/lazy-img.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Component, Input} from '@angular/core';

/**
* Generated class for the LazyImgComponent component.
*
* See https://angular.io/api/core/Component for more info on Angular
* Components.
*/
@Component({
selector: 'op-lazy-img',
templateUrl: 'lazy-img.html'
})
export class LazyImgComponent {

@Input()
public source: string;

public placeholderActive: boolean = true;

}
8 changes: 8 additions & 0 deletions src/directives/directives.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { LazyLoadDirective } from './lazy-load/lazy-load';
@NgModule({
declarations: [LazyLoadDirective],
imports: [],
exports: [LazyLoadDirective]
})
export class DirectivesModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
OnInit, OnDestroy, Renderer2
} from '@angular/core';

import { ImgCacheService } from './img-cache.service';

import { Subscription } from 'rxjs/Subscription';
import {Subscription} from 'rxjs/Subscription';
import {ImgCacheProvider} from "../../providers/img-cache/img-cache";

/**
* This directive is charge of cache the images and emit a loaded event
*/
* This directive is charge of cache the images and emit a loaded event
*/
@Directive({
selector: '[op-lazy-img]'
})
Expand All @@ -31,8 +31,9 @@ export class LazyLoadDirective implements OnInit, OnDestroy {
private cacheSubscription: Subscription;

constructor(public el: ElementRef,
public imgCacheService: ImgCacheService,
public renderer: Renderer2) { }
public imgCacheService: ImgCacheProvider,
public renderer: Renderer2) {
}

public ngOnInit(): void {
// get img element
Expand All @@ -50,10 +51,10 @@ export class LazyLoadDirective implements OnInit, OnDestroy {
// cache img and set the src to the img
this.cacheSubscription =
this.imgCacheService
.cache(this.source)
.subscribe((value) => {
this.renderer.setAttribute(nativeElement, 'src', value);
}, (e) => console.log(e));
.cache(this.source)
.subscribe((value) => {
this.renderer.setAttribute(nativeElement, 'src', value);
}, (e) => console.log(e));
}

public ngOnDestroy(): void {
Expand Down
35 changes: 0 additions & 35 deletions src/global/img-cache/img-cache.module.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/global/img-cache/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/global/img-cache/lazy-img.component.scss

This file was deleted.

22 changes: 0 additions & 22 deletions src/global/img-cache/lazy-img.component.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/global/index.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/pages/contact/contact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';

import { ContactPage } from './contact';
import { CacheImgModule } from '../../global';

@NgModule({
declarations: [ ContactPage ],
imports: [
CacheImgModule,

IonicPageModule.forChild(ContactPage),
],
exports: [ ContactPage ]
exports: [ ContactPage ],

})
export class ContactPageModule {}
4 changes: 1 addition & 3 deletions src/pages/contact/contact.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Component } from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';

import { ImgCacheService } from '../../global';

@IonicPage()
@Component({
selector: 'page-contact',
templateUrl: 'contact.html'
})
export class ContactPage {

constructor(public navCtrl: NavController, imgCacheService: ImgCacheService) { }
constructor(public navCtrl: NavController) { }

}
2 changes: 1 addition & 1 deletion src/pages/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p>in code we trust</p>
</ion-item>

<op-lazy-img [source]="'http://i.imgur.com/RgLjrEd.png'"></op-lazy-img>
<img op-lazy-img [source]="'http://i.imgur.com/RgLjrEd.png'" />

<ion-card-content>
<p>Images above have been cached. Try turning on the airplane mode and let Imgcache.js do the magic!</p>
Expand Down
18 changes: 11 additions & 7 deletions src/pages/home/home.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import {NgModule, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {IonicPageModule} from 'ionic-angular';
import {HomePage} from './home';

import { CacheImgModule } from '../../global';
import {ComponentsModule} from "../../components/components.module";
import {DirectivesModule} from "../../directives/directives.module";

@NgModule({
declarations: [
HomePage,
],
imports: [
CacheImgModule,
ComponentsModule,
DirectivesModule,

IonicPageModule.forChild(HomePage),
],
exports: [
HomePage
]
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HomePageModule {}
export class HomePageModule {
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { Injectable } from '@angular/core';
import { File } from '@ionic-native/file';
import { Platform } from 'ionic-angular';
import {Injectable} from '@angular/core';

import {File} from '@ionic-native/file';
import {Platform} from 'ionic-angular';

import ImgCache from '@chrisben/imgcache.js';

import { ReplaySubject } from 'rxjs/ReplaySubject';
import { map, take, flatMap, switchMapTo, tap } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import { bindCallback } from 'rxjs/observable/bindCallback';
import {ReplaySubject} from 'rxjs/ReplaySubject';
import {map, take, flatMap, switchMapTo, tap} from 'rxjs/operators';
import {Observable} from 'rxjs/Observable';
import {bindCallback} from 'rxjs/observable/bindCallback';

import {normalizeUrlIos} from "../../global/utils/url.util";

import { normalizeUrlIos } from '../utils';
/*
Generated class for the ImgCacheProvider provider.

/**
* This service is charged of provide the methods to cache the images
*/
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class ImgCacheService {
export class ImgCacheProvider {


private initNotifier$: ReplaySubject<string> = new ReplaySubject();

Expand Down