... | ... |
@@ -13,49 +13,58 @@ |
13 | 13 |
var current_book_id; |
14 | 14 |
var found_book_ids = []; |
15 | 15 |
var max_search_pos; |
16 |
+ var current_word_count_h; |
|
17 |
+ var current_pos; |
|
16 | 18 |
|
17 | 19 |
var fragment = location.hash; |
18 |
- var current_pos; |
|
19 |
- if (fragment) { |
|
20 |
- var ret = fragment.match(/word-(\d)/); |
|
21 |
- current_pos = ret[1] - 0; |
|
22 |
- } |
|
23 |
- else { |
|
24 |
- current_pos = 1; |
|
25 |
- } |
|
26 |
- $("#word-pos").text(current_pos); |
|
20 |
+ |
|
21 |
+ $("#word-pos").text('-'); |
|
27 | 22 |
|
28 | 23 |
$("#up-arrow").on('click', function () { |
29 |
- var current_pos = $('#word-pos').text(); |
|
30 |
- var prev_pos = current_pos - 1; |
|
31 |
- |
|
32 |
- if (prev_pos < 1) { |
|
24 |
+ if (current_pos) { |
|
25 |
+ var prev_pos = current_pos - 1; |
|
33 | 26 |
|
34 |
- } else { |
|
35 |
- location.href = '#word-' + prev_pos; |
|
36 |
- $('#word-pos').text(prev_pos); |
|
27 |
+ if (prev_pos < 1) { |
|
28 |
+ var prev_book_id; |
|
29 |
+ for (var i = 0; i < found_book_ids.length; i++) { |
|
30 |
+ if (found_book_ids[i] === current_book_id) { |
|
31 |
+ prev_book_id = found_book_ids[i - 1]; |
|
32 |
+ } |
|
33 |
+ } |
|
34 |
+ if (prev_book_id) { |
|
35 |
+ current_pos = current_word_count_h[prev_book_id]; |
|
36 |
+ $('#books tr[id=book-' + prev_book_id + ']').find('.book').trigger('click'); |
|
37 |
+ } |
|
38 |
+ } else { |
|
39 |
+ location.href = '#word-' + prev_pos; |
|
40 |
+ current_pos--; |
|
41 |
+ $('#word-pos').text(prev_pos); |
|
42 |
+ } |
|
37 | 43 |
} |
38 | 44 |
}); |
39 | 45 |
|
40 | 46 |
$("#down-arrow").on('click', function () { |
41 |
- var current_pos = $('#word-pos').text(); |
|
42 |
- var next_pos = current_pos - 0 + 1; |
|
43 |
- |
|
44 |
- if (next_pos > max_search_pos) { |
|
45 |
- var next_book_id; |
|
46 |
- for (var i = 0; i < found_book_ids.length; i++) { |
|
47 |
- if (found_book_ids[i] === current_book_id) { |
|
48 |
- next_book_id = found_book_ids[i + 1]; |
|
47 |
+ if (current_pos) { |
|
48 |
+ var next_pos = current_pos - 0 + 1; |
|
49 |
+ |
|
50 |
+ if (next_pos > max_search_pos) { |
|
51 |
+ var next_book_id; |
|
52 |
+ for (var i = 0; i < found_book_ids.length; i++) { |
|
53 |
+ if (found_book_ids[i] === current_book_id) { |
|
54 |
+ next_book_id = found_book_ids[i + 1]; |
|
55 |
+ } |
|
56 |
+ } |
|
57 |
+ if (next_book_id) { |
|
58 |
+ current_pos = 1; |
|
59 |
+ $('#books tr[id=book-' + next_book_id + ']').find('.book').trigger('click'); |
|
49 | 60 |
} |
50 | 61 |
} |
51 |
- if (next_book_id) { |
|
52 |
- $('#books tr[id=book-' + next_book_id + ']').find('.book').trigger('click'); |
|
62 |
+ else { |
|
63 |
+ location.href = '#word-' + next_pos; |
|
64 |
+ current_pos++; |
|
65 |
+ $('#word-pos').text(next_pos); |
|
53 | 66 |
} |
54 | 67 |
} |
55 |
- else { |
|
56 |
- location.href = '#word-' + next_pos; |
|
57 |
- $('#word-pos').text(next_pos); |
|
58 |
- } |
|
59 | 68 |
}); |
60 | 69 |
|
61 | 70 |
// 書をクリック |
... | ... |
@@ -76,12 +85,16 @@ |
76 | 85 |
|
77 | 86 |
var word_re = new RegExp('(' + current_word + ')', 'g'); |
78 | 87 |
result.content = result.content.replace(word_re, function (all, group1) { return replace_cb(all, group1); }); |
79 |
- max_search_pos = i; |
|
88 |
+ max_search_pos = i - 1; |
|
80 | 89 |
} |
81 | 90 |
|
82 | 91 |
$("#content").html(result.content); |
83 | 92 |
if (current_word) { |
84 |
- location.href = '#word-1'; |
|
93 |
+ if (!current_pos) { |
|
94 |
+ current_pos = 1; |
|
95 |
+ } |
|
96 |
+ location.href = '#word-' + current_pos; |
|
97 |
+ $('#word-pos').text(current_pos); |
|
85 | 98 |
} |
86 | 99 |
current_book_id = book_id; |
87 | 100 |
|
... | ... |
@@ -108,6 +121,7 @@ |
108 | 121 |
var word_count_h; |
109 | 122 |
$.get('/api/word-count/' + word, function (result) { |
110 | 123 |
var word_count_h = result.word_count; |
124 |
+ current_word_count_h = word_count_h; |
|
111 | 125 |
|
112 | 126 |
$('#books tr').each(function () { |
113 | 127 |
var book_id_str = $(this).attr('id'); |