-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
wow.service.ts
57 lines (47 loc) · 1.52 KB
/
wow.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { NgwWowConfig } from '../models/index';
import { WindowService } from './window.service';
/**
* Basic type to represent the `WOW` object from `WOW.js` library.
*/
export interface WOW {
/**
* Initializes the WOW.js library
* @param config the custom configuration to use
*/
init(config?: NgwWowConfig): void;
}
/**
* Type definition for the `WOW` object from `WOW.js` library.
*/
declare var WOW: {
new (config?: NgwWowConfig): WOW;
};
@Injectable()
export class NgwWowService {
// Window Object
private window: Window;
// Observable source that emits the box that is about to be shown by WOW
private itemRevealedSource: Subject<HTMLElement>;
// Observable users can subscribed to, in order to be notified when the box element is about to be shown by WOW
itemRevealed$: Observable<HTMLElement>;
constructor(windowService: WindowService) {
// Observable source
this.itemRevealedSource = new Subject<HTMLElement>();
// Observable stream
this.itemRevealed$ = this.itemRevealedSource.asObservable();
this.window = windowService.nativeWindow;
}
init(config?: NgwWowConfig): void {
// For Angular Universal support
if (this.window) {
let wowConfig = config || {};
// Set callback hook:
wowConfig.callback = () => this.itemRevealedSource.next();
// Initializes the library
new WOW(wowConfig).init();
}
}
}