biblesearch / templates / index.html.ep /
Newer Older
160 lines | 4.899kb
add files
Yuki Kimoto authored on 2014-03-26
1
<%
2
  my $dbi = app->dbi;
3
  my $op = param('op') // '';
4
  my $book_id = param('book-id');
5
  
improve design
Yuki Kimoto authored on 2014-03-27
6
  my $show_word_count;
7
  my $word_count_h = {};
8
  my $word = param('word');
9
  my $word_length = length $word;
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
10
  my $word_q = quotemeta($word);
improve design
Yuki Kimoto authored on 2014-03-27
11
  if ($word_length) {
12
    $show_word_count = 1;
13
    for (my $i = 0; $i < 66; $i++) {
14
      my $num = sprintf "%02d", $i + 1;
15
      
16
      my $content = $dbi->select(
17
        'content_no_tag',
18
        table => 'book',
19
        where => {id => $num}
20
      )->value;
21
      my $content_length = length $content;
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
22
      $content =~ s/$word_q//g;
improve design
Yuki Kimoto authored on 2014-03-27
23
      my $content_length_no_word = length $content;
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
24
      
25
      # 文字の個数
improve design
Yuki Kimoto authored on 2014-03-27
26
      my $word_count = ($content_length - $content_length_no_word) / $word_length;
27
      $word_count_h->{$num} = $word_count;
28
    }
29
  }
30
  
improve design
Yuki Kimoto authored on 2014-03-27
31
  my $books = $dbi->model('book')->select(['id', 'short_name'])->all;
add files
Yuki Kimoto authored on 2014-03-26
32
  
improve design
Yuki Kimoto authored on 2014-03-27
33
  my $content;
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
34
  my $max_search_pos;
improve design
Yuki Kimoto authored on 2014-03-27
35
  if ($book_id) {
36
    $content = $dbi->model('book')->select(
37
      'content',
38
      where => {id => $book_id}
39
    )->value;
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
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
    }
improve design
Yuki Kimoto authored on 2014-03-27
53
  }
add files
Yuki Kimoto authored on 2014-03-26
54
%>
55

            
56

            
57
% layout 'common';
58

            
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
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

            
add files
Yuki Kimoto authored on 2014-03-26
78
<div id="container">
79

            
80
  <div id="boxA">
81
    <h1>口語訳聖書オンライン語句検索</h1>
82
  </div>
83

            
84
  <div id="boxB">
improve design
Yuki Kimoto authored on 2014-03-27
85
      <form style="margin-bottom:5px" action="<%= url_for('current') %>" method="get">
add files
Yuki Kimoto authored on 2014-03-26
86
        <%= text_field 'word' , style => "width:160px"%>
improve design
Yuki Kimoto authored on 2014-03-27
87
        <input type="submit" value="検索" style="width:50px;padding:2px;">
88
      </form>
add files
Yuki Kimoto authored on 2014-03-26
89
      <div style="margin-bottom:10px;">
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
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>
add files
Yuki Kimoto authored on 2014-03-26
108
      </div>
109
      <div style="border:1px solid gray;width:218px;height:400px;overflow:auto;padding:5px">
improve design
Yuki Kimoto authored on 2014-03-27
110
        <table style="border-collapse: collapse;width:100%;color:#333333">
111
            <tr style="border-bottom:1px solid #EEEEEE">
112
              <td>
113
114
              </td>
115
              <td style="text-align:right">
116
                % if ($word_length) {
117
                  回数
118
                % }
119
              </td>
120
            </tr>
add files
Yuki Kimoto authored on 2014-03-26
121
          % for my $book (@$books) {
improve design
Yuki Kimoto authored on 2014-03-27
122
            <tr>
アンカーを移動できるようにした。
Yuki Kimoto authored on 2014-03-27
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
              % }
improve design
Yuki Kimoto authored on 2014-03-27
137
            </tr>
add files
Yuki Kimoto authored on 2014-03-26
138
          % }
improve design
Yuki Kimoto authored on 2014-03-27
139
        </table>
add files
Yuki Kimoto authored on 2014-03-26
140
      </div>
141
  </div>
142

            
143
  <div id="boxC">
improve design
Yuki Kimoto authored on 2014-03-27
144
    <div style="height:500px;overflow:auto">
145
      % if ($book_id) {
146
        %== $content
147
      % }
148
    </div>
add files
Yuki Kimoto authored on 2014-03-26
149
  </div>
150

            
151

            
152
  <div id="boxD">
improve design
Yuki Kimoto authored on 2014-03-27
153
    <div style="border-top:1px solid #AAAAAA;padding-top:10px;">
154
      This site is create by
155
      <a href="http://d.hatena.ne.jp/perlcodesample">Perl</a> +
156
      <a href="http://d.hatena.ne.jp/perlcodesample/20140319/1395203665">Mojolicious</a>.
157
      Auther is <a href="https://twitter.com/yukikimoto2">Yuki kimoto</a>.
158
    </div>
add files
Yuki Kimoto authored on 2014-03-26
159
  </div>
160
</div>