Skip to content

Commit 2e2b4fc

Browse files
committed
fix go to reference keyboard shortcuts
1 parent df32ec3 commit 2e2b4fc

File tree

2 files changed

+59
-55
lines changed

2 files changed

+59
-55
lines changed

src/components/trays/tray-list.js

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// External
2-
import mousetrap from 'mousetrap';
32
import React, { PropTypes } from 'react';
43
import withStyles from 'isomorphic-style-loader/lib/withStyles';
54

@@ -11,9 +10,6 @@ import SearchTray from './search';
1110
import BookmarksTray from './bookmarks';
1211
import SettingsTray from './settings';
1312

14-
// Component variables
15-
let lastTimeStamp = 0;
16-
1713
function getComponent( componentString ) {
1814
switch ( componentString ) {
1915
case 'WordTray':
@@ -34,56 +30,6 @@ function getComponent( componentString ) {
3430
}
3531

3632
class TrayList extends React.Component{
37-
goToNextCurrentVerse() {
38-
if ( this.props.nextReference ) {
39-
this.props.goToReference( this.props.nextReference );
40-
this.props.markNextCurrentReference();
41-
}
42-
}
43-
44-
goToPreviousCurrentVerse() {
45-
if ( this.props.previousReference ) {
46-
this.props.goToReference( this.props.previousReference );
47-
this.props.markPreviousCurrentReference();
48-
}
49-
}
50-
51-
goToChapter( event, combo ) {
52-
const currentTimeStamp = Math.floor( event.timeStamp ),
53-
currentReference = javascripture.modules.reference.getReferenceFromHash(),
54-
bookId = bible.getBookId( currentReference.book );
55-
56-
let chapterToGoTo = combo;
57-
if ( currentTimeStamp - lastTimeStamp < 750) {
58-
chapterToGoTo = currentReference.chapter + combo;
59-
}
60-
61-
if ( bible.Data.verses[bookId - 1][ chapterToGoTo - 1] ) {
62-
var newReference = currentReference;
63-
newReference.chapter = chapterToGoTo;
64-
window.location.hash = javascripture.modules.reference.createReferenceLink( newReference );
65-
}
66-
67-
lastTimeStamp = currentTimeStamp;
68-
}
69-
70-
goToReference() {
71-
$( '#goToReference' ).val( '' ).focus();
72-
}
73-
74-
componentDidMount() {
75-
mousetrap.bind( [ '=' ], () => this.goToNextCurrentVerse( false ) );
76-
mousetrap.bind( [ '-' ], () => this.goToPreviousCurrentVerse( false ) );
77-
mousetrap.bind( [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ], this.goToChapter );
78-
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.goToReference );
79-
}
80-
81-
componentWillUnmount() {
82-
mousetrap.unbind( [ '=' ], () => this.goToNextCurrentVerse( false ) );
83-
mousetrap.unbind( [ '-' ], () => this.goToPreviousCurrentVerse( false ) );
84-
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.goToReference );
85-
}
86-
8733
render() {
8834
const { trays, filter, onTrayClick } = this.props;
8935

src/components/version-selector/index.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// External dependencies
22
import React, { PropTypes } from 'react';
3+
import mousetrap from 'mousetrap';
34
import withStyles from 'isomorphic-style-loader/lib/withStyles';
45

6+
// Component variables
7+
let lastTimeStamp = 0;
8+
59
// Internal dependencies
610
import 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

Comments
 (0)