Skip to content
Permalink
Browse files

Improved screen reader support

  • Loading branch information
Eric Chernoff
Eric Chernoff committed Dec 6, 2018
1 parent 6ff6aec commit ab575c53a22bcee1c4066ce2eafa611169f7fbb3
@@ -262,6 +262,9 @@ sub pack_luggage {

}

# also save their screen reader preference to the utility belt, for template processing
$$luggage{belt}->{screen_reader_mode} = $$luggage{session}->screen_reader_mode( $$luggage{db} );

# if we are using a $uri_base in the actual URI, revert the URI to index.html
# We need to do this after the authentication step, to make sure the login form gets the
# proper URI
@@ -250,6 +250,63 @@ sub get_instance_db_object {
return $correct_db;
}

# centralized method to handle interacting with otstatedata.screen_reader_users
# this is where we store the option to enable that screen_reader_mode, which
# tells our templates (skeletons, tool_controls.tt, form_elments.tt mainly)
# and omnitool_routines.js (enable_chosen)
# to disable certain features so that the UI is friendlier to screen reader software
sub screen_reader_mode {
my $self = shift;

# required arg is the db connection, because we may not have it in $self due to
# re-blessing of earlier session (see new())
# optional arg is the task (get or toggle, default is 'get')
my ($db,$task) = @_;

return 'Disabled' if !$db;

$task ||= 'get';
# sanity
my $username = $self->{username};
my $screen_reader_mode;

# get = is screen reader mode enabled?
if ($task eq 'get') {

# do the lookup
($screen_reader_mode) = $db->quick_select(qq{
select screen_reader_mode from otstatedata.screen_reader_users
where username=?
},[$username]);

# no record? default mode is Disabled
$screen_reader_mode ||= 'Disabled';

# toggle = change the mode
} else {
# what is the current mode?
$screen_reader_mode = $self->screen_reader_mode($db);
# change it to the opposite
if ($screen_reader_mode eq 'Enabled') {
$screen_reader_mode = 'Disabled';
} else {
$screen_reader_mode = 'Enabled';
}

# basic table, primary key is the username, they may not have a
# record yet, so replace is our friend
$db->do_sql(qq{
replace into otstatedata.screen_reader_users
(username, screen_reader_mode) values (?,?)
},[$username, $screen_reader_mode]);

}

# return our current screen_reader_mode
return $screen_reader_mode;

}

# method to serialize this object and save to our database / data store
# supports update now, for possibly keeping tools' search states here too ;)
sub save {
@@ -422,9 +422,24 @@ sub get_instance_info {
$$info_hashref{default_tool} = '/tools/'.$self->{luggage}{session}{tools}{$default_tool}{uri_path_base};
}

# tell omnitool_routines about their screen reader mode preference
$$info_hashref{screen_reader_mode} = $self->{luggage}{belt}->{screen_reader_mode};

return $info_hashref;
}

# endpoint method for setting a new screen reader mode preference
# please see toggle_screen_reader_mode() in omnitool_routines.js
sub toggle_screen_reader_mode {
my $self = shift;

# easy call to the method in the session object
my $new_screen_reader_mode = $self->{luggage}{session}->screen_reader_mode( $self->{luggage}{db}, 'toggle');

$self->{luggage}{belt}->mr_zebra('Accessibility mode set to '.$new_screen_reader_mode,2);

}

# method to load all the javascript classes used by this application
# we do this here to avoid loading and reloading via complex AJAX
# called at the bottom of our HTML skeleton
@@ -1036,6 +1036,11 @@ sub template_process {
# default tag_style to regular, [% %]
$args{tag_style} ||= 'template';

# make sure the template know if they have screen reader mode enabled
# this matters for the skeletons (default.tt, top_menu_skeleton.tt) as well as tools_controls.tt
# this attribute is set in pack_luggage after their session is created / revived
$args{template_vars}{screen_reader_mode} = $self->{screen_reader_mode};

# crank up the template toolkit object, and set it up to save to the $output variable
$output = '';
$tt = Template->new({

0 comments on commit ab575c5

Please sign in to comment.
You can’t perform that action at this time.