Commit 5adb8201e6d539e34e857e10b6a5afd04722c50c
1 parent
fab8ed52
Exists in
master
and in
8 other branches
Add color utils (darker or lighter RGB)
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
src/app/index.run.js
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | .run(runAuth) | 7 | .run(runAuth) |
| 8 | .run(runAccessibility) | 8 | .run(runAccessibility) |
| 9 | .run(runPath) | 9 | .run(runPath) |
| 10 | + .run(runColorUtils) | ||
| 10 | .run(runBlock); | 11 | .run(runBlock); |
| 11 | 12 | ||
| 12 | /** @ngInject */ | 13 | /** @ngInject */ |
| @@ -82,6 +83,30 @@ | @@ -82,6 +83,30 @@ | ||
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | /** @ngInject */ | 85 | /** @ngInject */ |
| 86 | + function runColorUtils($log) { | ||
| 87 | + | ||
| 88 | + window.ColorLuminance = function (hex, lum) { | ||
| 89 | + | ||
| 90 | + // validate hex string | ||
| 91 | + hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
| 92 | + if (hex.length < 6) { | ||
| 93 | + hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; | ||
| 94 | + } | ||
| 95 | + lum = lum || 0; | ||
| 96 | + | ||
| 97 | + // convert to decimal and change luminosity | ||
| 98 | + var rgb = "#", c, i; | ||
| 99 | + for (i = 0; i < 3; i++) { | ||
| 100 | + c = parseInt(hex.substr(i*2,2), 16); | ||
| 101 | + c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
| 102 | + rgb += ("00"+c).substr(c.length); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + return rgb; | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** @ngInject */ | ||
| 85 | function runBlock($log) { | 110 | function runBlock($log) { |
| 86 | $log.debug('runBlock end.'); | 111 | $log.debug('runBlock end.'); |
| 87 | } | 112 | } |