1+ import Ember from 'ember' ;
12import $ from 'jquery' ;
23import { inject as service } from '@ember/service' ;
34import Component from '@ember/component' ;
45import layout from './template' ;
6+ import { EKMixin , keyDown } from 'ember-keyboard' ;
57
6- export default Component . extend ( {
8+ export default Component . extend ( EKMixin , {
79 layout,
810 docsRoutes : service ( ) ,
11+ router : service ( ) ,
912
1013 classNames : 'docs-viewer' ,
1114
15+ init ( ) {
16+ this . _super ( ) ;
17+
18+ this . set ( 'keyboardActivated' , true ) ;
19+ } ,
20+
1221 didInsertElement ( ) {
1322 $ ( 'body' ) . addClass ( 'docs-viewer--showing' ) ;
1423 } ,
@@ -18,4 +27,72 @@ export default Component.extend({
1827 this . get ( 'docsRoutes' ) . resetState ( ) ;
1928 } ,
2029
30+ nextPage : Ember . on ( keyDown ( 'KeyL' ) , keyDown ( 'ArrowRight' ) , function ( ) {
31+ if ( this . searchIsNotFocused ( ) && this . get ( 'docsRoutes.nextUrl' ) ) {
32+ this . get ( 'router' ) . transitionTo ( this . get ( 'docsRoutes.nextUrl' ) ) ;
33+ }
34+ } ) ,
35+
36+ previousPage : Ember . on ( keyDown ( 'KeyH' ) , keyDown ( 'ArrowLeft' ) , function ( ) {
37+ if ( this . searchIsNotFocused ( ) && this . get ( 'docsRoutes.previousUrl' ) ) {
38+ this . get ( 'router' ) . transitionTo ( this . get ( 'docsRoutes.previousUrl' ) ) ;
39+ }
40+ } ) ,
41+
42+ pageDown : Ember . on ( keyDown ( 'KeyJ' ) , function ( ) {
43+ if ( this . searchIsNotFocused ( ) ) {
44+ let $el = $ ( "#docs-viewer__scroll-body" ) ;
45+
46+ $el . velocity ( 'stop' ) ;
47+ $el . velocity ( 'scroll' , {
48+ offset : ( $el . height ( ) - 150 ) ,
49+ container : $el ,
50+ duration : 225
51+ } ) ;
52+ }
53+ } ) ,
54+
55+ halfPageDown : Ember . on ( keyDown ( 'ctrl+KeyJ' ) , function ( ) {
56+ if ( this . searchIsNotFocused ( ) ) {
57+ let $el = $ ( "#docs-viewer__scroll-body" ) ;
58+
59+ $el . velocity ( 'stop' ) ;
60+ $el . velocity ( 'scroll' , {
61+ offset : ( ( $el . height ( ) / 2 ) - 150 ) ,
62+ container : $el ,
63+ duration : 225
64+ } ) ;
65+ }
66+ } ) ,
67+
68+ pageUp : Ember . on ( keyDown ( 'KeyK' ) , function ( ) {
69+ if ( this . searchIsNotFocused ( ) ) {
70+ let $el = $ ( "#docs-viewer__scroll-body" ) ;
71+
72+ $el . velocity ( 'stop' ) ;
73+ $el . velocity ( 'scroll' , {
74+ offset : - ( $el . height ( ) - 150 ) ,
75+ container : $el ,
76+ duration : 225
77+ } ) ;
78+ }
79+ } ) ,
80+
81+ halfPageUp : Ember . on ( keyDown ( 'ctrl+KeyK' ) , function ( ) {
82+ if ( this . searchIsNotFocused ( ) ) {
83+ let $el = $ ( "#docs-viewer__scroll-body" ) ;
84+
85+ $el . velocity ( 'stop' ) ;
86+ $el . velocity ( 'scroll' , {
87+ offset : - ( ( $el . height ( ) / 2 ) - 150 ) ,
88+ container : $el ,
89+ duration : 225
90+ } ) ;
91+ }
92+ } ) ,
93+
94+ searchIsNotFocused ( ) {
95+ return ! this . $ ( '.docs-viewer-search__input' ) . is ( ':focus' ) ;
96+ }
97+
2198} ) ;
0 commit comments