summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-05-25 21:27:46 +0200
committeremkael <emkael@tlen.pl>2020-05-25 21:27:46 +0200
commit9133d012030ec8a875bed63d98346e97d7363df3 (patch)
tree46ccd1f7202261a4addd77dcd784c3088d89c1a7
parentd76e8702883dfb0a566ebaa810985e5d68fa2c84 (diff)
Auto-run from location.hash
Fixes PZBS/smol#2
-rw-r--r--index.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/index.php b/index.php
index 98d5b23..b47a9ef 100644
--- a/index.php
+++ b/index.php
@@ -141,6 +141,7 @@
if(!$discrete) {
echo '<br /><a class="btn" href="teamy.php?n='.$n.'">Pobierz tabelÄ™ dla programu JFR Teamy</a>';
}
+ echo '<input type="hidden" id="formHash" value="' . $n . ($discrete ? '|dyskretna' : '') . '" />';
}
?>
@@ -153,5 +154,37 @@
</div> <!-- /container -->
+ <script type="text/javascript">
+ var hashTrigger = true;
+ var formHash = document.getElementById('formHash');
+ var onHash = function(e) {
+ if (hashTrigger) {
+ var hash = location.hash.replace(/^#/, '');
+ if (hash) {
+ var hashParts = hash.split('|');
+ var boards = parseInt(hashParts[0]);
+ var discrete = (['dyskretna', 'calkowita'].indexOf(hashParts[1]) > -1);
+ document.forms['boardNumForm'].n.value = boards;
+ document.forms['boardNumForm'].discrete.value = (discrete ? 1 : 0);
+ if (e.type != 'load' || !formHash) {
+ document.forms['boardNumForm'].submit();
+ }
+ }
+ } else {
+ hashTrigger = true;
+ }
+ }
+ window.onload = onHash;
+ window.onhashchange = onHash;
+ if (formHash) {
+ var fromForm = formHash.value;
+ if (fromForm) {
+ hashTrigger = false;
+ location.hash = fromForm;
+ formHash.value = '';
+ }
+ }
+ </script>
+
</body>
</html>