Skip to content

Commit

Permalink
Fixes based on @Fedik's feedback!
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchaboryk committed Feb 9, 2024
1 parent 7fd9040 commit 6674a90
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 232 deletions.
4 changes: 3 additions & 1 deletion administrator/language/en-GB/plg_system_jooa11y.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ PLG_SYSTEM_JOOA11Y_FIELD_LINKS_ADVANCED_DESC="Show Links (Advanced) toggle in Se
PLG_SYSTEM_JOOA11Y_FIELD_COLOUR_FILTER="Colour Filter"
PLG_SYSTEM_JOOA11Y_FIELD_COLOUR_FILTER_DESC="Show Colour Filter toggle in Settings panel. Colour filters help identify potential color combinations that may be difficult for people to distinguish."
PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS="Extra Properties"
PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS_DESC="Pass additional (boolean) properties to customize. Use a comma to seperate multiple key/value pairs. Refer to <a href="https://sa11y.netlify.app/developers/props/">documentation.</a>"
PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS_DESC="Pass additional properties to customize. Provide a valid key/value pair. Refer to <a href="https://sa11y.netlify.app/developers/props/">documentation</a>."
PLG_SYSTEM_JOOA11Y_KEY="Key"
PLG_SYSTEM_JOOA11Y_VALUE="Value"
2 changes: 1 addition & 1 deletion administrator/language/en-GB/plg_system_jooa11y.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_JOOA11Y="System - Joomla Accessibility Checker"
PLG_SYSTEM_JOOA11Y_XML_DESCRIPTION="The Joomla Accessibility Checker visually highlights common accessibility and usability issues. Geared towards content authors, the plugin identifies errors or warnings and provides guidance on how to fix them."
PLG_SYSTEM_JOOA11Y_XML_DESCRIPTION="The Joomla Accessibility Checker visually highlights common accessibility and usability issues. Geared towards content authors, the plugin identifies errors or warnings and provides guidance on how to fix them. Please be aware that this plugin does not offer an exhaustive analysis of your website, nor does it automatically ensure your website's accessibility. It's important to select a theme that is inherently accessible to ensure your site meets accessibility standards."
161 changes: 2 additions & 159 deletions build/build-modules-js/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,169 +785,12 @@
"name": "sa11y",
"type": "script",
"uri": "sa11y.esm.min.js",
"attributes": {
"type": "module"
}
},
{
"name": "Sa11yLangEn",
"type": "script",
"uri": "en.js"
},
{
"name": "Sa11yLangBg",
"type": "script",
"uri": "bg.js"
},
{
"name": "Sa11yLangCs",
"type": "script",
"uri": "cs.js"
},
{
"name": "Sa11yLangDa",
"type": "script",
"uri": "da.js"
},
{
"name": "Sa11yLangDe",
"type": "script",
"uri": "de.js"
},
{
"name": "Sa11yLangEl",
"type": "script",
"uri": "el.js"
},
{
"name": "Sa11yLangEn",
"type": "script",
"uri": "en.js"
},
{
"name": "Sa11yLangEnUS",
"type": "script",
"uri": "enUS.js"
},
{
"name": "Sa11yLangEs",
"type": "script",
"uri": "es.js"
},
{
"name": "Sa11yLangEt",
"type": "script",
"uri": "et.js"
},
{
"name": "Sa11yLangFi",
"type": "script",
"uri": "fi.js"
},
{
"name": "Sa11yLangFr",
"type": "script",
"uri": "fr.js"
"importmap": true
},
{
"name": "sa11yCSS",
"name": "sa11y",
"type": "style",
"uri": "sa11y.min.css"
},
{
"name": "Sa11yLangHu",
"type": "script",
"uri": "hu.js"
},
{
"name": "Sa11yLangId",
"type": "script",
"uri": "id.js"
},
{
"name": "Sa11yLangIt",
"type": "script",
"uri": "it.js"
},
{
"name": "Sa11yLangJa",
"type": "script",
"uri": "ja.js"
},
{
"name": "Sa11yLangKo",
"type": "script",
"uri": "ko.js"
},
{
"name": "Sa11yLangLt",
"type": "script",
"uri": "lt.js"
},
{
"name": "Sa11yLangLv",
"type": "script",
"uri": "lv.js"
},
{
"name": "Sa11yLangNb",
"type": "script",
"uri": "nb.js"
},
{
"name": "Sa11yLangNl",
"type": "script",
"uri": "nl.js"
},
{
"name": "Sa11yLangPl",
"type": "script",
"uri": "pl.js"
},
{
"name": "Sa11yLangPtBR",
"type": "script",
"uri": "ptBR.js"
},
{
"name": "Sa11yLangPtPT",
"type": "script",
"uri": "ptPT.js"
},
{
"name": "Sa11yLangRo",
"type": "script",
"uri": "ro.js"
},
{
"name": "Sa11yLangSk",
"type": "script",
"uri": "sk.js"
},
{
"name": "Sa11yLangSl",
"type": "script",
"uri": "sl.js"
},
{
"name": "Sa11yLangSv",
"type": "script",
"uri": "sv.js"
},
{
"name": "Sa11yLangTr",
"type": "script",
"uri": "tr.js"
},
{
"name": "Sa11yLangUa",
"type": "script",
"uri": "ua.js"
},
{
"name": "Sa11yLangZh",
"type": "script",
"uri": "zh.js"
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"punycode": "^2.3.0",
"qrcode-generator": "^1.4.4",
"roboto-fontface": "^0.10.0",
"sa11y": "^3.0.7",
"sa11y": "^3.0.8",
"shepherd.js": "^11.2.0",
"short-and-sweet": "^1.0.4",
"skipto": "^4.1.7",
Expand Down Expand Up @@ -131,4 +131,4 @@
"stylelint-order": "^5.0.0",
"stylelint-scss": "^4.7.0"
}
}
}
17 changes: 11 additions & 6 deletions plugins/system/jooa11y/jooa11y.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@
filter="string"
/>
<field
name="extraProps"
type="textarea"
label="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS"
description="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS_DESC"
filter="string"
/>
name="extraProps"
type="subform"
multiple="true"
label="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS"
description="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS_DESC"
>
<form>
<field type="text" name="key" label="PLG_SYSTEM_JOOA11Y_KEY"/>
<field type="text" name="value" label="PLG_SYSTEM_JOOA11Y_VALUE"/>
</form>
</field>
</fieldset>
</fields>
</config>
Expand Down
101 changes: 42 additions & 59 deletions plugins/system/jooa11y/src/Extension/Jooa11y.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,82 +146,65 @@ public function initJooa11y()
$lang = ($country === "us") ? "enUS" : "en";
}

