-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.rb
159 lines (134 loc) · 5.09 KB
/
static.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# encoding: UTF-8
# Copyright 2008, 2009, 2010 Boris ARZUR
#
# This file is part of Kemuri.
#
# Kemuri is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# Kemuri is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with Kemuri. If not, see http://www.gnu.org/licenses.
class Static
@@voyage_buttons = ""
def self.load_content file
if file =~ /.gz$/
raw_content = Zlib::GzipReader.open( file ) {|gz| gz.read}
file = file[0..-4]
else
raw_content = File::read( file )
end
clean_content = raw_content
#clean_content = raw_content.gsub( /\/\*.*?\*\//m, '' ).gsub( "\n", "" )
#while clean_content.gsub!( " ", " " )
#end
if file =~ /\.js$/
clean_content.script
elsif file =~ /\.css$/
clean_content.style
else
clean_content
end
end
BarStyle = load_content( 'bar.css' )
VoyageScript = load_content( 'voyage.js' )
Next_pageScript = load_content( 'next_page.js' )
Rad_barScript = load_content( 'rad_bar.js' )
def self.kanji_table id_table
kanji_table = File::read( 'kanji_table.html' )
kanji_table.gsub( /#id_table#/, id_table )
end
def self.add_button name, path = name
button = "<button onclick='window.location = \"/#{path}\"'>#{name}</button> "
@@voyage_buttons << button
end
def self.look_select max, url
res = <<-EOS
<script type="text/javascript" charset="utf-8">
var selection = new Array();
function set_visi_class(classname, visi) {
var elements = document.getElementsByClassName( classname );
for(var i = 0;i < elements.length;i++)
elements[i].style.display = visi;
};
function select(id,kan,id_table) {
selection[id] = kan;
set_visi_class('hideable-' + id_table, 'none');
set_visi_class('radz-' + id_table, 'none');
document.getElementById('radi_up-' + id_table).style.display = 'none';
document.getElementById('radi_down-' + id_table).style.display = 'none';
if(selection.length == #{max}) window.location = "#{url}kans=" + selection.toString();
var link = document.createElement('a');
link.setAttribute('href', 'javascript:reshow("' + id_table + '")');
link.appendChild( document.createTextNode("Reshow kanji " + id ) );
var footer = document.getElementById( 'footer' );
footer.appendChild( link );
footer.appendChild( document.createElement('br') );
};
function reshow(id_table) {
set_visi_class('hideable-' + id_table, 'inline');
set_visi_class('radz-' + id_table, 'inline');
document.getElementById('radi_up-' + id_table).style.display = 'inline';
document.getElementById('radi_down-' + id_table).style.display = 'inline';
};
</script>
<div id=footer></div>
EOS
end
def self.voyage
res = <<-EOS
<div id="voyage" class="bar">
<form onsubmit='voyage_update_options(); return false;'><input type="text" id="dokomade" autocapitalize="off" size='10'/></form>
<button onclick='voyage_update_options()'>←search</button>
#{@@voyage_buttons}
</div>
EOS
res + VoyageScript
end
def self.next_page base, start, next_page
res = <<-EOS
<script type="text/javascript">
var update = #{start ? 'true' : 'false'};
var next_page_url_base = "#{base}";
var glue = "#{(base =~ /\?$/ )?"":"&"}";
var next_page = #{next_page};
</script>
EOS
res + Next_pageScript
end
def self.rad_bar
res = <<-EOS
<div id="rad_bar" class="bar">
<form onsubmit='voyage_update_options(); return false;'><input type="text" id="dokomade" autocapitalize="off" size='10'/></form>
<button onclick='voyage_update_options()'>←search</button>
#{@@voyage_buttons}
<button onclick='send_form()'>search</button>
<button onclick='rad_bar_clear()'>clear</button>
</div>
EOS
res + BarStyle + Rad_barScript + VoyageScript
end
def self.yad_head request, request_xml, options = {}
request += request.include?('?') ? "&links" : "?links"
request.force_encoding(Encoding::UTF_8)
request_xml += request_xml.include?('?') ? "&kb" : "?kb"
res = <<-EOS
<div id="yad_bar" class="bar">
<form onsubmit='voyage_update_options(); return false;'><input type="text" id="dokomade" autocapitalize="off" size='10'/></form>
<button onclick='voyage_update_options()'>←search</button>
#{@@voyage_buttons}
<button onclick='window.location = \"#{request}\"'>make links on all kanjis</button>
EOS
res += "<button onclick='ajax_get( \"#{request_xml}\" )'>search kanjis one by one</button>" if options[:kb]
res += "<button onclick='do_fuzz();'>fuzz</button>" if options[:fuzz]
res += "<button onclick='do_pairs();'>search pairs of kanjis</button><button onclick='do_alt();'>search alternative pairs</button>" if options[:pairs]
res += "</div>"
res + BarStyle + VoyageScript
end
end