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 c7656de commit 944ac6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
21 changes: 15 additions & 6 deletions accessibility_textcolour.php → classes/textcolour.php
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_textcolour;

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

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

/**
* Text colour accessibility widget definition
*/
class textcolour extends colourwidget {
class textcolour extends colourwidget implements apply_style {

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

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

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 "body.accessibility-textcolour, body.accessibility-textcolour * { color: {$color}; }";
}
}
38 changes: 0 additions & 38 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_textcolour';
$plugin->release = '1.0.1';
$plugin->version = 2023103000;
$plugin->version = 2024051300;
$plugin->requires = 2022041900;
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
'local_accessibility' => 2023071300,
'local_accessibility' => 2024050800,
];

0 comments on commit 944ac6f

Please sign in to comment.