Skip to content

Always update the url bar #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ <h3>Examples</h3>
<script type="text/javascript" src="js/syntree.js"></script>
<script type="text/javascript">

function set_url() {
window.location.hash = "i=" +
encodeURIComponent(document.getElementById("i").value);
};

function handler(font_size_update, vert_space_update, hor_space_update) {
try {
// Initialize the various options.
Expand Down Expand Up @@ -148,7 +153,8 @@ <h3>Examples</h3>
var img = go(str, font_size, term_font, nonterm_font, vert_space, hor_space, color, term_lines);
$("#image-goes-here").empty();
$("#image-goes-here").append(img);


set_url();
} catch (err) {
if (debug) {
throw(err);
Expand All @@ -169,13 +175,22 @@ <h3>Examples</h3>
$("#font-style-radio, #term-font-check, #nonterm-font-check").buttonset();
$("#accordion").accordion({collapsible: true, icons: false, autoHeight: false});

// Try to load old-style links from the querystring.
try {
var qs = decodeURIComponent(window.location.search.slice(1));
qs = qs.replace(/^i=/,"");
qs = qs.replace(/\+/g," ");
if (qs == "") throw "";
document.getElementById("i").value = qs;
} catch (err) {}

// Try to load tree from hash.
try {
var qs = decodeURIComponent(window.location.hash);
qs = qs.replace(/^#i=/,"");
if (qs == "") throw "";
document.getElementById("i").value = qs;
} catch (err) {}

handler();

Expand All @@ -189,8 +204,7 @@ <h3>Examples</h3>
var loc = window.location.href;
loc = loc.replace(window.location.search, "");

window.prompt ("Link for this tree:", loc + "?i=" +
encodeURIComponent(document.getElementById("i").value));
window.prompt ("Link for this tree:", window.location.href);
return false;
});
$("#font-size-slider").bind("slide", function (event, ui) {
Expand All @@ -206,4 +220,4 @@ <h3>Examples</h3>
</script>

</body>
</html>
</html>