parent
8c2d5fc6c2
commit
749602c097
@ -0,0 +1,56 @@ |
|||||||
|
package HexGrid::Dynamic; |
||||||
|
|
||||||
|
use v5.30; |
||||||
|
|
||||||
|
use Carp; |
||||||
|
use Data::Dumper; |
||||||
|
|
||||||
|
use feature "signatures"; |
||||||
|
no warnings "experimental::signatures"; |
||||||
|
|
||||||
|
$HexGrid::Dynamic::click_pin = <<EOS; |
||||||
|
function clickPin(pinId, containerId) { |
||||||
|
let popup = document.getElementById(pinId + '-popup'); |
||||||
|
popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible'; |
||||||
|
} |
||||||
|
EOS |
||||||
|
$HexGrid::Dynamic::toggle_coords = <<EOS; |
||||||
|
function toggleCoords(show) { |
||||||
|
for (var elem of document.getElementsByClassName('coords')) { |
||||||
|
elem.style.visibility = show ? 'visible' : 'hidden'; |
||||||
|
} |
||||||
|
} |
||||||
|
EOS |
||||||
|
|
||||||
|
$HexGrid::Dynamic::coords_toggler = <<EOS; |
||||||
|
<label for="show-coords-checkbox">Show coordinates</label> |
||||||
|
<input type="checkbox" checked id="show-coords-checkbox" onclick="toggleCoords(event.srcElement.checked)" /> |
||||||
|
EOS |
||||||
|
|
||||||
|
sub render_html($svg, $options = undef) |
||||||
|
{ |
||||||
|
my $document = "<!DOCTYPE html>"; |
||||||
|
$document .= "\n<html>\n<body>"; |
||||||
|
|
||||||
|
if($options) |
||||||
|
{ |
||||||
|
if (ref $options eq 'HASH') |
||||||
|
{ |
||||||
|
$document .= "\n<script>\n"; |
||||||
|
$document .= $HexGrid::Dynamic::click_pin if $options->{pin_popups}; |
||||||
|
$document .= $HexGrid::Dynamic::toggle_coords if $options->{toggle_coords}; |
||||||
|
$document .= "\n</script>\n"; |
||||||
|
$document .= $HexGrid::Dynamic::coords_toggler if $options->{toggle_coords}; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
carp("Options passed to HexGrid::Dynamic::render_html must be a hash ref"); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$document .= "\n" . $svg; |
||||||
|
$document .= "\n</body>\n</html>"; |
||||||
|
return $document; |
||||||
|
} |
||||||
|
1; |
Loading…
Reference in new issue