diff options
author | Janis Köhr <janis.koehr@novatec-gmbh.de> | 2019-08-30 11:23:09 +0200 |
---|---|---|
committer | Janis Köhr <janis.koehr@novatec-gmbh.de> | 2019-09-16 21:04:18 +0200 |
commit | 567b224df4522d751ac3199730a73d5d2cd9a21a (patch) | |
tree | e1cd677935bb8df0dd75313a109e9af6d460d93d /apps/accessibility/lib/Controller | |
parent | 9629015b4bef62898e38f34b5951407f941827cf (diff) | |
download | nextcloud-server-567b224df4522d751ac3199730a73d5d2cd9a21a.tar.gz nextcloud-server-567b224df4522d751ac3199730a73d5d2cd9a21a.zip |
Add theme class for selected theme to body, fix for accessibility theme selection and separated highcontrast theme
Signed-off-by: Janis Köhr <janis.koehr@novatec-gmbh.de>
Diffstat (limited to 'apps/accessibility/lib/Controller')
-rw-r--r-- | apps/accessibility/lib/Controller/AccessibilityController.php | 22 | ||||
-rw-r--r-- | apps/accessibility/lib/Controller/ConfigController.php | 8 |
2 files changed, 22 insertions, 8 deletions
diff --git a/apps/accessibility/lib/Controller/AccessibilityController.php b/apps/accessibility/lib/Controller/AccessibilityController.php index e17b206cdfd..91fd9dc6fa5 100644 --- a/apps/accessibility/lib/Controller/AccessibilityController.php +++ b/apps/accessibility/lib/Controller/AccessibilityController.php @@ -167,7 +167,7 @@ class AccessibilityController extends Controller { $appWebRoot = substr($this->appRoot, strlen($this->serverRoot) - strlen(\OC::$WEBROOT)); $css = $this->rebaseUrls($css, $appWebRoot . '/css'); - if (in_array('themedark', $userValues) && $this->iconsCacher->getCachedList() && $this->iconsCacher->getCachedList()->getSize() > 0) { + if (in_array('dark', $userValues) && $this->iconsCacher->getCachedList() && $this->iconsCacher->getCachedList()->getSize() > 0) { $iconsCss = $this->invertSvgIconsColor($this->iconsCacher->getCachedList()->getContent()); $css = $css . $iconsCss; } @@ -201,16 +201,27 @@ class AccessibilityController extends Controller { if ($user === null) { $theme = false; + $highcontrast = false; } else { $theme = $this->config->getUserValue($user->getUID(), $this->appName, 'theme', false); + $highcontrast = $this->config->getUserValue($user->getUID(), $this->appName, 'highcontrast', false) !== false; } - - $responseJS = '(function() { + if ($theme !== false) { + $responseJS = '(function() { OCA.Accessibility = { + highcontrast: ' . json_encode($highcontrast) . ', theme: ' . json_encode($theme) . ', - }; + document.body.classList.add(' . json_encode($theme) . '); })();'; + } else { + $responseJS = '(function() { + OCA.Accessibility = { + highcontrast: ' . json_encode($highcontrast) . ', + theme: ' . json_encode($theme) . ', + }; +})();'; + } $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); $response->cacheFor(3600); return $response; @@ -224,8 +235,9 @@ class AccessibilityController extends Controller { private function getUserValues(): array{ $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false); $userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false); + $userHighContrast = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false); - return [$userTheme, $userFont]; + return [$userTheme, $userHighContrast, $userFont]; } /** diff --git a/apps/accessibility/lib/Controller/ConfigController.php b/apps/accessibility/lib/Controller/ConfigController.php index 1fe2c4fbc13..cb15324f9c6 100644 --- a/apps/accessibility/lib/Controller/ConfigController.php +++ b/apps/accessibility/lib/Controller/ConfigController.php @@ -83,6 +83,7 @@ class ConfigController extends OCSController { */ public function getConfig(): DataResponse { return new DataResponse([ + 'highcontrast' => $this->config->getUserValue($this->userId, $this->appName, 'highcontrast', false), 'theme' => $this->config->getUserValue($this->userId, $this->appName, 'theme', false), 'font' => $this->config->getUserValue($this->userId, $this->appName, 'font', false) ]); @@ -98,7 +99,7 @@ class ConfigController extends OCSController { * @throws Exception */ public function setConfig(string $key, $value): DataResponse { - if ($key === 'theme' || $key === 'font') { + if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { if ($value === false) { $this->config->deleteUserValue($this->userId, $this->appName, $key); @@ -113,11 +114,12 @@ class ConfigController extends OCSController { } $themes = $this->accessibilityProvider->getThemes(); + $highcontrast = $this->accessibilityProvider->getHighContrast(); $fonts = $this->accessibilityProvider->getFonts(); $availableOptions = array_map(function($option) { return $option['id']; - }, array_merge($themes, $fonts)); + }, array_merge($themes, $highcontrast, $fonts)); if (in_array($value, $availableOptions)) { $this->config->setUserValue($this->userId, $this->appName, $key, $value); @@ -130,4 +132,4 @@ class ConfigController extends OCSController { throw new OCSBadRequestException('Invalid key: ' . $key); } -}
\ No newline at end of file +} |