Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
spoilers: Fix selections and simplify link implementation.
Tim Abbottdd3767981dea
diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.jsindex 4dd31110627..9d02349d75b 100644--- a/frontend_tests/node_tests/rendered_markdown.js+++ b/frontend_tests/node_tests/rendered_markdown.js@@ -207,7 +207,7 @@ run_test('spoiler-header', () => {// Test that button gets appened to a spoiler headerconst label = 'My Spoiler Header';- const toggle_button_html = '<a class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></a>';+ const toggle_button_html = '<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';$header.html(label);rm.update_elements($content);assert.equal(toggle_button_html + label, $header.html());@@ -220,7 +220,7 @@ run_test('spoiler-header-empty-fill', () => {$content.set_find_results('div.spoiler-header', $array([$header]));// Test that an empty header gets the default text applied (through i18n filter)- const toggle_button_html = '<a class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></a>';+ const toggle_button_html = '<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';$header.html('');rm.update_elements($content);assert.equal(toggle_button_html + '<p>translated: Spoiler</p>', $header.html());diff --git a/static/js/rendered_markdown.js b/static/js/rendered_markdown.jsindex e04a2ececdf..b4154b9a163 100644--- a/static/js/rendered_markdown.js+++ b/static/js/rendered_markdown.js@@ -170,7 +170,7 @@ exports.update_elements = (content) => {}// Add the expand/collapse button to spoiler blocks- const toggle_button_html = '<a class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></a>';+ const toggle_button_html = '<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';$(this).prepend(toggle_button_html);});diff --git a/static/js/spoilers.js b/static/js/spoilers.jsindex 27cdec8bcb8..b343a3fff2a 100644--- a/static/js/spoilers.js+++ b/static/js/spoilers.js@@ -40,11 +40,15 @@ exports.initialize = function () {const spoiler_content = $(this).siblings(".spoiler-content");const target = $(e.target);- // Spoiler headers can contain markdown, including links. We follow the link- // and don't expand the spoiler if a link has been clicked (unless it's the dropdown arrow)- // This can be accomplished by just breaking from this function before preventing default- // or toggling the state of the spoiler block.- if (target.is('a') && !target.hasClass('.spoiler-button')) {+ // Spoiler headers can contain markdown, including links. We+ // return so that clicking such links will be be processed by+ // the browser rather than opening the header.+ if (target.is('a')) {+ return;+ }++ // Allow selecting text inside a spoiler header.+ if (document.getSelection().type === "Range") {return;}