-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrava11y.php
82 lines (73 loc) · 1.97 KB
/
grava11y.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Grav\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page;
use Grav\Common\Plugin;
use Grav\Common\User\User;
/**
* Grav Plugin Grava11y
* provides accessibility testing on your theme.
*
* @author Lawrence Meckan
*
* @link https://github.com/absalomedia/grav-plugin-grava11y
*
* @license http://opensource.org/licenses/MIT
*/
class Grava11yPlugin extends Plugin
{
protected $enabled = false;
/**
* @return array
*/
public static function getSubscribedEvents()
{
// initialize when plugins are ready
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
];
}
/**
* Initialize configuration.
*/
public function onPluginsInitialized()
{
// Don't load in Admin-Backend
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->initializeGrava11y();
}
/**
* Initialize Grava11y
* Check for user-auth and access before
* loading JS file for a11y.
*/
public function initializeGrava11y()
{
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
]);
// Save plugin status
$this->enabled = true;
}
/**
* if enabled on this page, load the JS.
*/
public function onTwigSiteVariables()
{
// check if enabled
if ($this->enabled) {
$a11ystack = [
'plugin://grava11y/css/grava11y.css',
];
$siter = $this->config->get('plugins.grava11y.offsite');
$siter = (0) ? array_push($a11ystack, 'https://unpkg.com/@khanacademy/tota11y@0.2.0/dist/tota11y.min.js') : array_push($a11ystack, 'plugin://grava11y/js/tota11y.min.js');
// register and add assets
$assets = $this->grav['assets'];
$assets->registerCollection('grava11y', $a11ystack);
$assets->add('grava11y', 100);
}
}
}