123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
-
- export default class Pointer {
-
- constructor( Reveal ) {
-
- this.Reveal = Reveal;
-
-
- this.lastMouseWheelStep = 0;
-
-
- this.cursorHidden = false;
-
-
- this.cursorInactiveTimeout = 0;
-
- this.onDocumentCursorActive = this.onDocumentCursorActive.bind( this );
- this.onDocumentMouseScroll = this.onDocumentMouseScroll.bind( this );
-
- }
-
-
-
- configure( config, oldConfig ) {
-
- if( config.mouseWheel ) {
- document.addEventListener( 'DOMMouseScroll', this.onDocumentMouseScroll, false );
- document.addEventListener( 'mousewheel', this.onDocumentMouseScroll, false );
- }
- else {
- document.removeEventListener( 'DOMMouseScroll', this.onDocumentMouseScroll, false );
- document.removeEventListener( 'mousewheel', this.onDocumentMouseScroll, false );
- }
-
-
- if( config.hideInactiveCursor ) {
- document.addEventListener( 'mousemove', this.onDocumentCursorActive, false );
- document.addEventListener( 'mousedown', this.onDocumentCursorActive, false );
- }
- else {
- this.showCursor();
-
- document.removeEventListener( 'mousemove', this.onDocumentCursorActive, false );
- document.removeEventListener( 'mousedown', this.onDocumentCursorActive, false );
- }
-
- }
-
-
-
- showCursor() {
-
- if( this.cursorHidden ) {
- this.cursorHidden = false;
- this.Reveal.getRevealElement().style.cursor = '';
- }
-
- }
-
-
-
- hideCursor() {
-
- if( this.cursorHidden === false ) {
- this.cursorHidden = true;
- this.Reveal.getRevealElement().style.cursor = 'none';
- }
-
- }
-
- destroy() {
-
- this.showCursor();
-
- document.removeEventListener( 'DOMMouseScroll', this.onDocumentMouseScroll, false );
- document.removeEventListener( 'mousewheel', this.onDocumentMouseScroll, false );
- document.removeEventListener( 'mousemove', this.onDocumentCursorActive, false );
- document.removeEventListener( 'mousedown', this.onDocumentCursorActive, false );
-
- }
-
-
-
- onDocumentCursorActive( event ) {
-
- this.showCursor();
-
- clearTimeout( this.cursorInactiveTimeout );
-
- this.cursorInactiveTimeout = setTimeout( this.hideCursor.bind( this ), this.Reveal.getConfig().hideCursorTime );
-
- }
-
-
-
- onDocumentMouseScroll( event ) {
-
- if( Date.now() - this.lastMouseWheelStep > 1000 ) {
-
- this.lastMouseWheelStep = Date.now();
-
- let delta = event.detail || -event.wheelDelta;
- if( delta > 0 ) {
- this.Reveal.next();
- }
- else if( delta < 0 ) {
- this.Reveal.prev();
- }
-
- }
-
- }
-
- }
|