| 16 |
return $s; |
return $s; |
| 17 |
}; |
}; |
| 18 |
|
|
| 19 |
|
my $htescape_value = sub ($) { |
| 20 |
|
my $s = $_[0]; |
| 21 |
|
$s =~ s/&/&/g; |
| 22 |
|
$s =~ s/</</g; |
| 23 |
|
$s =~ s/>/>/g; |
| 24 |
|
$s =~ s/"/"/g; |
| 25 |
|
return $s; |
| 26 |
|
}; |
| 27 |
|
|
| 28 |
sub new ($) { |
sub new ($) { |
| 29 |
return bless {nav => [], section_rank => 1}, shift; |
require WebHACC::Input; |
| 30 |
|
return bless {nav => [], section_rank => 1, |
| 31 |
|
input => WebHACC::Input->new}, shift; |
| 32 |
} # new |
} # new |
| 33 |
|
|
| 34 |
sub input ($;$) { |
sub input ($;$) { |
| 36 |
if (defined $_[1]) { |
if (defined $_[1]) { |
| 37 |
$_[0]->{input} = $_[1]; |
$_[0]->{input} = $_[1]; |
| 38 |
} else { |
} else { |
| 39 |
delete $_[0]->{input}; |
$_[0]->{input} = WebHACC::Input->new; |
| 40 |
} |
} |
| 41 |
} |
} |
| 42 |
|
|
| 84 |
|
|
| 85 |
sub start_tag ($$%) { |
sub start_tag ($$%) { |
| 86 |
my ($self, $tag_name, %opt) = @_; |
my ($self, $tag_name, %opt) = @_; |
| 87 |
$self->html ('<' . $htescape->($tag_name)); # escape for safety |
$self->html ('<' . $htescape_value->($tag_name)); # escape for safety |
| 88 |
if (exists $opt{id}) { |
if (exists $opt{id}) { |
| 89 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
| 90 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape_value->($id) . '"'); |
| 91 |
delete $opt{id}; |
delete $opt{id}; |
| 92 |
} |
} |
| 93 |
for (keys %opt) { # for safety |
for (keys %opt) { # for safety |
| 94 |
$self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"'); |
$self->html (' ' . $htescape_value->($_) . '="' . |
| 95 |
|
$htescape_value->($opt{$_}) . '"'); |
| 96 |
} |
} |
| 97 |
$self->html ('>'); |
$self->html ('>'); |
| 98 |
} # start_tag |
} # start_tag |
| 99 |
|
|
| 100 |
sub end_tag ($$) { |
sub end_tag ($$) { |
| 101 |
shift->html ('</' . $htescape->(shift) . '>'); |
shift->html ('</' . $htescape_value->(shift) . '>'); |
| 102 |
} # end_tag |
} # end_tag |
| 103 |
|
|
| 104 |
sub start_section ($%) { |
sub start_section ($%) { |
| 137 |
$self->html ('<div class=section'); |
$self->html ('<div class=section'); |
| 138 |
if (defined $opt{id}) { |
if (defined $opt{id}) { |
| 139 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
| 140 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape->($id) . '">'); |
| 141 |
push @{$self->{nav}}, |
if ($self->{section_rank} == 2 or defined $opt{parent_id}) { |
| 142 |
[$id => $opt{short_title} || $opt{title} => $opt{text}] |
my $st = $opt{short_title} || $opt{title}; |
| 143 |
if $self->{section_rank} == 2; |
push @{$self->{nav}}, |
| 144 |
|
[$id => $st => $opt{text}]; |
| 145 |
|
|
| 146 |
|
$self->start_tag ('script'); |
| 147 |
|
$self->html (qq[ addSectionLink ('] . $self->input->id_prefix . |
| 148 |
|
qq[$id', ']); |
| 149 |
|
$self->nl_text ($st, text => $opt{text}); |
| 150 |
|
if (defined $opt{parent_id}) { |
| 151 |
|
$self->html (q[', '] . $opt{parent_id}); |
| 152 |
|
} |
| 153 |
|
$self->html (q[') ]); |
| 154 |
|
$self->end_tag ('script'); |
| 155 |
|
} |
| 156 |
|
} else { |
| 157 |
|
$self->html ('>'); |
| 158 |
} |
} |
| 159 |
my $section_rank = $self->{section_rank}; |
my $section_rank = $self->{section_rank}; |
| 160 |
$section_rank = 6 if $section_rank > 6; |
$section_rank = 6 if $section_rank > 6; |
| 161 |
$self->html ('><h' . $section_rank . '>'); |
$self->html ('<h' . $section_rank . '>'); |
| 162 |
$self->nl_text ($opt{title}, text => $opt{text}); |
$self->nl_text ($opt{title}, text => $opt{text}); |
| 163 |
$self->html ('</h' . $section_rank . '>'); |
$self->html ('</h' . $section_rank . '>'); |
| 164 |
} # start_section |
} # start_section |
| 213 |
my $self = shift; |
my $self = shift; |
| 214 |
|
|
| 215 |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
| 216 |
q[', '] . shift . q[')]); |
q[', '] . shift () . q[')]); |
| 217 |
} # add_source_to_parse_error_list |
} # add_source_to_parse_error_list |
| 218 |
|
|
| 219 |
sub start_code_block ($) { |
sub start_code_block ($) { |
| 244 |
$self->nl_text ($content, text => $opt{text}); |
$self->nl_text ($content, text => $opt{text}); |
| 245 |
} # dt |
} # dt |
| 246 |
|
|
| 247 |
|
sub select ($$%) { |
| 248 |
|
my ($self, $options, %opt) = @_; |
| 249 |
|
|
| 250 |
|
my $selected = $opt{selected}; |
| 251 |
|
delete $opt{selected}; |
| 252 |
|
|
| 253 |
|
$self->start_tag ('select', %opt); |
| 254 |
|
|
| 255 |
|
my @options = @$options; |
| 256 |
|
while (@options) { |
| 257 |
|
my $opt = shift @options; |
| 258 |
|
if ($opt->{options}) { |
| 259 |
|
$self->html ('<optgroup label="'); |
| 260 |
|
$self->nl_text ($opt->{label}); |
| 261 |
|
$self->html ('">'); |
| 262 |
|
unshift @options, @{$opt->{options}}, {end_options => 1}; |
| 263 |
|
} elsif ($opt->{end_options}) { |
| 264 |
|
$self->end_tag ('optgroup'); |
| 265 |
|
} else { |
| 266 |
|
$self->start_tag ('option', value => $opt->{value}, |
| 267 |
|
((defined $selected and $opt->{value} eq $selected) |
| 268 |
|
? (selected => '') : ())); |
| 269 |
|
$self->nl_text (defined $opt->{label} ? $opt->{label} : $opt->{value}); |
| 270 |
|
} |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
$self->end_tag ('select'); |
| 274 |
|
} # select |
| 275 |
|
|
| 276 |
sub link ($$%) { |
sub link ($$%) { |
| 277 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
| 278 |
$self->start_tag ('a', %opt, href => $opt{url}); |
$self->start_tag ('a', %opt, href => $opt{url}); |
| 320 |
return join '/', @r; |
return join '/', @r; |
| 321 |
}; # $get_node_path |
}; # $get_node_path |
| 322 |
|
|
| 323 |
|
my $get_object_path = sub ($) { |
| 324 |
|
my $node = shift; |
| 325 |
|
my @r; |
| 326 |
|
while (defined $node) { |
| 327 |
|
my $ref = ref $node; |
| 328 |
|
$ref =~ /([^:]+)$/; |
| 329 |
|
my $rs = $1; |
| 330 |
|
my $node_name = $node->node_name; |
| 331 |
|
if (defined $node_name) { |
| 332 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
| 333 |
|
} |
| 334 |
|
$node = undef; |
| 335 |
|
unshift @r, $rs; |
| 336 |
|
} |
| 337 |
|
return join '/', @r; |
| 338 |
|
}; # $get_object_path |
| 339 |
|
|
| 340 |
sub node_link ($$) { |
sub node_link ($$) { |
| 341 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
| 342 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
| 343 |
|
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
| 344 |
|
} else { |
| 345 |
|
$self->html ($get_object_path->($node)); |
| 346 |
|
} |
| 347 |
} # node_link |
} # node_link |
| 348 |
|
|
| 349 |
{ |
{ |
| 443 |
$self->nl_text (q[WebHACC:Title]); |
$self->nl_text (q[WebHACC:Title]); |
| 444 |
$self->html (q[</title> |
$self->html (q[</title> |
| 445 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
| 446 |
|
<script src="../cc-script.js"></script> |
| 447 |
</head> |
</head> |
| 448 |
<body> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
| 449 |
<h1>]); |
<h1>]); |
| 450 |
$self->nl_text (q[WebHACC:Heading]); |
$self->nl_text (q[WebHACC:Heading]); |
| 451 |
$self->html ('</h1>'); |
$self->html (q[</h1><script> insertNavSections () </script>]); |
| 452 |
} # html_header |
} # html_header |
| 453 |
|
|
| 454 |
|
sub generate_input_section ($$) { |
| 455 |
|
my ($out, $cgi) = @_; |
| 456 |
|
|
| 457 |
|
my $options = sub ($) { |
| 458 |
|
my $context = shift; |
| 459 |
|
|
| 460 |
|
$out->html (q[<div class="details default"><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'block' ? 'none' : 'block'; parentNode.className = nextSibling.style.display == 'none' ? 'details' : 'details open'">]); |
| 461 |
|
$out->nl_text (q[Options]); |
| 462 |
|
$out->start_tag ('div'); |
| 463 |
|
|
| 464 |
|
if ($context eq 'url') { |
| 465 |
|
$out->start_tag ('p'); |
| 466 |
|
$out->start_tag ('label'); |
| 467 |
|
$out->start_tag ('input', type => 'checkbox', name => 'error-page', |
| 468 |
|
value => 1, |
| 469 |
|
($cgi->get_parameter ('error-page') |
| 470 |
|
? (checked => '') : ())); |
| 471 |
|
$out->nl_text ('Check error page'); |
| 472 |
|
$out->end_tag ('label'); |
| 473 |
|
} |
| 474 |
|
|
| 475 |
|
$out->start_tag ('p'); |
| 476 |
|
$out->start_tag ('label'); |
| 477 |
|
$out->nl_text (q[Content type]); |
| 478 |
|
$out->text (': '); |
| 479 |
|
$out->select ([ |
| 480 |
|
{value => '', label => 'As specified'}, |
| 481 |
|
{value => 'application/atom+xml'}, |
| 482 |
|
{value => 'application/xhtml+xml'}, |
| 483 |
|
{value => 'application/xml'}, |
| 484 |
|
{value => 'text/html'}, |
| 485 |
|
{value => 'text/xml'}, |
| 486 |
|
{value => 'text/css'}, |
| 487 |
|
{value => 'text/cache-manifest'}, |
| 488 |
|
{value => 'text/x-webidl'}, |
| 489 |
|
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
| 490 |
|
$out->end_tag ('label'); |
| 491 |
|
|
| 492 |
|
if ($context ne 'text') { |
| 493 |
|
$out->start_tag ('p'); |
| 494 |
|
$out->start_tag ('label'); |
| 495 |
|
$out->nl_text (q[Charset]); |
| 496 |
|
$out->text (q[: ]); |
| 497 |
|
$out->select ([ |
| 498 |
|
{value => '', label => 'As specified'}, |
| 499 |
|
{label => 'Japanese charsets', options => [ |
| 500 |
|
{value => 'Windows-31J'}, |
| 501 |
|
{value => 'Shift_JIS'}, |
| 502 |
|
{value => 'EUC-JP'}, |
| 503 |
|
{value => 'ISO-2022-JP'}, |
| 504 |
|
]}, |
| 505 |
|
{label => 'European charsets', options => [ |
| 506 |
|
{value => 'Windows-1252'}, |
| 507 |
|
{value => 'ISO-8859-1'}, |
| 508 |
|
{value => 'US-ASCII'}, |
| 509 |
|
]}, |
| 510 |
|
{label => 'Asian charsets', options => [ |
| 511 |
|
{value => 'Windows-874'}, |
| 512 |
|
{value => 'ISO-8859-11'}, |
| 513 |
|
{value => 'TIS-620'}, |
| 514 |
|
]}, |
| 515 |
|
{label => 'Unicode charsets', options => [ |
| 516 |
|
{value => 'UTF-8'}, |
| 517 |
|
{value => 'UTF-8n'}, |
| 518 |
|
]}, |
| 519 |
|
], name => 'charset', |
| 520 |
|
selected => scalar $cgi->get_parameter ('charset')); |
| 521 |
|
$out->end_tag ('label'); |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
if ($context eq 'text') { |
| 525 |
|
$out->start_tag ('p'); |
| 526 |
|
$out->start_tag ('label'); |
| 527 |
|
$out->nl_text ('Setting innerHTML'); |
| 528 |
|
$out->text (': '); |
| 529 |
|
$out->start_tag ('input', name => 'e', |
| 530 |
|
value => scalar $cgi->get_parameter ('e')); |
| 531 |
|
$out->end_tag ('label'); |
| 532 |
|
} |
| 533 |
|
|
| 534 |
|
$out->html (q[</div></div>]); |
| 535 |
|
}; # $options |
| 536 |
|
|
| 537 |
|
$out->start_section (id => 'input', title => 'Input'); |
| 538 |
|
$out->html (q[<script> insertNavSections ('input') </script>]); |
| 539 |
|
|
| 540 |
|
$out->start_section (id => 'input-url', title => 'By URL', |
| 541 |
|
parent_id => 'input'); |
| 542 |
|
$out->start_tag ('form', action => './#result-summary', |
| 543 |
|
'accept-charset' => 'utf-8', |
| 544 |
|
method => 'get'); |
| 545 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
| 546 |
|
|
| 547 |
|
$out->start_tag ('p'); |
| 548 |
|
$out->start_tag ('label'); |
| 549 |
|
$out->nl_text ('URL'); |
| 550 |
|
$out->text (': '); |
| 551 |
|
$out->start_tag ('input', |
| 552 |
|
name => 'uri', |
| 553 |
|
type => 'url', |
| 554 |
|
value => $cgi->get_parameter ('uri')); |
| 555 |
|
$out->end_tag ('label'); |
| 556 |
|
|
| 557 |
|
$out->start_tag ('p'); |
| 558 |
|
$out->start_tag ('button', type => 'submit'); |
| 559 |
|
$out->nl_text ('Check'); |
| 560 |
|
$out->end_tag ('button'); |
| 561 |
|
|
| 562 |
|
$options->('url'); |
| 563 |
|
|
| 564 |
|
$out->end_tag ('form'); |
| 565 |
|
$out->end_section; |
| 566 |
|
|
| 567 |
|
$out->end_tag ('fieldset'); |
| 568 |
|
|
| 569 |
|
## TODO: File upload |
| 570 |
|
|
| 571 |
|
$out->start_section (id => 'input-text', title => 'By direct input', |
| 572 |
|
parent_id => 'input'); |
| 573 |
|
$out->start_tag ('form', action => './#result-summary', |
| 574 |
|
'accept-charset' => 'utf-8', |
| 575 |
|
method => 'post'); |
| 576 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
| 577 |
|
|
| 578 |
|
$out->start_tag ('p'); |
| 579 |
|
$out->start_tag ('label'); |
| 580 |
|
$out->nl_text ('Document source to check'); |
| 581 |
|
$out->text (': '); |
| 582 |
|
$out->start_tag ('br'); |
| 583 |
|
$out->start_tag ('textarea', |
| 584 |
|
name => 's'); |
| 585 |
|
my $s = $cgi->get_parameter ('s'); |
| 586 |
|
$out->html ($htescape_value->($s)) if defined $s; |
| 587 |
|
$out->end_tag ('textarea'); |
| 588 |
|
$out->end_tag ('label'); |
| 589 |
|
|
| 590 |
|
$out->start_tag ('p'); |
| 591 |
|
$out->start_tag ('button', type => 'submit', |
| 592 |
|
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
| 593 |
|
$out->nl_text ('Check'); |
| 594 |
|
$out->end_tag ('button'); |
| 595 |
|
|
| 596 |
|
$options->('text'); |
| 597 |
|
|
| 598 |
|
$out->end_tag ('form'); |
| 599 |
|
$out->end_section; |
| 600 |
|
|
| 601 |
|
$out->script (q[ |
| 602 |
|
if (!document.webhaccNavigated && |
| 603 |
|
document.getElementsByTagName ('textarea')[0].value.length > 0) { |
| 604 |
|
showTab ('input-text'); |
| 605 |
|
document.webhaccNavigated = false; |
| 606 |
|
} |
| 607 |
|
]); |
| 608 |
|
|
| 609 |
|
$out->end_section; |
| 610 |
|
} # generate_input_section |
| 611 |
|
|
| 612 |
sub encode_url_component ($$) { |
sub encode_url_component ($$) { |
| 613 |
shift; |
shift; |
| 614 |
require Encode; |
require Encode; |