From 2343512bb7bdcab4c6ed67e45d01af3ea150aa82 Mon Sep 17 00:00:00 2001 From: Ali Abid Date: Thu, 11 Feb 2021 09:50:38 -0800 Subject: [PATCH] add example hyperlinking --- gradio/static/js/gradio.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gradio/static/js/gradio.js b/gradio/static/js/gradio.js index 3eccfeab34..4f179cb5e5 100644 --- a/gradio/static/js/gradio.js +++ b/gradio/static/js/gradio.js @@ -251,6 +251,17 @@ function gradio(config, fn, target, example_file_path) { $(".examples_body > tr").removeClass("current_example"); $(".examples_body > tr[row='" + example_id + "'").addClass("current_example"); io_master.current_example = example_id; + window.location.hash = example_id + 1; + } + function hash_handler() { + let hash = window.location.hash; + if (hash == "") { + return; + } + hash = hash.substring(1) + if (!isNaN(parseInt(hash))) { + load_example(parseInt(hash) - 1); + } } function next_example() { current_example = io_master.current_example; @@ -324,6 +335,8 @@ function gradio(config, fn, target, example_file_path) { target.find(".pages").append(html); } load_page(); + window.onhashchange = hash_handler; + hash_handler(); target.on("click", ".examples_body > tr", function() { let example_id = parseInt($(this).attr("row")); load_example(example_id);