summaryrefslogtreecommitdiff
path: root/static/js/colorutils.js
diff options
context:
space:
mode:
authorPeter 'Pita' Martischka <petermartischka@googlemail.com>2011-07-07 18:59:34 +0100
committerPeter 'Pita' Martischka <petermartischka@googlemail.com>2011-07-07 18:59:34 +0100
commit271ee1776b6900d90d138d6770fe288768162ca1 (patch)
treeb6996fed98a30d24bb6cad2b3b60e5367b180858 /static/js/colorutils.js
parent2fa1d8768b52ebf7483a4ecb41c2a0ad007efaef (diff)
downloadetherpad-lite-271ee1776b6900d90d138d6770fe288768162ca1.zip
beautified all static js files
Diffstat (limited to 'static/js/colorutils.js')
-rw-r--r--static/js/colorutils.js99
1 files changed, 61 insertions, 38 deletions
diff --git a/static/js/colorutils.js b/static/js/colorutils.js
index 31c26c9a..03141271 100644
--- a/static/js/colorutils.js
+++ b/static/js/colorutils.js
@@ -1,6 +1,5 @@
// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/colorutils.js
// THIS FILE IS ALSO SERVED AS CLIENT-SIDE JS
-
/**
* Copyright 2009 Google Inc.
*
@@ -20,73 +19,97 @@
var colorutils = {};
// "#ffffff" or "#fff" or "ffffff" or "fff" to [1.0, 1.0, 1.0]
-colorutils.css2triple = function(cssColor) {
+colorutils.css2triple = function(cssColor)
+{
var sixHex = colorutils.css2sixhex(cssColor);
- function hexToFloat(hh) {
- return Number("0x"+hh)/255;
+
+ function hexToFloat(hh)
+ {
+ return Number("0x" + hh) / 255;
}
- return [hexToFloat(sixHex.substr(0,2)),
- hexToFloat(sixHex.substr(2,2)),
- hexToFloat(sixHex.substr(4,2))];
+ return [hexToFloat(sixHex.substr(0, 2)), hexToFloat(sixHex.substr(2, 2)), hexToFloat(sixHex.substr(4, 2))];
}
// "#ffffff" or "#fff" or "ffffff" or "fff" to "ffffff"
-colorutils.css2sixhex = function(cssColor) {
+colorutils.css2sixhex = function(cssColor)
+{
var h = /[0-9a-fA-F]+/.exec(cssColor)[0];
- if (h.length != 6) {
+ if (h.length != 6)
+ {
var a = h.charAt(0);
var b = h.charAt(1);
var c = h.charAt(2);
- h = a+a+b+b+c+c;
+ h = a + a + b + b + c + c;
}
return h;
}
// [1.0, 1.0, 1.0] -> "#ffffff"
-colorutils.triple2css = function(triple) {
- function floatToHex(n) {
- var n2 = colorutils.clamp(Math.round(n*255), 0, 255);
- return ("0"+n2.toString(16)).slice(-2);
+colorutils.triple2css = function(triple)
+{
+ function floatToHex(n)
+ {
+ var n2 = colorutils.clamp(Math.round(n * 255), 0, 255);
+ return ("0" + n2.toString(16)).slice(-2);
}
- return "#" + floatToHex(triple[0]) +
- floatToHex(triple[1]) + floatToHex(triple[2]);
+ return "#" + floatToHex(triple[0]) + floatToHex(triple[1]) + floatToHex(triple[2]);
}
-colorutils.clamp = function(v,bot,top) { return v < bot ? bot : (v > top ? top : v); };
-colorutils.min3 = function(a,b,c) { return (a < b) ? (a < c ? a : c) : (b < c ? b : c); };
-colorutils.max3 = function(a,b,c) { return (a > b) ? (a > c ? a : c) : (b > c ? b : c); };
-colorutils.colorMin = function(c) { return colorutils.min3(c[0], c[1], c[2]); };
-colorutils.colorMax = function(c) { return colorutils.max3(c[0], c[1], c[2]); };
-colorutils.scale = function(v, bot, top) { return colorutils.clamp(bot + v*(top-bot), 0, 1); };
-colorutils.unscale = function(v, bot, top) { return colorutils.clamp((v-bot)/(top-bot), 0, 1); };
+colorutils.clamp = function(v, bot, top)
+{
+ return v < bot ? bot : (v > top ? top : v);
+};
+colorutils.min3 = function(a, b, c)
+{
+ return (a < b) ? (a < c ? a : c) : (b < c ? b : c);
+};
+colorutils.max3 = function(a, b, c)
+{
+ return (a > b) ? (a > c ? a : c) : (b > c ? b : c);
+};
+colorutils.colorMin = function(c)
+{
+ return colorutils.min3(c[0], c[1], c[2]);
+};
+colorutils.colorMax = function(c)
+{
+ return colorutils.max3(c[0], c[1], c[2]);
+};
+colorutils.scale = function(v, bot, top)
+{
+ return colorutils.clamp(bot + v * (top - bot), 0, 1);
+};
+colorutils.unscale = function(v, bot, top)
+{
+ return colorutils.clamp((v - bot) / (top - bot), 0, 1);
+};
-colorutils.scaleColor = function(c, bot, top) {
- return [colorutils.scale(c[0], bot, top),
- colorutils.scale(c[1], bot, top),
- colorutils.scale(c[2], bot, top)];
+colorutils.scaleColor = function(c, bot, top)
+{
+ return [colorutils.scale(c[0], bot, top), colorutils.scale(c[1], bot, top), colorutils.scale(c[2], bot, top)];
}
-colorutils.unscaleColor = function(c, bot, top) {
- return [colorutils.unscale(c[0], bot, top),
- colorutils.unscale(c[1], bot, top),
- colorutils.unscale(c[2], bot, top)];
+colorutils.unscaleColor = function(c, bot, top)
+{
+ return [colorutils.unscale(c[0], bot, top), colorutils.unscale(c[1], bot, top), colorutils.unscale(c[2], bot, top)];
}
-colorutils.luminosity = function(c) {
+colorutils.luminosity = function(c)
+{
// rule of thumb for RGB brightness; 1.0 is white
- return c[0]*0.30 + c[1]*0.59 + c[2]*0.11;
+ return c[0] * 0.30 + c[1] * 0.59 + c[2] * 0.11;
}
-colorutils.saturate = function(c) {
+colorutils.saturate = function(c)
+{
var min = colorutils.colorMin(c);
var max = colorutils.colorMax(c);
if (max - min <= 0) return [1.0, 1.0, 1.0];
return colorutils.unscaleColor(c, min, max);
}
-colorutils.blend = function(c1, c2, t) {
- return [colorutils.scale(t, c1[0], c2[0]),
- colorutils.scale(t, c1[1], c2[1]),
- colorutils.scale(t, c1[2], c2[2])];
+colorutils.blend = function(c1, c2, t)
+{
+ return [colorutils.scale(t, c1[0], c2[0]), colorutils.scale(t, c1[1], c2[1]), colorutils.scale(t, c1[2], c2[2])];
}