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

[4.0] [a11y] Add SkipTo Navigation plugin #24142

Merged
merged 22 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -0,0 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(496, 0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, '', '{"section_skipto":"2"}', 0, '0000-00-00 00:00:00', 0, 0),
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(496, 0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, '', '{"section_skipto":"2"}', 0, '1970-01-01 00:00:00', 0, 0),
16 changes: 16 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_skipto.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SKIPTO="System - Skip-To Navigation"
PLG_SYSTEM_SKIPTO_CONTENT="Content"
PLG_SYSTEM_SKIPTO_PAGE_OUTLINE="Page Outline"
PLG_SYSTEM_SKIPTO_SECTION="Site Section"
PLG_SYSTEM_SKIPTO_SECTION_ADMIN="Administrator (Backend)"
PLG_SYSTEM_SKIPTO_SECTION_BOTH="Both"
PLG_SYSTEM_SKIPTO_SECTION_SITE="Site (Frontend)"
PLG_SYSTEM_SKIPTO_SKIP_TO="Skip To"
PLG_SYSTEM_SKIPTO_SKIP_TO_AND_PAGE_OUTLINE="Skip To and Page Outline"
PLG_SYSTEM_SKIPTO_SKIP_TO_KEYBOARD="Skip To Keyboard Navigation"
PLG_SYSTEM_SKIPTO_XML_DESCRIPTION="The plugin creates a dropdown menu consisting of the links to the important places on a given web page. This makes it easier for keyboard and screen reader users to quickly jump to the desired location by simply choosing it from the list of options."
7 changes: 7 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_skipto.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SKIPTO="System - Skip-To Navigation"
PLG_SYSTEM_SKIPTO_XML_DESCRIPTION="The plugin creates a dropdown menu consisting of the links to the important places on a given web page. This makes it easier for keyboard and screen reader users to quickly jump to the desired location by simply choosing it from the list of options."
11 changes: 11 additions & 0 deletions build/build-modules-js/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@
"dist/metismenujs.min.js": "js/metismenujs.min.js",
"dist/metismenujs.min.js.map": "js/metismenujs.min.js.map"
}
},
"skipto": {
"name": "skipto",
"licenseFilename": "LICENSE.md",
"js": {
"src/js/skipTo.js": "js/skipTo.js",
"src/js/dropMenu.js": "js/dropMenu.js"
},
"css": {
"src/css/SkipTo.css": "css/SkipTo.css"
}
}
},
"errorPages": {
Expand Down
1 change: 1 addition & 0 deletions installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem
(493, 0, 'plg_extension_finder', 'plugin', 'finder', 'extension', 0, 1, 1, 0, '', '', 0, '0000-00-00 00:00:00', 0, 0),
(494, 0, 'plg_api-authentication_basic', 'plugin', 'basic', 'api-authentication', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0),
(495, 0, 'plg_webservices_content', 'plugin', 'content', 'webservices', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0),
(496, 0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, '', '{"section_skipto":"2"}', 0, '0000-00-00 00:00:00', 0, 0),
(509, 0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, '', '', 0, '0000-00-00 00:00:00', 0, 0),
(510, 0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', 0, '0000-00-00 00:00:00', 0, 0),
(600, 802, 'English (en-GB)', 'language', 'en-GB', '', 0, 1, 1, 1, '', '', 0, '0000-00-00 00:00:00', 0, 0),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(493, 0, 'plg_extension_finder', 'plugin', 'finder', 'extension', 0, 1, 1, 0, '', '', 0, '1970-01-01 00:00:00', 0, 0),
(494, 0, 'plg_api-authentication_basic', 'plugin', 'basic', 'api-authentication', 0, 1, 1, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0),
(495, 0, 'plg_webservices_content', 'plugin', 'content', 'webservices', 0, 1, 1, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0),
(496, 0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, '', '{"section_skipto":"2"}', 0, 'q970-01-01 00:00:00', 0, 0),
(600, 802, 'English (en-GB)', 'language', 'en-GB', '', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0),
(601, 802, 'English (en-GB)', 'language', 'en-GB', '', 1, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0),
(700, 0, 'files_joomla', 'file', 'joomla', '', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"metismenujs": "^1.0.3",
"popper.js": "^1.14.3",
"punycode": "1.4.1",
"skipto": "^2.0.3",
"tinymce": "4.8.3"
},
"devDependencies": {
Expand Down
106 changes: 106 additions & 0 deletions plugins/system/skipto/skipto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.skipto
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;

/**
* Skipto plugin to add accessible keyboard navigation to the administrator template.
*
* @since __DEPLOY_VERSION__
*/
class PlgSystemSkipto extends CMSPlugin
{
/**
* If true, language files will be loaded automatically.
*
* @var boolean
* @since 4.0.0
*/
protected $autoloadLanguage = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this since language is loaded conditionally on line 80.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone has an idea why line 80 is required by the way I'll buy them a beer. Because for the life of me I don't understand why the variable here isn't working properly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 80 should not be necessary, because autloadLanguage does exactly the same only in the constructor...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there is a bug somewhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely a bug somewhere. I just didn't have the time/energy to debug it at 1am (i put about 15 minutes into it and succeeded in being very confused :) - only about half the system plugins language files were actually being loaded)


/**
* Application object.
*
* @var JApplicationCms
* @since 4.0.0
*/
protected $app;

/**
* Add the css and javascript for the skipto navigation menu
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onBeforeCompileHead()
{
$section = (int) $this->params->get('section_skipto', 2);
$current_section = 0;

// Get the document object.
$document = Factory::getDocument();

try
{
$app = Factory::getApplication();

if ($app->isClient('administrator'))
{
$current_section = 2;
}
elseif ($app->isClient('site'))
{
$current_section = 1;
}
}
catch (Exception $exc)
{
$current_section = 0;
}

if (!($current_section & $section))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!($current_section & $section))
if (!($current_section && $section))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is a direct copy paste from the yubikey plugin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we don't mean to do this http://www.php.net/manual/en/language.operators.bitwise.php - even if it does work. I'd change yubikey to match what @Quy is suggesting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work. The suggestion above does not.

{
return false;
}

{
// Add strings for translations in Javascript.
$this->loadLanguage();
Factory::getDocument()->addScriptOptions(
'skipto-settings',
[
'settings' => [
'skipTo' => [
'buttonLabel' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO'),
'buttonDivTitle' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO_KEYBOARD'),
'menuLabel' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO_AND_PAGE_OUTLINE'),
'landmarksLabel' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO'),
'headingsLabel' => Text::_('PLG_SYSTEM_SKIPTO_PAGE_OUTLINE'),
'contentLabel' => Text::_('PLG_SYSTEM_SKIPTO_CONTENT'),
]
]
]
);
HTMLHelper::_('script', 'vendor/skipto/dropMenu.js', ['version' => 'auto', 'relative' => true], ['defer' => true]);
HTMLHelper::_('script', 'vendor/skipto/skipTo.js', ['version' => 'auto', 'relative' => true], ['defer' => true]);
HTMLHelper::_('stylesheet', 'vendor/skipto/SkipTo.css', ['version' => 'auto', 'relative' => true]);

$document->addScriptDeclaration("document.addEventListener('DOMContentLoaded', function() {
window.SkipToConfig = Joomla.getOptions('skipto-settings');
window.skipToMenuInit();
});");
}
}
}
36 changes: 36 additions & 0 deletions plugins/system/skipto/skipto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="system" method="upgrade">
<name>plg_system_skipto</name>
<author>Joomla! Project</author>
<creationDate>2019-2-27</creationDate>
<copyright>(C) 2005 - 2019 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_SYSTEM_SKIPTO_XML_DESCRIPTION</description>
<files>
<filename plugin="skipto">skipto.php</filename>
</files>
<languages>
<language tag="en-GB">language/en-GB/en-GB.plg_system_skipto.ini</language>
<language tag="en-GB">language/en-GB/en-GB.plg_system_skipto.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="section_skipto"
type="list"
label="PLG_SYSTEM_SKIPTO_SECTION"
default="2"
filter="integer"
>
<option value="1">PLG_SYSTEM_SKIPTO_SECTION_SITE</option>
<option value="2">PLG_SYSTEM_SKIPTO_SECTION_ADMIN</option>
<option value="3">PLG_SYSTEM_SKIPTO_SECTION_BOTH</option>
</field>
</fieldset>
</fields>
</config>
</extension>