... | ... |
@@ -7,6 +7,7 @@ |
7 | 7 |
my $word_count_h = {}; |
8 | 8 |
my $word = param('word'); |
9 | 9 |
my $word_length = length $word; |
10 |
+ my $word_q = quotemeta($word); |
|
10 | 11 |
if ($word_length) { |
11 | 12 |
$show_word_count = 1; |
12 | 13 |
for (my $i = 0; $i < 66; $i++) { |
... | ... |
@@ -17,35 +18,63 @@ |
17 | 18 |
table => 'book', |
18 | 19 |
where => {id => $num} |
19 | 20 |
)->value; |
20 |
- |
|
21 | 21 |
my $content_length = length $content; |
22 |
- |
|
23 |
- $content =~ s/$word//g; |
|
24 |
- |
|
22 |
+ $content =~ s/$word_q//g; |
|
25 | 23 |
my $content_length_no_word = length $content; |
26 |
- |
|
24 |
+ |
|
25 |
+ # 文字の個数 |
|
27 | 26 |
my $word_count = ($content_length - $content_length_no_word) / $word_length; |
28 |
- |
|
29 | 27 |
$word_count_h->{$num} = $word_count; |
30 | 28 |
} |
31 | 29 |
} |
32 | 30 |
|
33 |
- warn dumper $word_count_h; |
|
34 |
- |
|
35 | 31 |
my $books = $dbi->model('book')->select(['id', 'short_name'])->all; |
36 | 32 |
|
37 | 33 |
my $content; |
34 |
+ my $max_search_pos; |
|
38 | 35 |
if ($book_id) { |
39 | 36 |
$content = $dbi->model('book')->select( |
40 | 37 |
'content', |
41 | 38 |
where => {id => $book_id} |
42 | 39 |
)->value; |
40 |
+ |
|
41 |
+ # アンカーを追加 |
|
42 |
+ if ($word_length) { |
|
43 |
+ my $i = 1; |
|
44 |
+ my $replace_cb = sub { |
|
45 |
+ my $word = shift; |
|
46 |
+ my $after = qq|<a style="background:#00ffff" id="word-$i">$word</a>|; |
|
47 |
+ $i++; |
|
48 |
+ return $after; |
|
49 |
+ }; |
|
50 |
+ $content =~ s#($word_q)#$replace_cb->($1)#ge; |
|
51 |
+ $max_search_pos = $i; |
|
52 |
+ } |
|
43 | 53 |
} |
44 | 54 |
%> |
45 | 55 |
|
46 | 56 |
|
47 | 57 |
% layout 'common'; |
48 | 58 |
|
59 |
+%= javascript begin |
|
60 |
+ $(document).ready(function () { |
|
61 |
+ |
|
62 |
+ $("#up-arrow").on('click', function () { |
|
63 |
+ var current_pos = $('#word-pos').text(); |
|
64 |
+ var prev_pos = current_pos - 1; |
|
65 |
+ $('#word-pos').text(prev_pos); |
|
66 |
+ location.href = '#word-' + prev_pos; |
|
67 |
+ }); |
|
68 |
+ |
|
69 |
+ $("#down-arrow").on('click', function () { |
|
70 |
+ var current_pos = $('#word-pos').text(); |
|
71 |
+ var next_pos = current_pos - 0 + 1; |
|
72 |
+ $('#word-pos').text(next_pos); |
|
73 |
+ location.href = '#word-' + next_pos; |
|
74 |
+ }); |
|
75 |
+ }); |
|
76 |
+% end |
|
77 |
+ |
|
49 | 78 |
<div id="container"> |
50 | 79 |
|
51 | 80 |
<div id="boxA"> |
... | ... |
@@ -58,7 +87,24 @@ |
58 | 87 |
<input type="submit" value="検索" style="width:50px;padding:2px;"> |
59 | 88 |
</form> |
60 | 89 |
<div style="margin-bottom:10px;"> |
61 |
- <a href="<%= url_for('/') %>" style="color:blue">聖書</a> |
|
90 |
+ <table style="border-collapse: collapse;width:100%;color:#333333"> |
|
91 |
+ <tr> |
|
92 |
+ <td style="width:90px"> |
|
93 |
+ <a href="<%= url_for('/') %>" style="color:blue">聖書</a> |
|
94 |
+ </td> |
|
95 |
+ <td> |
|
96 |
+ % if ($word_length) { |
|
97 |
+ <span> |
|
98 |
+ <a id="up-arrow" href="javascript:void()">▲</a> |
|
99 |
+ <div id="word-pos" style="display:inline-block;border:1px solid #DDDDDD;padding:2px 5px;width:35px;text-align:center"> |
|
100 |
+ <%= $book_id ? 1 : '-' %> |
|
101 |
+ </div> |
|
102 |
+ <a id="down-arrow" href="javascript:void()">▼</a> |
|
103 |
+ </span> |
|
104 |
+ % } |
|
105 |
+ </td> |
|
106 |
+ </tr> |
|
107 |
+ </table> |
|
62 | 108 |
</div> |
63 | 109 |
<div style="border:1px solid gray;width:218px;height:400px;overflow:auto;padding:5px"> |
64 | 110 |
<table style="border-collapse: collapse;width:100%;color:#333333"> |
... | ... |
@@ -74,12 +120,20 @@ |
74 | 120 |
</tr> |
75 | 121 |
% for my $book (@$books) { |
76 | 122 |
<tr> |
77 |
- <td> |
|
78 |
- <a class="book" id="<%= "book-$book->{id}" %>" href="<%= url_for->query('book-id' => $book->{id}) %>"><%= $book->{short_name} %></a> |
|
79 |
- </td> |
|
80 |
- <td style="text-align:right"> |
|
81 |
- <%= $word_count_h->{$book->{id}} %> |
|
82 |
- </td> |
|
123 |
+ % if (!$word_length || $word_count_h->{$book->{id}} > 0) { |
|
124 |
+ <td style="<%= $book_id eq $book->{id} ? 'background:#DDDDDD' : '' %>"> |
|
125 |
+ % my $book_url_query = {'book-id' => $book->{id}}; |
|
126 |
+ % $book_url_query->{word} = $word if $word_length; |
|
127 |
+ % my $book_url = url_for->query($book_url_query); |
|
128 |
+ % $book_url->fragment('#word-1') if $word_length; |
|
129 |
+ <a class="book" id="<%= "book-$book->{id}" %>" href="<%= $book_url %>"> |
|
130 |
+ <%= $book->{short_name} %> |
|
131 |
+ </a> |
|
132 |
+ </td> |
|
133 |
+ <td style="text-align:right"> |
|
134 |
+ <%= $word_count_h->{$book->{id}} %> |
|
135 |
+ </td> |
|
136 |
+ % } |
|
83 | 137 |
</tr> |
84 | 138 |
% } |
85 | 139 |
</table> |