Skip to content

Commit

Permalink
Update plugin structure based on ponlawat-w/moodle-local_accessibilit…
Browse files Browse the repository at this point in the history
  • Loading branch information
cli-ish committed Aug 17, 2024
1 parent 6fcd940 commit d6424ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_accessibility\widgets;
namespace accessibility_backgroundcolour;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__ . '/../../classes/colourwidget.php');
use local_accessibility\widgets\apply_style;
use local_accessibility\widgets\colourwidget;

/**
* Background colour accessibility widget definition
*/
class backgroundcolour extends colourwidget {
class backgroundcolour extends colourwidget implements apply_style {

/**
* Constructor
Expand All @@ -52,7 +51,6 @@ public function init() {
$userconfig = $this->getuserconfig();
if ($userconfig) {
$this->addbodyclass('accessibility-backgroundcolour');
$PAGE->requires->css('/local/accessibility/widgets/backgroundcolour/styles.php');
}

$PAGE->requires->js_call_amd('local_accessibility/colourwidget', 'init', [
Expand All @@ -62,4 +60,19 @@ public function init() {
'accessibility-backgroundcolour',
]);
}

public function apply_style(): string {
$userconfig = $this->getuserconfig();
if (!$userconfig) {
return "";
}
// Strip all special characters except # because its needed for hex colors.
// A check for #XX.. could have been used but this would not allow named css colors such as red, or green.
$color = preg_replace("/[^A-Za-z0-9#]/", '', $userconfig);
return <<<EOL
body.accessibility-backgroundcolour, body.accessibility-backgroundcolour *:not(.mediaplugin, .mediaplugin *) {
background-color: {$color} !important;
}
EOL;
}
}
42 changes: 0 additions & 42 deletions styles.php

This file was deleted.

4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

$plugin->component = 'accessibility_backgroundcolour';
$plugin->release = '1.0.2';
$plugin->version = 2024041600;
$plugin->version = 2024051300;
$plugin->requires = 2022041900;
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
'local_accessibility' => 2023071300,
'local_accessibility' => 2024050800,
];

0 comments on commit d6424ee

Please sign in to comment.