Skip to content

Commit

Permalink
Merge pull request #18 from k3nsei/develop
Browse files Browse the repository at this point in the history
Release v.1.2.0-rc.3
  • Loading branch information
k3nsei authored Mar 30, 2017
2 parents 01bb988 + 821f6ab commit 9a35131
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions dist/in-viewport.module.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ModuleWithProviders } from "@angular/core";
import { InViewportService } from "./in-viewport.service";
export declare class InViewportModule {
private inViewportService;
static forRoot(): ModuleWithProviders;
constructor(inViewportService: InViewportService);
}
9 changes: 7 additions & 2 deletions dist/in-viewport.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/in-viewport.module.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/in-viewport.service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export declare class InViewportService {
protected findRegistryEntry(rootElement: Element): InViewportServiceRegistryObject;
addTarget(target: Element, rootElement?: Element): void;
removeTarget(target: Element, rootElement?: Element): void;
protected getRootElement(element: any): any;
}
12 changes: 7 additions & 5 deletions dist/in-viewport.service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/in-viewport.service.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-in-viewport",
"version": "1.2.0-rc.1",
"version": "1.2.0-rc.3",
"description": "Allows us to check if an element is within the browsers visual viewport",
"license": "MIT",
"authors": [
Expand Down
2 changes: 2 additions & 0 deletions src/in-viewport.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export class InViewportModule {
]
};
}

constructor(private inViewportService: InViewportService) {}
}
12 changes: 7 additions & 5 deletions src/in-viewport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ export class InViewportService {
}

protected findRegistryEntry(rootElement: Element) {
return this.registry.find((item) => item.rootElement === rootElement);
return this.registry.find((item) => item.rootElement === this.getRootElement(rootElement));
}

public addTarget(target: Element, rootElement?: Element): void {
let registryEntry = this.findRegistryEntry(rootElement);
if (!registryEntry) {
const registryEntryObserverOptions: any = {
root: this.getRootElement(rootElement),
threshold: Array(101).fill(void 0).map((item, i) => (i / 100))
};
if (rootElement) {
registryEntryObserverOptions.root = rootElement;
}
registryEntry = {
targets: [target],
rootElement,
rootElement: this.getRootElement(rootElement),
observer: new IntersectionObserver(
(entries: IntersectionObserverEntry[]) => this.onChanges(entries),
registryEntryObserverOptions
Expand Down Expand Up @@ -64,4 +62,8 @@ export class InViewportService {
}
}
}

protected getRootElement(element: any) {
return (element && element.nodeType === 1) ? element : null;
}
}

0 comments on commit 9a35131

Please sign in to comment.