<% my $dbi = app->dbi; my $op = param('op') // ''; my $book_id = param('book-id'); my $current_book_id; my $show_word_count; my $word_count_h = {}; my $word = param('word'); my $word_length = length $word; my $word_q = quotemeta($word) if defined $word; if ($word_length) { $show_word_count = 1; for (my $i = 0; $i < 66; $i++) { my $num = sprintf "%02d", $i + 1; my $content = $dbi->select( 'content_no_tag', table => 'book', where => {id => $num} )->value; my $content_length = length $content; $content =~ s/$word_q//g; my $content_length_no_word = length $content; # 文字の個数 my $word_count = ($content_length - $content_length_no_word) / $word_length; $word_count_h->{$num} = $word_count; } } my $books = $dbi->model('book')->select(['id', 'short_name'])->all; my $max_search_pos = $word_count_h->{$book_id} // 0; # 前と次の見つかった書籍 my $next_book_id; my $prev_book_id; my $found_books = []; for my $book (@$books) { if (!$word_length || $word_count_h->{$book->{id}} > 0) { push @$found_books, $book; } } for (my $i = 0; $i < @$found_books; $i++) { if ($book_id eq $found_books->[$i]{id}) { $prev_book_id = $found_books->[$i - 1]{id} if $i > 0; $next_book_id = $found_books->[$i + 1]{id} if $i < @$found_books; } } %> % layout 'common'; %= javascript begin $(document).ready(function () { var fragment = location.hash; var current_pos; if (fragment) { var ret = fragment.match(/word-(\d)/); current_pos = ret[1] - 0; } else { current_pos = 1; } $("#word-pos").text(current_pos); % if ($word_length) { $("#up-arrow").on('click', function () { var current_pos = $('#word-pos').text(); var prev_pos = current_pos - 1; if (prev_pos < 1) { location.href = "<%= url_for('/')->query(word => $word, 'book-id' => $prev_book_id)->fragment("word-$word_count_h->{$prev_book_id}") %>"; } else { location.href = '#word-' + prev_pos; $('#word-pos').text(prev_pos); } }); $("#down-arrow").on('click', function () { var current_pos = $('#word-pos').text(); var next_pos = current_pos - 0 + 1; if (next_pos > <%= $max_search_pos %>) { location.href = "<%= url_for('/')->query(word => $word, 'book-id' => $next_book_id)->fragment('word-1') %>"; } else { location.href = '#word-' + next_pos; $('#word-pos').text(next_pos); } }); % } $('.book').on('click', function () { var book_id_str = $(this).attr('id'); var ret = book_id_str.match(/book-(\d+)/); var book_id = ret[1]; var word; % if ($word_length) { % my $word_quote = $word; % $word_quote =~ s/'/\'/g; word = '<%= $word %>'; % } $.get('/api/book/' + book_id + '/content', function (result) { if (word) { var i = 1; var replace_cb = function (all, group1) { var after = '' + group1 + ''; i = i + 1; return after; }; // var word_regex_quote = word.replace(/([^0-9A-Za-z_])/g, '\\$1'); //alert(word_regex_quote); var word_re = new RegExp('(' + word + ')', 'g'); result.content = result.content.replace(word_re, function (all, group1) { return replace_cb(all, group1); }); } $("#content").html(result.content); current_book_id = book_id; }); }); }); % end

口語訳聖書オンライン語句検索

<%= text_field 'word' , style => "width:160px"%>
聖書 % if ($word_length) {
<%= $book_id ? ' ' : '-' %>
% }
% my $prev_book_id; % for my $book (@$books) { % if (!$word_length || $word_count_h->{$book->{id}} > 0) { % if ($prev_book_id && $book_id) { $next_book_list->{$prev_book_id} = $book_id; $prev_book_list->{$book_id} = $prev_book_id; % } % } % }
% if ($word_length) { 回数 % }
% my $book_url_query = {'book-id' => $book->{id}}; % $book_url_query->{word} = $word if $word_length; % my $book_url = url_for->query($book_url_query); % $book_url->fragment('word-1') if $word_length; {id}" %>" href="javascript:void(0)"> <%= $book->{short_name} %> <%= $word_count_h->{$book->{id}} %>
This site is create by Perl + Mojolicious. Auther is Yuki kimoto.