]> source.dussan.org Git - nextcloud-server.git/commitdiff
Theming: Colorize checkboxes depending on luminance
authorJulius Haertl <jus@bitgrid.net>
Tue, 19 Jul 2016 12:00:33 +0000 (14:00 +0200)
committerJulius Haertl <jus@bitgrid.net>
Wed, 27 Jul 2016 17:45:57 +0000 (19:45 +0200)
apps/theming/lib/controller/themingcontroller.php
apps/theming/lib/util.php
apps/theming/tests/lib/UtilTest.php

index eb377f27ff868c57d4cbb7dfdd928903881663e6..32d96203d62405e9069788d823f60043115dabd9 100644 (file)
@@ -214,6 +214,7 @@ class ThemingController extends Controller {
                $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
                $responseCss = '';
                $color = $this->config->getAppValue($this->appName, 'color');
+               $elementColor = Util::elementColor($color);
                if($color !== '') {
                        $responseCss .= sprintf(
                                '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}',
@@ -221,11 +222,11 @@ class ThemingController extends Controller {
                        );
                        $responseCss .= sprintf('
                                input[type="checkbox"].checkbox:checked + label:before {
-                                       background-image:url(/core/img/actions/checkmark-white.svg);
+                                       background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');
                                        background-color: %s; background-position: center center; background-size:contain;
                                        width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;
                        }',
-                               $color
+                               $elementColor
                        );
                }
                $logo = $this->config->getAppValue($this->appName, 'logoMime');
index 2088650b19db734745bb077d8d0da92784b48612..d342073d83e9eb785e26adddc655eecc6271275d 100644 (file)
@@ -38,6 +38,21 @@ class Util {
                }
        }
 
+       /**
+        * get color for on-page elements:
+        * theme color by default, grey if theme color is to bright
+        * @param $color
+        * @return string
+        */
+       public static function elementColor($color) {
+               $l = self::calculateLuminance($color);
+               if($l>0.8) {
+                       return '#969696';
+               } else {
+                       return $color;
+               }
+       }
+
        /**
         * @param string $color rgb color value
         * @return float
index 9ebb11d6288434fd381a622bbdf87164648bf60c..6451b65d0271df63aaa409420ef4bde6048ba123 100644 (file)
@@ -65,4 +65,14 @@ class UtilTest extends TestCase {
                $invert = Util::invertTextColor('');
                $this->assertEquals(false, $invert);
        }
+
+       public function testElementColorDefault() {
+               $elementColor = Util::elementColor("#000000");
+               $this->assertEquals('#000000', $elementColor);
+       }
+
+       public function testElementColorOnBrightBackground() {
+               $elementColor = Util::elementColor('#ffffff');
+               $this->assertEquals('#969696', $elementColor);
+       }
 }