// Sa11y language file name
$sa11yLang = 'Sa11yLang' . ucfirst($lang);

// Get the document object
$document = $this->getApplication()->getDocument();

// Prepare `extraProps` into JSON.
function prepareExtraProps($extraProps)
{

// Remove special chars and seperate key/value pairs
$extraProps = preg_replace('/[^a-zA-Z0-9_,:]/', '', $extraProps);
$pairs = explode(',', $extraProps);
$data = [];

foreach ($pairs as $pair) {
// Split the pair into key and value
list($property, $value) = array_map('trim', explode(':', $pair, 2)) + [null, null];

// Handle booleans
$booleanValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

// If it's not a boolean, try parsing it as a number
$value = ($booleanValue === null)
? (filter_var($value, FILTER_VALIDATE_FLOAT) ?? null)
: ($booleanValue ? 1 : 0);

// Store the property and its value in the data array
$data[$property] = $value;
// Get plugin options from xml
$getOptions = [
'checkRoot' => $this->params->get('checkRoot', 'main'),
'readabilityRoot' => $this->params->get('readabilityRoot', 'main'),
'containerIgnore' => $this->params->get('containerIgnore'),
'contrastPlugin' => $this->params->get('contrastPlugin'),
'formLabelsPlugin' => $this->params->get('formLabelsPlugin'),
'linksAdvancedPlugin' => $this->params->get('linksAdvancedPlugin'),
'colourFilterPlugin' => $this->params->get('colourFilterPlugin'),
'checkAllHideToggles' => $this->params->get('additionalChecks'),
'shadowComponents' => $this->params->get('shadowComponents'),
];
$getExtraProps = $this->params->get('extraProps');

// Process extra props
$extraProps = [];
foreach ($getExtraProps as $prop) {
$decodedValue = json_decode($prop->value);
if (is_numeric($decodedValue) || is_bool($decodedValue)) {
$extraProps[$prop->key] = $decodedValue;
} else {
$extraProps[$prop->key] = "{$prop->value}";
}

// Encode to JSON, ensuring numeric values are not treated as strings
return json_encode($data, JSON_NUMERIC_CHECK);
}

// Get extra props
$extraProps = $this->params->get('extraProps');
$extraPropsJSON = !empty($extraProps) ? prepareExtraProps($extraProps) : '""';

// Add plugin settings from the xml
$document->addScriptOptions(
'jooa11yOptions',
[
'checkRoot' => $this->params->get('checkRoot', 'main'),
'readabilityRoot' => $this->params->get('readabilityRoot', 'main'),
'containerIgnore' => $this->params->get('containerIgnore'),
'contrastPlugin' => $this->params->get('contrastPlugin'),
'formLabelsPlugin' => $this->params->get('formLabelsPlugin'),
'linksAdvancedPlugin' => $this->params->get('linksAdvancedPlugin'),
'colourFilterPlugin' => $this->params->get('colourFilterPlugin'),
'checkAllHideToggles' => $this->params->get('additionalChecks'),
'shadowComponents' => $this->params->get('shadowComponents'),
],
);
// Merge all options together and add to page
$allOptions = array_merge($getOptions, $extraProps);
$document->addScriptOptions('jooa11yOptions', $allOptions);

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa*/
$wa = $document->getWebAssetManager();

// Load scripts and instantiate
$wa->useStyle('sa11yCSS');
$wa->useStyle('sa11y')
->useScript('sa11y')
->registerAndUseScript(
'sa11y-lang',
'vendor/sa11y/' . $lang . '.js',
['importmap' => true],
[],
[]
);

$wa->addInlineScript(
<<<EOT
import { Sa11y, Lang } from '/media/vendor/sa11y/js/sa11y.esm.min.js';
import $sa11yLang from '/media/vendor/sa11y/js/$lang.js';
Lang.addI18n($sa11yLang.strings);
import { Sa11y, Lang } from 'sa11y';
import Sa11yLang from 'sa11y-lang';
const options = Joomla.getOptions('jooa11yOptions');
const extraProps = $extraPropsJSON;
const allOptions = Object.assign({}, options, extraProps);
Lang.addI18n(Sa11yLang.strings);
window.addEventListener('load', () => {
const sa11y = new Sa11y(allOptions);
new Sa11y(Joomla.getOptions('jooa11yOptions', {}));
});
EOT,
[],
['type' => 'module']
['name' => 'inline.plg_system_sa11y-init'],
['type' => 'module'],
['core', 'sa11y', 'sa11y-lang']
);

return true;
Expand Down

0 comments on commit 6674a90

Please sign in to comment.