summaryrefslogtreecommitdiff
path: root/www/js/utils.js
diff options
context:
space:
mode:
authorPeter Grassberger <petertheone@gmail.com>2016-01-01 17:26:34 (GMT)
committerPeter Grassberger <petertheone@gmail.com>2016-01-01 17:26:34 (GMT)
commitb508322f56292b0d4d9fbf41389a1c0fee5befdf (patch)
treedff0171f80d7875d87af092c23e8bdc7ee046e1d /www/js/utils.js
parent91e18a8859806ba096825f9d44401b8e6469676f (diff)
musicgrid: title hover, set font color dependent on background
Diffstat (limited to 'www/js/utils.js')
-rw-r--r--www/js/utils.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/www/js/utils.js b/www/js/utils.js
index 8331ea1..470b3b5 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -101,3 +101,32 @@ function locationHrefValue() {
var value = window.location.href.match(/import.helsinki.at\/([a-z]+)\/?.*/);
return value ? value[1] : '';
}
+
+/*
+ see: https://gist.github.com/kozo002/6806421
+ */
+jQuery.fn.isBackgroundDark = function() {
+ return this.brightness() === 'dark';
+};
+
+jQuery.fn.brightness = function() {
+ var bg_color, rgba, y;
+ bg_color = this.css('background-color');
+ if ((bg_color != null) && bg_color.length) {
+ rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
+ if (rgba != null) {
+ if (rgba[4] === '0') {
+ if (this.parent().length) return this.parent().brightness();
+ } else {
+ y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];
+ if (y >= 1275) {
+ return 'light';
+ } else {
+ return 'dark';
+ }
+ }
+ }
+ } else {
+ if (this.parent().length) return this.parent().brightness();
+ }
+};