aboutsummaryrefslogtreecommitdiffstats
path: root/apps/accessibility/src/App.vue
blob: 17c0ce63c5f2d102e028fd790e18aeb9821eea93 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
	<div id="accessibility" class="section">
		<h2>{{t('accessibility', 'Accessibility')}}</h2>
		<p v-html="description" />
		<p v-html="descriptionDetail" />

		<div class="preview-list">
			<preview v-for="preview in highcontrast" :preview="preview"
				 :key="preview.id" :selected="selected.highcontrast"
				 v-on:select="selectHighContrast"></preview>
			<preview v-for="preview in themes" :preview="preview"
				 :key="preview.id" :selected="selected.theme"
				 v-on:select="selectTheme"></preview>
			<preview v-for="preview in fonts" :preview="preview"
				 :key="preview.id" :selected="selected.font"
				 v-on:select="selectFont"></preview>
		</div>
	</div>
</template>

<script>
import preview from './components/itemPreview';
import axios from 'nextcloud-axios';

export default {
	name: 'Accessibility',
	components: { preview },
	beforeMount() {
		// importing server data into the app
		const serverDataElmt = document.getElementById('serverData');
		if (serverDataElmt !== null) {
			this.serverData = JSON.parse(
				document.getElementById('serverData').dataset.server
			);
		}
	},
	data() {
		return {
			serverData: []
		};
	},
	computed: {
		themes() {
			return this.serverData.themes;
		},
		highcontrast() {
			return this.serverData.highcontrast;
		},
		fonts() {
			return this.serverData.fonts;
		},
		selected() {
			return {
				theme: this.serverData.selected.theme,
				highcontrast: this.serverData.selected.highcontrast,
				font: this.serverData.selected.font
			};
		},
		description() {
			// using the `t` replace method escape html, we have to do it manually :/
			return t(
				'accessibility',
				`Universal access is very important to us. We follow web standards
				and check to make everything usable also without mouse,
				and assistive software such as screenreaders.
				We aim to be compliant with the {guidelines} 2.1 on AA level,
				with the high contrast theme even on AAA level.`
			)
			.replace('{guidelines}', this.guidelinesLink)
		},
		guidelinesLink() {
			return `<a target="_blank" href="https://www.w3.org/WAI/standards-guidelines/wcag/" rel="noreferrer nofollow">${t('accessibility', 'Web Content Accessibility Guidelines')}</a>`
		},
		descriptionDetail() {
			return t(
				'accessibility',
				`If you find any issues, don’t hesitate to report them on {issuetracker}.
				And if you want to get involved, come join {designteam}!`
			)
			.replace('{issuetracker}', this.issuetrackerLink)
			.replace('{designteam}', this.designteamLink)
		},
		issuetrackerLink() {
			return `<a target="_blank" href="https://github.com/nextcloud/server/issues/" rel="noreferrer nofollow">${t('accessibility', 'our issue tracker')}</a>`
		},
		designteamLink() {
			return `<a target="_blank" href="https://nextcloud.com/design" rel="noreferrer nofollow">${t('accessibility', 'our design team')}</a>`
		}
	},
	methods: {
		selectHighContrast(id) {
			this.selectItem('highcontrast', id);
		},
		selectTheme(id, idSelectedBefore) {
			this.selectItem('theme', id);
			document.body.classList.remove(idSelectedBefore);
			if (id) {
				document.body.classList.add(id);
			}
		},
		selectFont(id) {
			this.selectItem('font', id);
		},

		/**
		 * Commit a change and force reload css
		 * Fetching the file again will trigger the server update
		 *
		 * @param {string} type type of the change (font, highcontrast or theme)
		 * @param {string} id the data of the change
		 */
		selectItem(type, id) {
			axios.post(
					OC.linkToOCS('apps/accessibility/api/v1/config', 2) + type,
					{ value: id }
				)
				.then(response => {
					this.serverData.selected[type] = id;

					// Remove old link
					let link = document.querySelector('link[rel=stylesheet][href*=accessibility][href*=user-]');
					if (!link) {
						// insert new css
						let link = document.createElement('link');
						link.rel = 'stylesheet';
						link.href = OC.generateUrl('/apps/accessibility/css/user-style.css') + '?v=' + new Date().getTime();
						document.head.appendChild(link);
					} else {
						// compare arrays
						if (
							JSON.stringify(Object.values(this.selected)) ===
							JSON.stringify([false, false])
						) {
							// if nothing is selected, blindly remove the css
							link.remove();
						} else {
							// force update
							link.href =
								link.href.split('?')[0] +
								'?v=' +
								new Date().getTime();
						}
					}
				})
				.catch(err => {
					console.log(err, err.response);
					OC.Notification.showTemporary(t('accessibility', err.response.data.ocs.meta.message + '. Unable to apply the setting.'));
				});
		}
	}
};
</script>