From 32248e9e3643c7dbcbcdbb9fa5079d7cda73f89d Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 30 Oct 2016 03:04:57 -0400 Subject: [PATCH] Fix UI "clear" button to clear URL state --- frontend/main.ts | 3 ++- frontend/url.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/main.ts b/frontend/main.ts index ca0441f7df..9ff92f081c 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -8,7 +8,7 @@ declare var $: any; import { setup_animation } from "./animation"; import Audio from "./audio"; -import { decode_url_hash, get_audio_api_url, set_url_hash } from "./url"; +import { clear_url_hash, decode_url_hash, get_audio_api_url, set_url_hash } from "./url"; import { RawSentence, FilteredSentence } from "./sentence"; const INPUT = 'input#jungle'; @@ -75,6 +75,7 @@ function install_events() { $('button#clear').on('click', function(ev: any): any { $(INPUT).val(''); // ESC key. (window).audio.stop(); + clear_url_hash(); ev.preventDefault(); return false; }); diff --git a/frontend/url.ts b/frontend/url.ts index 93b63039bf..a1fca25511 100644 --- a/frontend/url.ts +++ b/frontend/url.ts @@ -13,6 +13,13 @@ export function get_audio_api_url(sentence: FilteredSentence) : string { return `/speak?v=trump&vol=3&s=${encoded}`; } +/** + * Reset the URL. + */ +export function clear_url_hash() { + window.history.replaceState(null, null, '/'); +} + /** * Sentence -> Persistent URL hash */