forked from orizens/ngx-infinite-scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
272 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"port": 8000, | ||
"files": ["./example**/*.{html,htm,css,js}"], | ||
"server": [ "./example", "./dist/bundles" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
let systemConfig = { | ||
//use typescript for compilation | ||
transpiler: 'typescript', | ||
//typescript compiler options | ||
typescriptOptions: { | ||
emitDecoratorMetadata: true | ||
}, | ||
//map tells the System loader where to look for things | ||
map: { | ||
app: './src', | ||
'@angular': 'https://unpkg.com/@angular', | ||
'@angular/common': 'https://unpkg.com/@angular/[email protected]', | ||
'@angular/core': 'https://unpkg.com/@angular/[email protected]', | ||
'@angular/compiler': 'https://unpkg.com/@angular/[email protected]', | ||
'@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/[email protected]', | ||
'@angular/platform-browser': 'https://unpkg.com/@angular/[email protected]', | ||
'rxjs': 'https://unpkg.com/[email protected]' | ||
// 'ngx-infinite-scroll': 'https://unpkg.com/ngx-infinite-scroll' | ||
}, | ||
//packages defines our app package | ||
packages: { | ||
app: { | ||
main: './main.ts', | ||
defaultExtension: 'ts' | ||
}, | ||
'@angular/core': { | ||
main: 'bundles/core.umd.js', | ||
defaultExtension: 'js' | ||
}, | ||
'@angular/compiler': { | ||
main: 'bundles/compiler.umd.js', | ||
defaultExtension: 'js' | ||
}, | ||
'@angular/common': { | ||
main: 'bundles/common.umd.js', | ||
defaultExtension: 'js' | ||
}, | ||
'@angular/platform-browser-dynamic': { | ||
main: 'bundles/platform-browser-dynamic.umd.js', | ||
defaultExtension: 'js' | ||
}, | ||
'@angular/platform-browser': { | ||
main: 'bundles/platform-browser.umd.js', | ||
defaultExtension: 'js' | ||
}, | ||
rxjs: { | ||
defaultExtension: 'js' | ||
}, | ||
'ngx-infinite-scroll': { | ||
main: '../ngx-infinite-scroll.umd.js', | ||
defaultExtension: 'js' | ||
} | ||
} | ||
}; | ||
System.config(systemConfig); | ||
module.exports = systemConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Angular Playground</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" /> | ||
<script src="https://unpkg.com/core-js/client/shim.min.js"></script> | ||
|
||
<script src="https://unpkg.com/[email protected]?main=browser"></script> | ||
<script src="https://unpkg.com/[email protected]"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/system.src.js"></script> | ||
<script src="https://code.angularjs.org/tools/typescript.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/chance/1.0.4/chance.min.js"></script> | ||
<script src="config.js"></script> | ||
<script> | ||
System.import('app') | ||
.catch(console.error.bind(console)); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<my-app> | ||
loading... | ||
</my-app> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// our root app component | ||
import { Component, ViewEncapsulation } from '@angular/core'; | ||
import * as config from '../config'; | ||
|
||
@Component({ | ||
selector: 'my-app', | ||
styleUrls: [ './style.css' ], | ||
template: ` | ||
<h1 class="title well"> | ||
{{ title }} | ||
<section> | ||
<small>items: {{sum}}, now triggering scroll: {{direction}}</small> | ||
</section> | ||
</h1> | ||
<div class="search-results" | ||
data-infinite-scroll | ||
debounce | ||
[infiniteScrollDistance]="scrollDistance" | ||
[infiniteScrollUpDistance]="scrollUpDistance" | ||
[infiniteScrollThrottle]="throttle" | ||
(scrolled)="onScrollDown()" | ||
(scrolledUp)="onUp()"> | ||
<p *ngFor="let i of array"> | ||
{{ i }} | ||
</p> | ||
</div> | ||
` | ||
}) | ||
export class AppComponent { | ||
array = []; | ||
sum = 100; | ||
throttle = 300; | ||
scrollDistance = 1; | ||
scrollUpDistance = 2; | ||
direction = ''; | ||
// title = 'This is Angular InfiniteScroll v' + systemConfig.map['ngx-infinite-scroll'].split('@')[1]; | ||
|
||
constructor() { | ||
this.appendItems(0, this.sum); | ||
// debugger | ||
// console.log(systemConfig); | ||
} | ||
|
||
addItems(startIndex, endIndex, _method) { | ||
for (let i = 0; i < this.sum; ++i) { | ||
this.array[_method]([i, ' ', this.generateWord()].join('')); | ||
} | ||
} | ||
|
||
appendItems(startIndex, endIndex) { | ||
this.addItems(startIndex, endIndex, 'push'); | ||
} | ||
|
||
prependItems(startIndex, endIndex) { | ||
this.addItems(startIndex, endIndex, 'unshift'); | ||
} | ||
|
||
onScrollDown (ev) { | ||
console.log('scrolled down!!', ev); | ||
|
||
// add another 20 items | ||
const start = this.sum; | ||
this.sum += 20; | ||
this.appendItems(start, this.sum); | ||
|
||
this.direction = 'down'; | ||
} | ||
|
||
onUp(ev) { | ||
console.log('scrolled up!', ev); | ||
const start = this.sum; | ||
this.sum += 20; | ||
this.prependItems(start, this.sum); | ||
|
||
this.direction = 'up'; | ||
} | ||
generateWord() { | ||
return chance.word(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// main entry point | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { InfiniteScrollModule } from 'ngx-infinite-scroll'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { AppComponent } from './app'; | ||
|
||
@NgModule({ | ||
declarations: [ AppComponent ], | ||
imports: [ BrowserModule, InfiniteScrollModule ], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule { } | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.search-results { | ||
height: 100%; | ||
} | ||
.title { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
background-color: rgba(0,0,0,.5); | ||
color: white; | ||
width: 100%; | ||
} | ||
.title small { | ||
color: #eaeaea; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function resolveContainerElement(selector: string | any, scrollWindow, defaultElement): any { | ||
const hasWindow = window && window.hasOwnProperty('document'); | ||
const containerIsString = selector && hasWindow && typeof(selector) === 'string'; | ||
let container = containerIsString | ||
? window.document.querySelector(selector) | ||
: selector; | ||
if (!selector) { | ||
container = scrollWindow ? window : defaultElement; | ||
} | ||
return container; | ||
} |
Oops, something went wrong.