130 |
log => 'log4perl.conf', |
log => 'log4perl.conf', |
131 |
detail_url => sub { |
detail_url => sub { |
132 |
my $mfn = shift; |
my $mfn = shift; |
133 |
my $path = "./out/thes/${mfn}.html"; |
my $path = "thes/${mfn}.html"; |
134 |
return $path if (-e $path); |
return $path if (-e "./out/$path"); |
135 |
}, |
}, |
136 |
|
nodes_dir => 'nodes', |
137 |
); |
); |
138 |
|
|
139 |
C<tree> is tree array with levels of tree described above. |
C<tree> is tree array with levels of tree described above. |
144 |
C<detail_url> code ref to check if detail html exists (and return URL if |
C<detail_url> code ref to check if detail html exists (and return URL if |
145 |
it does). |
it does). |
146 |
|
|
147 |
|
C<nodes_dir> is relative path from output directory where tree nodes for |
148 |
|
iframes will be created. |
149 |
|
|
150 |
=cut |
=cut |
151 |
|
|
152 |
sub new { |
sub new { |
164 |
$self->{'show_ids'} = []; |
$self->{'show_ids'} = []; |
165 |
$self->{'hide_ids'} = []; |
$self->{'hide_ids'} = []; |
166 |
|
|
167 |
|
# figure out relative URL to other content from nodes_dir |
168 |
|
my $iframe_base = $self->{'nodes_dir'}; |
169 |
|
if ($iframe_base) { |
170 |
|
$iframe_base = s#[^/]*##g; |
171 |
|
$iframe_base = '../' x ( length($iframe_base) ); |
172 |
|
$self->{'iframe_base'} = $iframe_base; |
173 |
|
$log->debug("nodes dir is '",$self->{'nodes_dir'},"' so iframe_base is '",$self->{'iframe_base'},"'"); |
174 |
|
} |
175 |
|
|
176 |
$self->{'tree_html'} = $self->unroll(0,()); |
$self->{'tree_html'} = $self->unroll(0,()); |
177 |
|
|
178 |
if (! $self->{'tree_html'}) { |
if (! $self->{'tree_html'}) { |
252 |
file => $js_file, |
file => $js_file, |
253 |
); |
); |
254 |
|
|
255 |
if (! $args->{'nodes'}) { |
if (! $self->{'nodes_dir'}) { |
256 |
$log->warn("skipping node creation"); |
$log->warn("skipping node creation"); |
257 |
return $self; |
return $self; |
258 |
} |
} |
259 |
|
|
260 |
foreach my $mfn (keys %{$self->{'node_html'}}) { |
foreach my $mfn (keys %{$self->{'node_html'}}) { |
261 |
|
|
262 |
my $html_file = $args->{'dir'}."/".$args->{'nodes'}."/${mfn}.html"; |
my $html_file = $args->{'dir'}."/".$self->{'nodes_dir'}."/${mfn}.html"; |
263 |
|
|
264 |
$log->debug("creating tree node $html_file"); |
$log->debug("creating tree node $html_file"); |
265 |
|
|
307 |
# all levels passed? |
# all levels passed? |
308 |
return if (! defined($tree->[$level])); |
return if (! defined($tree->[$level])); |
309 |
|
|
310 |
$log->debug("unroll level $level"); |
$log->debug("unroll level $level base path ",($base_path || "none")); |
311 |
|
|
312 |
my $html; |
my $html; |
313 |
|
|
328 |
|
|
329 |
$log->debug("$code -> $v900 : $term [$mfn]"); |
$log->debug("$code -> $v900 : $term [$mfn]"); |
330 |
|
|
331 |
my ($link_start,$link_end) = ('',''); |
my ($link_start,$link_end,$level_el) = ('','','ul'); |
332 |
|
|
333 |
my $have_children = $tree->[$level]->{'have_children'}->($code,$v900); |
my $have_children = $tree->[$level]->{'have_children'}->($code,$v900); |
334 |
|
|
339 |
|
|
340 |
} |
} |
341 |
|
|
342 |
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}) if ($have_children); |
my $iframe = $tree->[$level]->{'iframe'}; |
343 |
|
|
344 |
|
if ($have_children) { |
345 |
|
($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}); |
346 |
|
if ($iframe) { |
347 |
|
my $url = $self->{'nodes_dir'} || $log->logdie("no nodes_dir?"); |
348 |
|
$url .= "/${mfn}.html"; |
349 |
|
$link_start = qq{<a href="#mfn$mfn" onClick="iframe_load('i$mfn','$url'); return toggle_display('id$mfn');">}; |
350 |
|
$level_el = 'div'; |
351 |
|
} |
352 |
|
} |
353 |
|
|
354 |
my $mfn_link; |
my $mfn_link; |
355 |
$mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'}); |
$mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'}); |
356 |
|
|
357 |
if ($mfn_link) { |
if ($mfn_link) { |
358 |
$term =~ s, *#C# *, <img src="${base_path}img/crovoc.png" border="0">,; |
$term =~ s/ *#C# */ <img src="${base_path}img\/crovoc.png" border="0">/; |
359 |
$html .= " " x $level . |
$html .= " " x $level . |
360 |
qq{<li>${link_start}<span id="o$mfn">${term}</span>${link_end}}. |
qq{<li>${link_start}<span id="o$mfn">${term}</span>${link_end}}. |
361 |
qq{ <a href="${base_path}${mfn_link}" onClick="javascript:return popup(this);"><img src="${base_path}img/listic.png" border="0"></a></li>\n}; |
qq{ <a href="${base_path}${mfn_link}" onClick="javascript:return popup(this);"><img src="${base_path}img/listic.png" border="0"></a></li>\n}; |
364 |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
$log->warn("file 'out/$mfn_link' doesn't exist, skipping"); |
365 |
} |
} |
366 |
|
|
367 |
|
# save mfn for iframe |
368 |
|
push @{$self->{'mfn_arr'}}, $mfn; |
369 |
|
|
370 |
unless ($have_children) { |
unless ($have_children) { |
371 |
next; |
next; |
372 |
} |
} |
373 |
my $style = $tree->[$level]->{'style'}; |
my $style = $tree->[$level]->{'style'}; |
374 |
|
|
375 |
$html .= " " x $level . |
$html .= " " x $level . |
376 |
qq{<ul id="id$mfn"}. |
qq{<$level_el id="id$mfn"}. |
377 |
($style ? ' style="'.$style.'"' : ''). |
($style ? ' style="'.$style.';"' : ''). |
378 |
qq{>\n}; |
qq{>\n}; |
379 |
|
|
380 |
if ($style) { |
if ($style) { |
388 |
push @{$self->{'show_ids'}}, "id$mfn"; |
push @{$self->{'show_ids'}}, "id$mfn"; |
389 |
} |
} |
390 |
|
|
391 |
if ($tree->[$level]->{'iframe'}) { |
|
392 |
|
if ($iframe) { |
393 |
|
|
394 |
|
# reset list of current mfns |
395 |
|
$self->{'mfn_arr'} = (); |
396 |
|
|
397 |
# unroll to separate file |
# unroll to separate file |
398 |
$self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, '../'); |
$self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, $self->{'iframe_base'}); |
399 |
|
$html .= " " x $level . qq{<span id="w$mfn" style="display: none;">Učitavanje podataka...</span>\n}; |
400 |
|
|
401 |
|
$html .= " " x $level . |
402 |
|
qq{<iframe id="i$mfn" name="i$mfn" width="100%" height="0" marginwidth="0" marginheight="0" frameborder="1" border="0" onLoad="iframe_resize(this.name);"></iframe>\n}; |
403 |
|
@{$self->{'iframe_mfn'}->{$mfn}} = @{$self->{'mfn_arr'}}; |
404 |
|
|
405 |
} else { |
} else { |
406 |
# unroll at base HTML |
# unroll at base HTML |
407 |
$html .= $self->unroll($next_level, $have_children, $base_path); |
$html .= $self->unroll($next_level, $have_children, $base_path); |
408 |
} |
} |
409 |
|
|
410 |
$html .= " " x $level . qq{</ul>\n}; |
$html .= " " x $level . qq{</$level_el>\n}; |
411 |
|
|
412 |
} |
} |
413 |
} |
} |
440 |
open(JS, ">", $js_file) || $log->logdie("can't open '$js_file': $!"); |
open(JS, ">", $js_file) || $log->logdie("can't open '$js_file': $!"); |
441 |
print JS "var show = ['",join("','",@{$self->{'show_ids'}}),"'];\n"; |
print JS "var show = ['",join("','",@{$self->{'show_ids'}}),"'];\n"; |
442 |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; |
443 |
|
|
444 |
|
print JS "var mfn_iframe = [\n"; |
445 |
|
foreach my $if (keys %{$self->{'iframe_mfn'}}) { |
446 |
|
# print JS " ",join(",",map { "[$_:$if]" } @{$self->{'iframe_mfn'}->{$if}}),",\n"; |
447 |
|
} |
448 |
|
print JS " null\n]\n"; |
449 |
|
|
450 |
close(JS); |
close(JS); |
451 |
|
|
452 |
$log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements"); |
$log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements"); |