11// External dependencies
22import React , { PropTypes } from 'react' ;
3+ import mousetrap from 'mousetrap' ;
34import withStyles from 'isomorphic-style-loader/lib/withStyles' ;
45
6+ // Component variables
7+ let lastTimeStamp = 0 ;
8+
59// Internal dependencies
610import styles from './styles.scss' ;
711
@@ -14,14 +18,68 @@ const VersionSelector = React.createClass( {
1418 event . preventDefault ( ) ;
1519 const reference = bible . parseReference ( this . refs . referenceInput . value ) ;
1620 reference . book = bible . Data . books [ reference . bookID - 1 ] [ 0 ] ;
17- window . location . hash = javascripture . modules . reference . createReferenceLink ( reference )
21+ console . log ( javascripture . modules . reference . createReferenceLink ( reference ) ) ;
22+ window . location . hash = javascripture . modules . reference . createReferenceLink ( reference ) ;
1823 this . refs . referenceInput . blur ( ) ;
1924 } ,
2025
2126 componentWillReceiveProps ( nextProps ) {
2227 this . refs . referenceInput . value = nextProps . value ;
2328 } ,
2429
30+ goToNextCurrentVerse ( ) {
31+ if ( this . props . nextReference ) {
32+ this . props . goToReference ( this . props . nextReference ) ;
33+ this . props . markNextCurrentReference ( ) ;
34+ }
35+ } ,
36+
37+ goToPreviousCurrentVerse ( ) {
38+ if ( this . props . previousReference ) {
39+ this . props . goToReference ( this . props . previousReference ) ;
40+ this . props . markPreviousCurrentReference ( ) ;
41+ }
42+ } ,
43+
44+ goToChapter ( event , combo ) {
45+ const currentTimeStamp = Math . floor ( event . timeStamp ) ,
46+ currentReference = javascripture . modules . reference . getReferenceFromHash ( ) ,
47+ bookId = bible . getBookId ( currentReference . book ) ;
48+
49+ let chapterToGoTo = combo ;
50+ if ( currentTimeStamp - lastTimeStamp < 750 ) {
51+ chapterToGoTo = currentReference . chapter + combo ;
52+ }
53+
54+ if ( bible . Data . verses [ bookId - 1 ] [ chapterToGoTo - 1 ] ) {
55+ var newReference = currentReference ;
56+ newReference . chapter = chapterToGoTo ;
57+ window . location . hash = javascripture . modules . reference . createReferenceLink ( newReference ) ;
58+ }
59+
60+ lastTimeStamp = currentTimeStamp ;
61+ } ,
62+
63+ goToReferenceField ( event ) {
64+ this . refs . referenceInput . focus ( ) ;
65+ this . refs . referenceInput . selectionStart = this . refs . referenceInput . selectionEnd = 0 ;
66+ this . refs . referenceInput . value = event . key ;
67+
68+ } ,
69+
70+ componentDidMount ( ) {
71+ mousetrap . bind ( [ '=' ] , ( ) => this . goToNextCurrentVerse ( false ) ) ;
72+ mousetrap . bind ( [ '-' ] , ( ) => this . goToPreviousCurrentVerse ( false ) ) ;
73+ mousetrap . bind ( [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' ] , this . goToChapter ) ;
74+ mousetrap . bind ( [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ] , this . goToReferenceField ) ;
75+ } ,
76+
77+ componentWillUnmount ( ) {
78+ mousetrap . unbind ( [ '=' ] , ( ) => this . goToNextCurrentVerse ( false ) ) ;
79+ mousetrap . unbind ( [ '-' ] , ( ) => this . goToPreviousCurrentVerse ( false ) ) ;
80+ mousetrap . unbind ( [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ] , this . goToReferenceField ) ;
81+ } ,
82+
2583 render ( ) {
2684 return (
2785 < form className = { styles . versionSelector } onSubmit = { this . goToReference } id = "dock" >
0 commit comments