You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Accessibility.vue 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div id="accessibility" class="section">
  3. <h2>{{ t('accessibility', 'Accessibility') }}</h2>
  4. <p v-html="description" />
  5. <p v-html="descriptionDetail" />
  6. <div class="preview-list">
  7. <ItemPreview :key="highcontrast.id"
  8. :preview="highcontrast"
  9. :selected="selected.highcontrast"
  10. @select="selectHighContrast" />
  11. <ItemPreview v-for="preview in themes"
  12. :key="preview.id"
  13. :preview="preview"
  14. :selected="selected.theme"
  15. @select="selectTheme" />
  16. <ItemPreview v-for="preview in fonts"
  17. :key="preview.id"
  18. :preview="preview"
  19. :selected="selected.font"
  20. @select="selectFont" />
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import { generateUrl, generateOcsUrl } from '@nextcloud/router'
  26. import { loadState } from '@nextcloud/initial-state'
  27. import axios from '@nextcloud/axios'
  28. import ItemPreview from './components/ItemPreview'
  29. const availableConfig = loadState('accessibility', 'available-config')
  30. const userConfig = loadState('accessibility', 'user-config')
  31. export default {
  32. name: 'Accessibility',
  33. components: {
  34. ItemPreview,
  35. },
  36. data() {
  37. return {
  38. availableConfig,
  39. userConfig,
  40. }
  41. },
  42. computed: {
  43. themes() {
  44. return this.availableConfig.themes
  45. },
  46. highcontrast() {
  47. return this.availableConfig.highcontrast
  48. },
  49. fonts() {
  50. return this.availableConfig.fonts
  51. },
  52. selected() {
  53. return {
  54. theme: this.userConfig.theme,
  55. highcontrast: this.userConfig.highcontrast,
  56. font: this.userConfig.font,
  57. }
  58. },
  59. description() {
  60. // using the `t` replace method escape html, we have to do it manually :/
  61. return t(
  62. 'accessibility',
  63. '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}Web Content Accessibility Guidelines{linkend} 2.1 on AA level, with the high contrast theme even on AAA level.'
  64. )
  65. .replace('{guidelines}', this.guidelinesLink)
  66. .replace('{linkend}', '</a>')
  67. },
  68. guidelinesLink() {
  69. return '<a target="_blank" href="https://www.w3.org/WAI/standards-guidelines/wcag/" rel="noreferrer nofollow">'
  70. },
  71. descriptionDetail() {
  72. return t(
  73. 'accessibility',
  74. 'If you find any issues, don’t hesitate to report them on {issuetracker}our issue tracker{linkend}. And if you want to get involved, come join {designteam}our design team{linkend}!'
  75. )
  76. .replace('{issuetracker}', this.issuetrackerLink)
  77. .replace('{designteam}', this.designteamLink)
  78. .replace(/\{linkend\}/g, '</a>')
  79. },
  80. issuetrackerLink() {
  81. return '<a target="_blank" href="https://github.com/nextcloud/server/issues/" rel="noreferrer nofollow">'
  82. },
  83. designteamLink() {
  84. return '<a target="_blank" href="https://nextcloud.com/design" rel="noreferrer nofollow">'
  85. },
  86. },
  87. methods: {
  88. // SELECT handlers
  89. selectHighContrast(id) {
  90. this.selectItem('highcontrast', id)
  91. document.body.classList.toggle('theme--highcontrast')
  92. },
  93. selectTheme(id) {
  94. const previous = this.selected.theme
  95. if (previous) {
  96. document.body.classList.remove(`theme--${previous}`)
  97. }
  98. if (id) {
  99. document.body.classList.remove('theme--light')
  100. document.body.classList.add(`theme--${id}`)
  101. } else {
  102. document.body.classList.add('theme--light')
  103. }
  104. this.selectItem('theme', id)
  105. },
  106. selectFont(id) {
  107. this.selectItem('font', id)
  108. },
  109. /**
  110. * Commit a change and force reload css
  111. * Fetching the file again will trigger the server update
  112. *
  113. * @param {string} type type of the change (font, highcontrast or theme)
  114. * @param {string} id the data of the change
  115. */
  116. async selectItem(type, id) {
  117. try {
  118. const isDelete = id === ''
  119. await axios({
  120. url: generateOcsUrl('apps/accessibility/api/v1/config', 2) + type,
  121. method: isDelete ? 'DELETE' : 'PUT',
  122. data: {
  123. value: id,
  124. },
  125. })
  126. this.userConfig[type] = id
  127. // Remove old link
  128. const link = document.querySelector('link[rel=stylesheet][href*=accessibility][href*=user-]')
  129. if (!link) {
  130. // insert new css
  131. const link = document.createElement('link')
  132. link.rel = 'stylesheet'
  133. link.href = generateUrl('/apps/accessibility/css/user-style.css') + '?v=' + new Date().getTime()
  134. document.head.appendChild(link)
  135. } else {
  136. // compare arrays
  137. if (
  138. JSON.stringify(Object.values(this.selected))
  139. === JSON.stringify([false, false])
  140. ) {
  141. // if nothing is selected, blindly remove the css
  142. link.remove()
  143. } else {
  144. // force update
  145. link.href
  146. = link.href.split('?')[0]
  147. + '?v='
  148. + new Date().getTime()
  149. }
  150. }
  151. } catch (err) {
  152. console.error(err, err.response)
  153. OC.Notification.showTemporary(t('accessibility', err.response.data.ocs.meta.message + '. Unable to apply the setting.'))
  154. }
  155. },
  156. },
  157. }
  158. </script>