Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx-slimscroll as a service #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
10,329 changes: 10,329 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@
"tslint": "~5.7.0",
"typescript": "~2.4.2",
"zone.js": "^0.8.14"
},
"dependencies": {
"classlist.js": "^1.1.20150312",
"web-animations-js": "^2.3.1"
}
}
54 changes: 54 additions & 0 deletions package.json.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "ngx-slimscroll",
"version": "3.5.2",
"license": "MIT",
"main": "./dist/bundles/ngx-slimscroll.umd.js",
"module": "./dist/ngx-slimscroll.es5.js",
"es2015": "./dist/ngx-slimscroll.js",
"typings": "./dist/ngx-slimscroll.d.ts",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:lib": "ng-packagr -p ng-package.json"
},
"devDependencies": {
"@angular/animations": "^5.0.0",
"@angular/cli": "1.5.4",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"bulma": "^0.6.1",
"codelyzer": "^4.0.1",
"core-js": "^2.4.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^1.6.0",
"node-sass": "^4.7.2",
"protractor": "~5.1.2",
"rxjs": "^5.5.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2",
"zone.js": "^0.8.14"
}
}
65 changes: 65 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,71 @@ <h1>What is Lorem Ipsum?</h1>
</p>
</div>
</div>

<div class="column is-6 is-offset-3">
<div class="scroll-window" id="service-scroll">
<h1><strong>This SlimScroll is generated using Service instead of Directive</strong></h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h1>Why do we use it?</h1>
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
<h1>Where does it come from?</h1>
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
<p>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p>
<h1>Where can I get some?</h1>
<p>
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
<h1>What is Lorem Ipsum?</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h1>Why do we use it?</h1>
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
</div>
</div>

<div class="column is-6 is-offset-3">
<div class="scroll-window" id="service-scroll2">
<h1><strong>This is also generated using Service but without initial animation</strong></h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h1>Why do we use it?</h1>
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
<h1>Where does it come from?</h1>
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
<p>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p>
<h1>Where can I get some?</h1>
<p>
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
<h1>What is Lorem Ipsum?</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h1>Why do we use it?</h1>
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
</div>
</div>

</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { AppComponent } from './app.component';
import { SlimScrollDirective } from './ngx-slimscroll/directives/slimscroll.directive';
import { SlimScrollService } from './ngx-slimscroll/services/slim-scroll.service';

describe(`Slimscroll Directive`, () => {
let comp: AppComponent;
Expand All @@ -19,7 +20,10 @@ describe(`Slimscroll Directive`, () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent, SlimScrollDirective ]
declarations: [ AppComponent, SlimScrollDirective ],
providers: [
SlimScrollService
]
}).compileComponents();
}));

Expand Down
58 changes: 56 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, EventEmitter, OnInit } from '@angular/core';
import { SlimScrollService } from './ngx-slimscroll/services/slim-scroll.service';
import { Component, EventEmitter, OnInit, ElementRef } from '@angular/core';
import { ISlimScrollOptions } from './ngx-slimscroll/classes/slimscroll-options.class';
import { SlimScrollEvent } from './ngx-slimscroll/classes/slimscroll-event.class';

Expand All @@ -9,9 +10,13 @@ import { SlimScrollEvent } from './ngx-slimscroll/classes/slimscroll-event.class
export class AppComponent implements OnInit {
options: ISlimScrollOptions;
secondOptions: ISlimScrollOptions;
thirdOptions: ISlimScrollOptions;
scrollEvents: EventEmitter<SlimScrollEvent>;

constructor() {
constructor(
private elementRef: ElementRef,
private slimScrollService: SlimScrollService
) {
this.options = {
barBackground: '#C9C9C9',
gridBackground: '#D9D9D9',
Expand All @@ -30,11 +35,21 @@ export class AppComponent implements OnInit {
gridMargin: '0'
};

this.thirdOptions = {
barBackground: '#000',
gridBackground: '#DDDDDD',
barBorderRadius: '50',
barWidth: '5',
gridWidth: '2'
};

this.scrollEvents = new EventEmitter<SlimScrollEvent>();
}

ngOnInit() {
this.play();

this.startServices();
}

play(): void {
Expand Down Expand Up @@ -88,4 +103,43 @@ export class AppComponent implements OnInit {
timeout(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(() => resolve(), ms));
}

startServices() {
const scrollElem = this.elementRef.nativeElement.querySelector('#service-scroll');
if (scrollElem != null) {
const slimscroll1 = this.slimScrollService.init(scrollElem, this.thirdOptions);
this.playService(slimscroll1);
}

const scrollElem2 = this.elementRef.nativeElement.querySelector('#service-scroll2');
if (scrollElem2 != null) {
const slimscroll2 = this.slimScrollService.init(scrollElem2, this.secondOptions);
}
}

playService(ssObj): void {
let event = null;

Promise.resolve()
.then(() => this.timeout(3000))
.then(() => {
event = new SlimScrollEvent({
type: 'scrollToBottom',
duration: 2000,
easing: 'inOutQuad'
});

this.slimScrollService.handleEvent(ssObj, event);
})
.then(() => this.timeout(3000))
.then(() => {
event = new SlimScrollEvent({
type: 'scrollToTop',
duration: 3000,
easing: 'outCubic'
});

this.slimScrollService.handleEvent(ssObj, event);
});
}
}
41 changes: 41 additions & 0 deletions src/app/ngx-slimscroll/classes/slimscroll-object.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Subscription } from 'rxjs/Subscription';
import { SlimScrollOptions } from './slimscroll-options.class';

export interface ISlimScrollObject {
options?: SlimScrollOptions;
el?: HTMLElement;
wrapper?: HTMLElement;
grid?: HTMLElement;
body?: HTMLElement;
bar?: HTMLElement;
pageY?: number;
top?: number;
dragging?: boolean;
mutationThrottleTimeout?: number;
mutationObserver?: MutationObserver;
lastTouchPositionY?: number;
visibleTimeout?: any;
interactionSubscriptions: Subscription;
}

export class SlimScrollObject implements ISlimScrollObject {
options?: SlimScrollOptions;
el?: HTMLElement;
wrapper?: HTMLElement;
grid?: HTMLElement;
body?: HTMLElement;
bar?: HTMLElement;
pageY?: number;
top?: number;
dragging?: boolean;
mutationThrottleTimeout?: number;
mutationObserver?: MutationObserver;
lastTouchPositionY?: number;
visibleTimeout?: any;
interactionSubscriptions: Subscription;

constructor(el: HTMLElement) {
this.el = el;
this.interactionSubscriptions = new Subscription();
}
}
10 changes: 9 additions & 1 deletion src/app/ngx-slimscroll/module/ngx-slimscroll.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { NgModule } from '@angular/core';
import { SlimScrollDirective } from '../directives/slimscroll.directive';
import { SlimScrollService } from './../services/slim-scroll.service';

export { SlimScrollService } from './../services/slim-scroll.service';

@NgModule({
declarations: [
SlimScrollDirective
],
providers: [
SlimScrollService
],
exports: [
SlimScrollDirective
]
})
export class NgSlimScrollModule { }
export class NgSlimScrollModule {
constructor(public slimScrollerService: SlimScrollService) { }
}
Loading