From b7f8055edea4350f880dde641447542bbfeb627b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 8 Nov 2020 18:23:12 -0800 Subject: [PATCH 1/3] Fixes review/comment/quote tabs in create status form --- bookwyrm/static/js/shared.js | 18 +++++++++++++-- bookwyrm/templates/feed.html | 2 +- .../templates/snippets/create_status.html | 22 ++++++++++++++----- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index eb4ab677b..e07835638 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -34,6 +34,22 @@ function rate_stars(e) { function tabChange(e) { var target = e.target.closest('li') var identifier = target.getAttribute('data-id'); + + var parent_element = target.parentElement + var tabs = parent_element.getElementsByTagName('label'); + for (i = 0; i < tabs.length; i++) { + var tab = tabs[i].parentElement; + if (tab.getAttribute('data-id') == identifier) { + tab.className += ' is-active'; + } else { + tab.className = tab.className.replace('is-active', ''); + } + } +} + +function nestedTabChange(e) { + var target = e.target.closest('li') + var identifier = target.getAttribute('data-id'); var parent_element = target.parentElement.closest('li').parentElement; var tabs = parent_element.getElementsByTagName('label'); @@ -45,8 +61,6 @@ function tabChange(e) { tab.className = tab.className.replace('is-active', ''); } } - - var el = document.getElementById(identifier); } function ajaxPost(form) { diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index bc533db45..ecdce4ab2 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -21,7 +21,7 @@ diff --git a/bookwyrm/templates/snippets/create_status.html b/bookwyrm/templates/snippets/create_status.html index f8c5b3cf1..e36b1b194 100644 --- a/bookwyrm/templates/snippets/create_status.html +++ b/bookwyrm/templates/snippets/create_status.html @@ -2,15 +2,27 @@ {% load fr_display %}
-
@@ -22,7 +34,7 @@
- {% include 'snippets/create_status_form.html' with type="comment" placeholder="Some thougts on '"|add:book.title|add:"'" %} + {% include 'snippets/create_status_form.html' with type="comment" placeholder="Some thoughts on '"|add:book.title|add:"'" %}
From b7bc089d8616e3551f7a044cb82697e7268a5c09 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 8 Nov 2020 19:09:29 -0800 Subject: [PATCH 2/3] Improves tabbing javascript for create status tabs --- bookwyrm/static/js/shared.js | 23 +++++++++---------- .../templates/snippets/shelve_button.html | 9 -------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index e07835638..b4f6589ec 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -32,26 +32,25 @@ function rate_stars(e) { } function tabChange(e) { - var target = e.target.closest('li') - var identifier = target.getAttribute('data-id'); + var target = e.target.closest('li'); - var parent_element = target.parentElement + var parent_element = target.parentElement; var tabs = parent_element.getElementsByTagName('label'); - for (i = 0; i < tabs.length; i++) { - var tab = tabs[i].parentElement; - if (tab.getAttribute('data-id') == identifier) { - tab.className += ' is-active'; - } else { - tab.className = tab.className.replace('is-active', ''); - } - } + + parent_element.querySelectorAll('[aria-selected="true"]') + .forEach(t => t.setAttribute("aria-selected", false)); + e.target.parentElement.setAttribute("aria-selected", true); + + parent_element.querySelectorAll('li') + .forEach(t => t.className=''); + target.className += ' is-active'; } function nestedTabChange(e) { var target = e.target.closest('li') var identifier = target.getAttribute('data-id'); - var parent_element = target.parentElement.closest('li').parentElement; + var parent_element = target.parentElement.closest('li').parentElement; var tabs = parent_element.getElementsByTagName('label'); for (i = 0; i < tabs.length; i++) { var tab = tabs[i].parentElement; diff --git a/bookwyrm/templates/snippets/shelve_button.html b/bookwyrm/templates/snippets/shelve_button.html index a2938ad51..ff0c660fb 100644 --- a/bookwyrm/templates/snippets/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button.html @@ -38,14 +38,6 @@ From c37c6aae4057217dbc92c046cf41c9c8a2e8d8ec Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 8 Nov 2020 19:34:41 -0800 Subject: [PATCH 3/3] nested covers tabs should work with screen reader --- bookwyrm/static/js/shared.js | 38 ++++++++++++------------------------ bookwyrm/templates/feed.html | 8 +++++++- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index b4f6589ec..5be6ed632 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -31,35 +31,23 @@ function rate_stars(e) { return true; } -function tabChange(e) { - var target = e.target.closest('li'); - - var parent_element = target.parentElement; - var tabs = parent_element.getElementsByTagName('label'); - - parent_element.querySelectorAll('[aria-selected="true"]') - .forEach(t => t.setAttribute("aria-selected", false)); - e.target.parentElement.setAttribute("aria-selected", true); - - parent_element.querySelectorAll('li') - .forEach(t => t.className=''); - target.className += ' is-active'; -} - -function nestedTabChange(e) { +function tabChange(e, nested) { var target = e.target.closest('li') var identifier = target.getAttribute('data-id'); - var parent_element = target.parentElement.closest('li').parentElement; - var tabs = parent_element.getElementsByTagName('label'); - for (i = 0; i < tabs.length; i++) { - var tab = tabs[i].parentElement; - if (tab.getAttribute('data-id') == identifier) { - tab.className += ' is-active'; - } else { - tab.className = tab.className.replace('is-active', ''); - } + if (nested) { + var parent_element = target.parentElement.closest('li').parentElement; + } else { + var parent_element = target.parentElement; } + + parent_element.querySelectorAll('[aria-selected="true"]') + .forEach(t => t.setAttribute("aria-selected", false)); + target.querySelector('[role="tab"]').setAttribute("aria-selected", true); + + parent_element.querySelectorAll('li') + .forEach(t => t.className=''); + target.className = 'is-active'; } function ajaxPost(form) { diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index ecdce4ab2..46e7bc2a8 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -21,7 +21,13 @@