Skip to content
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

Update accessibilty #91

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@
{% endblock %}
</div>
</div>
{% set script_snippet = h.opendata_theme_get_footer_script_snippet() %}
{% if script_snippet %}
{{ script_snippet }}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@
{% endblock %}
</div>
</div>
{% set script_snippet = h.opendata_theme_get_footer_script_snippet() %}
{% if script_snippet %}
{{ script_snippet }}
{% endif %}
{% endblock %}
92 changes: 92 additions & 0 deletions ckanext/opendata_theme/opengov_custom_theme/assets/js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Close popover on pressing Escape key
$(document).on('keydown', function (e) {
if (e.key === "Escape") {
$('.popover').each(function () {
$(this).popover('hide');
$(this).data('bs.popover').inState.click = false;
});
}
});

// Trap focus inside api-info modal
$(document).ready(function () {
$('a[data-module="api-info"]').on('click', function () {
trapApiInfoEmbed();
});

$('a[data-module="api-info"]').on('keyup', function (e) {
if (e.key === 'Enter') {
trapApiInfoEmbed();
}
});

function trapApiInfoEmbed() {
const modal = $(`#api-info-embed`);
if (modal.length) {
// Trap focus within the modal
trapFocus(modal);
// When closed remove event handlers
modal.find('.close').on('click', function () {
modal.off('keydown');
$('[data-module="api-info"]').focus();
});
}
}
});

// Trap focus inside resource-view-embed modal
$(document).ready(function () {
$('a[data-module="resource-view-embed"]').on('click', function () {
const modalId = $(this).data('module-id');
trapResourceViewEmbed(modalId);
});

$('a[data-module="resource-view-embed"]').on('keyup', function (e) {
if (e.key === 'Enter') {
const modalId = $(this).data('module-id');
trapResourceViewEmbed(modalId);
}
});

function trapResourceViewEmbed(modalId) {
const modal = $(`#embed-${modalId}`);
if (modal.length) {
// Trap focus within the modal
trapFocus(modal);
// When closed remove event handlers
modal.find('.close').on('click', function () {
modal.off('keydown');
$('[data-module="resource-view-embed"]').focus();
});
}
}
});

function trapFocus(modal) {
const focusableElements = modal.find('a, button, input, textarea');
const firstElement = focusableElements.first();
const lastElement = focusableElements.last();

// Focus on first element when the modal opens
modal.on('shown.bs.modal', function () {
firstElement.focus();
});

modal.on('keydown', function (e) {
if (e.key === 'Tab') {
if (e.shiftKey) {
// Shift + Tab
if (document.activeElement === firstElement[0]) {
e.preventDefault();
lastElement.focus();
}
} else {
// Tab
if (document.activeElement === lastElement[0]) {
e.preventDefault();
firstElement.focus();
}
}
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
theme-js:
filters: rjsmin
output: opengov_custom_theme/%(version)s_theme.js
extra:
preload:
- base/main
contents:
- js/theme.js
1 change: 1 addition & 0 deletions ckanext/opendata_theme/opengov_custom_theme/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OpenDataThemePlugin(plugins.SingletonPlugin):
# IConfigurer
def update_config(self, ckan_config):
toolkit.add_template_directory(ckan_config, 'templates')
toolkit.add_resource('assets', 'opengov_custom_theme')

def update_config_schema(self, schema):
ignore_missing = toolkit.get_validator('ignore_missing')
Expand Down
15 changes: 14 additions & 1 deletion ckanext/opendata_theme/opengov_custom_theme/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

{% block skip %}
<div class="visually-hidden-focusable skip-content"><a href="#content">{{ _('Skip to content') }}</a></div>
{% endblock %}
{% endblock %}

{% block styles %}
{{ super() }}
{% asset 'opengov_custom_theme/theme-js' %}
{% endblock %}

{%- block scripts %}
{{ super() }}
{% set script_snippet = h.opendata_theme_get_footer_script_snippet() %}
{% if script_snippet %}
{{ script_snippet }}
{% endif %}
{% endblock -%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% import "macros/form.html" as form %}

{% block form %}
<form id="user-register-form" action="" method="post" enctype="multipart/form-data">
{{ form.errors(error_summary) }}

{% block core_fields %}
{% block required_core_fields %}
{{ form.input("name", id="field-username", label=_("Username"), placeholder=_("username"), value=data.name, error=errors.name, classes=["control-medium"], is_required=True) }}
{{ form.input("fullname", id="field-fullname", label=_("Full Name"), placeholder=_("Joe Bloggs"), value=data.fullname, error=errors.fullname, classes=["control-medium"]) }}
{{ form.input("email", id="field-email", label=_("Email"), type="email", placeholder=_("[email protected]"), value=data.email, error=errors.email, classes=["control-medium"], is_required=True) }}
{{ form.input("password1", id="field-password", label=_("Password"), type="password", placeholder="••••••••", value=data.password1, error=errors.password1, classes=["control-medium"], is_required=True) }}
{{ form.input("password2", id="field-confirm-password", label=_("Confirm Password"), type="password", placeholder="••••••••", value=data.password2, error=errors.password2, classes=["control-medium"], is_required=True) }}
{% endblock %}

{% block optional_core_fields %}
{% set is_upload = data.image_url and not data.image_url.startswith('http') %}
{% set is_url = data.image_url and data.image_url.startswith('http') %}
{{ form.image_upload(data, errors, is_upload_enabled=h.uploads_enabled(), is_url=is_url, is_upload=is_upload, upload_label=_('Profile picture'), url_label=_('Profile picture URL')) }}
{% endblock %}
{% endblock %}

{% block extra_fields %}
{% endblock %}

{% block captcha %}
{% if g.recaptcha_publickey %}
{% snippet "user/snippets/recaptcha.html", public_key=g.recaptcha_publickey %}
{% endif %}
{% endblock %}

{{ form.required_message() }}

<div class="form-actions">
{% block form_actions %}
<button class="btn btn-primary" type="submit" name="save">{{ _("Create Account") }}</button>
{% endblock %}
</div>
</form>
{% endblock %}
Loading