Skip to content

Commit

Permalink
Merge pull request #7 from sudile/master
Browse files Browse the repository at this point in the history
Update plugin structure
  • Loading branch information
ponlawat-w authored Aug 24, 2024
2 parents 6fcd940 + 3a60772 commit 5c9c379
Show file tree
Hide file tree
Showing 3 changed files with 26 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,24 @@ public function init() {
'accessibility-backgroundcolour',
]);
}

/**
* Apply own css styles, will be served to all users when plugin is enabled.
*
* @return string
*/
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 5c9c379

Please sign in to comment.