File tree 3 files changed +45
-28
lines changed
3 files changed +45
-28
lines changed Original file line number Diff line number Diff line change 21
21
22
22
// You are one of those who like to know how things work inside?
23
23
// Let me show you the cogs that make impress.js run...
24
- ; ( function ( document , window ) {
24
+ export function Impress ( document , window ) {
25
25
'use strict'
26
26
27
27
// HELPER FUNCTIONS
687
687
688
688
// Flag that can be used in JS to check if browser have passed the support test
689
689
impress . supported = impressSupported
690
- } ) ( document , window )
690
+ }
691
691
692
692
// NAVIGATION EVENTS
693
693
697
697
//
698
698
// In future I think about moving it to make them optional, move to separate files
699
699
// and treat more like a 'plugins'.
700
- ; ( function ( document , window ) {
700
+ export function ImpressHandleEvents ( ) {
701
701
'use strict'
702
702
703
703
// Throttling function calls, by Remy Sharp
768
768
return
769
769
}
770
770
771
- if (
772
- event . keyCode === 9 ||
773
- ( event . keyCode >= 32 && event . keyCode <= 34 ) ||
774
- ( event . keyCode >= 37 && event . keyCode <= 40 )
775
- ) {
776
- switch ( event . keyCode ) {
777
- case 33 : // Page up
778
- case 37 : // Left
779
- case 38 : // Up
780
- api . prev ( )
781
- break
782
- case 9 : // Tab
783
- case 32 : // Space
784
- case 34 : // Page down
785
- case 39 : // Right
786
- case 40 : // Down
787
- api . next ( )
788
- break
789
- }
790
-
791
- event . preventDefault ( )
771
+ switch ( event . key ) {
772
+ case 'PageUp' :
773
+ case 'ArrowLeft' :
774
+ case 'ArrowUp' :
775
+ api . prev ( )
776
+ event . preventDefault ( )
777
+ break
778
+ case 'Tab' :
779
+ case 'Space' :
780
+ case 'PageDown' :
781
+ case 'ArrowRight' :
782
+ case 'ArrowDown' :
783
+ api . next ( )
784
+ event . preventDefault ( )
785
+ break
786
+ default :
792
787
}
793
788
} ,
794
789
false
885
880
} ,
886
881
false
887
882
)
888
- } ) ( document , window )
883
+ }
889
884
890
885
// THAT'S ALL FOLKS!
891
886
//
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
import React from 'react'
3
3
import ReactDOM from 'react-dom'
4
- import './impress-vendor.js'
4
+ import { Impress , ImpressHandleEvents } from './impress-vendor.js'
5
5
import './impress.less'
6
6
import DeckStore from 'stores/deck'
7
7
import AutoScale from 'components/mixins/autoScale'
8
8
import _ from 'lodash'
9
9
import Global from './global'
10
10
var DisplayableComponent = require ( 'components/widgets/displayableComponent' )
11
-
11
+ ImpressHandleEvents ( document , window )
12
12
let Presentation = class extends AutoScale . autoScaleMixin ( React . Component ) {
13
13
constructor ( props ) {
14
14
super ( props )
@@ -23,6 +23,7 @@ let Presentation = class extends AutoScale.autoScaleMixin(React.Component) {
23
23
}
24
24
25
25
componentDidMount ( ) {
26
+ Impress ( document , window )
26
27
super . componentDidMount && super . componentDidMount ( )
27
28
if ( 'ontouchstart' in document . documentElement ) {
28
29
document . querySelector ( '.hint' ) . innerHTML =
Original file line number Diff line number Diff line change @@ -4,10 +4,31 @@ describe('show > impress', () => {
4
4
beforeEach ( ( ) => {
5
5
appWrapper = getAppWrapper ( 'Impress' )
6
6
} )
7
+ afterEach ( ( ) => {
8
+ $ ( 'body' ) . removeAttr ( 'style' )
9
+ $ ( 'body' ) . removeAttr ( 'class' )
10
+ } )
7
11
8
12
it ( 'should have 5 initial views' , ( ) => {
9
13
expect ( appWrapper . find ( '#impress' ) . props ( ) . children . length ) . to . equal ( 5 )
10
14
expect ( $ ( 'body' ) . attr ( 'class' ) ) . to . contain ( 'impress-on-step-1' )
11
- expect ( $ ( '#step-1' ) . attr ( 'class' ) . split ( ' ' ) ) . to . include ( 'active' )
15
+ expect (
16
+ $ ( '#step-1' )
17
+ . attr ( 'class' )
18
+ . split ( ' ' )
19
+ ) . to . include ( 'active' )
20
+ } )
21
+
22
+ it ( 'should move to 2nd step when press right key' , ( ) => {
23
+ let event = new KeyboardEvent ( 'keyup' , {
24
+ key : 'ArrowRight'
25
+ } )
26
+ document . dispatchEvent ( event )
27
+ expect ( $ ( 'body' ) . attr ( 'class' ) ) . to . contain ( 'impress-on-step-2' )
28
+ expect (
29
+ $ ( '#step-2' )
30
+ . attr ( 'class' )
31
+ . split ( ' ' )
32
+ ) . to . include ( 'active' )
12
33
} )
13
34
} )
You can’t perform that action at this time.
0 commit comments