2017-04-23 16:10:32 +03:00
|
|
|
import 'perfect-scrollbar/dist/css/perfect-scrollbar.css';
|
|
|
|
|
2017-09-21 18:03:31 +03:00
|
|
|
import { Directive, ElementRef, OnDestroy, OnInit } from '@angular/core';
|
2017-04-23 16:10:32 +03:00
|
|
|
import * as PS from 'perfect-scrollbar';
|
|
|
|
|
2017-09-21 18:03:31 +03:00
|
|
|
import { OptionsService } from '../../../services/options.service';
|
|
|
|
|
2017-04-23 16:10:32 +03:00
|
|
|
@Directive({
|
2017-09-21 18:03:31 +03:00
|
|
|
selector: '[perfect-scrollbar]',
|
2017-04-23 16:10:32 +03:00
|
|
|
})
|
|
|
|
export class PerfectScrollbar implements OnInit, OnDestroy {
|
|
|
|
$element: any;
|
|
|
|
subscription: any;
|
2017-09-21 18:03:31 +03:00
|
|
|
enabled: boolean = true;
|
2017-04-23 16:10:32 +03:00
|
|
|
|
2017-09-21 18:03:31 +03:00
|
|
|
constructor(elementRef: ElementRef, optionsService: OptionsService) {
|
2017-04-23 16:10:32 +03:00
|
|
|
this.$element = elementRef.nativeElement;
|
2017-09-21 18:03:31 +03:00
|
|
|
this.enabled = !optionsService.options.nativeScrollbars;
|
2017-04-23 16:10:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
2017-09-21 18:03:31 +03:00
|
|
|
if (!this.enabled) return;
|
2017-04-23 16:10:32 +03:00
|
|
|
PS.update(this.$element);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-09-21 18:03:31 +03:00
|
|
|
if (!this.enabled) return;
|
|
|
|
requestAnimationFrame(() =>
|
|
|
|
PS.initialize(this.$element, {
|
|
|
|
wheelSpeed: 2,
|
|
|
|
handlers: [
|
|
|
|
'click-rail',
|
|
|
|
'drag-scrollbar',
|
|
|
|
'keyboard',
|
|
|
|
'wheel',
|
|
|
|
'touch',
|
|
|
|
],
|
|
|
|
wheelPropagation: true,
|
|
|
|
minScrollbarLength: 20,
|
|
|
|
suppressScrollX: true,
|
|
|
|
} as any),
|
|
|
|
);
|
2017-04-23 16:10:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2017-09-21 18:03:31 +03:00
|
|
|
if (!this.enabled) return;
|
2017-04-23 16:10:32 +03:00
|
|
|
PS.destroy(this.$element);
|
|
|
|
}
|
|
|
|
}
|