ngx-free-fullpage
Version:
ngx-free-fullpage is a free-for-profit angular library that gives you all the tools you need to implement a fullpage scroll effect. This library hasn't been developed in order to substitute the current ngx-fullpage, this library is an alternative for thos
272 lines (256 loc) • 11 kB
JavaScript
import { __decorate } from 'tslib';
import { ɵɵdefineInjectable, Injectable, ElementRef, Directive, NgModule, Input } from '@angular/core';
var NgxFullpageService = /** @class */ (function () {
function NgxFullpageService() {
var _this = this;
this.section = 0;
this.scrollHeight = 0;
this.goNext = function () { return (_this.scroll(1)); };
this.goPrev = function () { return (_this.scroll(-1)); };
this.goTo = function (section) { return (_this.scroll(section - _this.section)); };
this.adjustSection = function (section) { return _this.setNumberInRange(section, 0, _this.sectionsNumber - 1); };
}
NgxFullpageService.prototype.addWrapper = function (wrapper, section) {
if (this.wrapper)
throw new Error('There is already a wrapper defined');
this.wrapper = wrapper;
if (section > 0)
this.goTo(section);
};
NgxFullpageService.prototype.scroll = function (direction) {
this.sectionsNumber = (this.wrapper.nativeElement.scrollHeight / this.wrapper.nativeElement.offsetHeight);
this.scrollHeight += direction * this.wrapper.nativeElement.offsetHeight;
this.scrollHeight = this.adjustScroll(this.scrollHeight);
this.wrapper.nativeElement.scroll({ top: this.scrollHeight });
this.section = this.adjustSection(Math.round(this.scrollHeight / this.wrapper.nativeElement.offsetHeight));
};
NgxFullpageService.prototype.goLast = function () {
this.sectionsNumber = this.sectionsNumber || (this.wrapper.nativeElement.scrollHeight / this.wrapper.nativeElement.offsetHeight);
this.goTo(this.sectionsNumber - 1);
};
NgxFullpageService.prototype.adjustScroll = function (scroll) {
var maxScroll = (this.sectionsNumber - 1) * this.wrapper.nativeElement.offsetHeight;
return this.setNumberInRange(scroll, 0, maxScroll);
};
NgxFullpageService.prototype.setNumberInRange = function (n, min, max) {
return Math.min(Math.max(n, min), max);
};
NgxFullpageService.ɵprov = ɵɵdefineInjectable({ factory: function NgxFullpageService_Factory() { return new NgxFullpageService(); }, token: NgxFullpageService, providedIn: "root" });
NgxFullpageService = __decorate([
Injectable({
providedIn: 'root'
})
], NgxFullpageService);
return NgxFullpageService;
}());
var NgxFullpageGoToLastDirective = /** @class */ (function () {
function NgxFullpageGoToLastDirective(el, justFullpageService) {
var _this = this;
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (function () { return _this.justFullpageService.goLast(); });
}
NgxFullpageGoToLastDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
NgxFullpageGoToLastDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-last]'
})
], NgxFullpageGoToLastDirective);
return NgxFullpageGoToLastDirective;
}());
var NgxFullpageGoToLastModule = /** @class */ (function () {
function NgxFullpageGoToLastModule() {
}
NgxFullpageGoToLastModule = __decorate([
NgModule({
declarations: [NgxFullpageGoToLastDirective],
imports: [],
exports: [NgxFullpageGoToLastDirective]
})
], NgxFullpageGoToLastModule);
return NgxFullpageGoToLastModule;
}());
var NgxFullpageWrapperDirective = /** @class */ (function () {
function NgxFullpageWrapperDirective(element, justFullpageService) {
var _this = this;
this.element = element;
this.justFullpageService = justFullpageService;
this.section = 0;
this.delta = 0;
this.element.nativeElement.style['overflow'] = 'hidden';
this.element.nativeElement.style['scroll-behavior'] = "smooth";
this.element.nativeElement.onwheel = function (ev) { return _this.wheelHandler(ev); };
this.justFullpageService.addWrapper(element, this.section);
}
NgxFullpageWrapperDirective.prototype.wheelHandler = function (event) {
var _this = this;
this.delta += event.deltaY;
if (this.delta === event.deltaY)
setTimeout(function () {
var direction = Math.abs(_this.delta) / _this.delta;
_this.justFullpageService.scroll(direction);
setTimeout(function () { return _this.delta = 0; }, 150);
}, 50);
};
NgxFullpageWrapperDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
__decorate([
Input()
], NgxFullpageWrapperDirective.prototype, "section", void 0);
NgxFullpageWrapperDirective = __decorate([
Directive({
selector: '[ngx-fullpage-wrapper]',
providers: [NgxFullpageService]
})
], NgxFullpageWrapperDirective);
return NgxFullpageWrapperDirective;
}());
var NgxFullpageSectionDirective = /** @class */ (function () {
function NgxFullpageSectionDirective(element) {
this.element = element;
this.element.nativeElement.style.height = "100%";
this.element.nativeElement.style.width = "100%";
}
NgxFullpageSectionDirective.ctorParameters = function () { return [
{ type: ElementRef }
]; };
NgxFullpageSectionDirective = __decorate([
Directive({
selector: '[ngx-fullpage-section]'
})
], NgxFullpageSectionDirective);
return NgxFullpageSectionDirective;
}());
var NgxFullpageModule = /** @class */ (function () {
function NgxFullpageModule() {
}
NgxFullpageModule = __decorate([
NgModule({
declarations: [NgxFullpageWrapperDirective, NgxFullpageSectionDirective],
imports: [],
exports: [NgxFullpageWrapperDirective, NgxFullpageSectionDirective],
})
], NgxFullpageModule);
return NgxFullpageModule;
}());
var NgxFullpageNextButtonDirective = /** @class */ (function () {
function NgxFullpageNextButtonDirective(el, justFullpageService) {
var _this = this;
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = function (_ev) { return _this.justFullpageService.goNext(); };
}
NgxFullpageNextButtonDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
NgxFullpageNextButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-next-button]'
})
], NgxFullpageNextButtonDirective);
return NgxFullpageNextButtonDirective;
}());
var NgxFullpagePrevButtonDirective = /** @class */ (function () {
function NgxFullpagePrevButtonDirective(el, justFullpageService) {
var _this = this;
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = function (_ev) { return _this.justFullpageService.goPrev(); };
}
NgxFullpagePrevButtonDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
NgxFullpagePrevButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-prev-button]'
})
], NgxFullpagePrevButtonDirective);
return NgxFullpagePrevButtonDirective;
}());
var NgxFullpageNextButtonModule = /** @class */ (function () {
function NgxFullpageNextButtonModule() {
}
NgxFullpageNextButtonModule = __decorate([
NgModule({
declarations: [NgxFullpageNextButtonDirective, NgxFullpagePrevButtonDirective],
imports: [],
exports: [NgxFullpageNextButtonDirective, NgxFullpagePrevButtonDirective],
})
], NgxFullpageNextButtonModule);
return NgxFullpageNextButtonModule;
}());
var NgxFullpageToFirstButtonDirective = /** @class */ (function () {
function NgxFullpageToFirstButtonDirective(el, justFullpageService) {
var _this = this;
this.el = el;
this.justFullpageService = justFullpageService;
this.el.nativeElement.onclick = (function () { return _this.justFullpageService.goTo(0); });
}
NgxFullpageToFirstButtonDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
NgxFullpageToFirstButtonDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-first]'
})
], NgxFullpageToFirstButtonDirective);
return NgxFullpageToFirstButtonDirective;
}());
var NgxFullpageToFirstButtonModule = /** @class */ (function () {
function NgxFullpageToFirstButtonModule() {
}
NgxFullpageToFirstButtonModule = __decorate([
NgModule({
declarations: [NgxFullpageToFirstButtonDirective],
imports: [],
exports: [NgxFullpageToFirstButtonDirective],
})
], NgxFullpageToFirstButtonModule);
return NgxFullpageToFirstButtonModule;
}());
var NgxFullpageGoToSectionDirective = /** @class */ (function () {
function NgxFullpageGoToSectionDirective(element, justFullpageService) {
var _this = this;
this.element = element;
this.justFullpageService = justFullpageService;
this.element.nativeElement.onclick = function () { return _this.justFullpageService.goTo(_this.section); };
}
NgxFullpageGoToSectionDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: NgxFullpageService }
]; };
__decorate([
Input('ngx-fullpage-go-to-section')
], NgxFullpageGoToSectionDirective.prototype, "section", void 0);
NgxFullpageGoToSectionDirective = __decorate([
Directive({
selector: '[ngx-fullpage-go-to-section]'
})
], NgxFullpageGoToSectionDirective);
return NgxFullpageGoToSectionDirective;
}());
var NgxFullpageGoToSectionModule = /** @class */ (function () {
function NgxFullpageGoToSectionModule() {
}
NgxFullpageGoToSectionModule = __decorate([
NgModule({
declarations: [NgxFullpageGoToSectionDirective],
imports: [],
exports: [NgxFullpageGoToSectionDirective],
})
], NgxFullpageGoToSectionModule);
return NgxFullpageGoToSectionModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { NgxFullpageGoToLastModule, NgxFullpageGoToSectionModule, NgxFullpageModule, NgxFullpageNextButtonModule, NgxFullpageService, NgxFullpageToFirstButtonModule, NgxFullpageGoToLastDirective as ɵa, NgxFullpageWrapperDirective as ɵb, NgxFullpageSectionDirective as ɵc, NgxFullpageNextButtonDirective as ɵd, NgxFullpagePrevButtonDirective as ɵe, NgxFullpageToFirstButtonDirective as ɵf, NgxFullpageGoToSectionDirective as ɵg };
//# sourceMappingURL=ngx-free-fullpage.js.map