-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstylechange.js
104 lines (86 loc) · 3.06 KB
/
stylechange.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Script for displaying open-dyslexic font on site
*
* @package block_dyslexic
* @copyright 2016 onwards Éric Bugnet {@link http://eric.bugnet.fr/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Éric Bugnet
*/
// Set values to cookies.
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + '=' + cvalue + '; ' + expires + '; path=/ ';
javascript:window.location.reload();
}
// Get value from cookies.
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
var dys = getCookie("dyslexic");
var bkg = getCookie("dyslexis-bkg");
var txt = getCookie("dyslexis-txt");
// Check if OpenDysexic font is needed.
if (dys == 'true') {
// If needed, change CSS to apply OpenDyslexic font.
var x = document.createElement("STYLE");
/*jshint multistr: true */
var t = document.createTextNode("\
body,h1,h2,h3,h4,h5,h6,p,ul,ol,dl,input,textarea \
{font-family: opendyslexic;} \
select \
{font-family: opendyslexic; \
box-sizing: content-box;} \
\
");
x.appendChild(t);
document.head.appendChild(x);
changeColorAtt(bkg,txt);
} else {
// Else, nothing to do, but I keep it for test.
}
function changeColor(bkg,txt) {
debugger;
// If needed, change CSS to apply OpenDyslexic font.
setCookie('dyslexis-bkg',bkg,100);
setCookie('dyslexis-txt',txt,100);
changeColorAtt(bkg,txt);
}
function changeColorAtt(bkg,txt) {
// If needed, change CSS to apply OpenDyslexic font.
var x = document.createElement("STYLE");
/*jshint multistr: true */
var t = document.createTextNode("\
.card, #page-enrol-users #filterform, .que .history, .userprofile .profile_tree section, .groupinfobox, .well, #region-main \
{background-color: "+bkg+" !important;} \
body { color: "+txt+" !important}\
");
x.appendChild(t);
document.head.appendChild(x);
}