diff options
author | emkael <emkael@tlen.pl> | 2020-05-25 21:27:46 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-05-25 21:27:46 +0200 |
commit | 9133d012030ec8a875bed63d98346e97d7363df3 (patch) | |
tree | 46ccd1f7202261a4addd77dcd784c3088d89c1a7 /index.php | |
parent | d76e8702883dfb0a566ebaa810985e5d68fa2c84 (diff) |
Auto-run from location.hash
Fixes PZBS/smol#2
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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> |