From f4ea956be3d0d9760332a2fc929740c3bdd418cf Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 2 Jan 2014 17:54:11 -0700 Subject: [PATCH] Accidentally broke all of this. Fix, refactor, golden. --- builds/appchan-x.user.js | 22 ++++++++++------------ builds/crx/script.js | 22 ++++++++++------------ src/Theming/color.coffee | 25 ++++++++++++++----------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 2646aa455..69e990f9d 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -13618,7 +13618,7 @@ }; Color = (function() { - var calcRGB, colorToHex, minmax, shortToLong; + var colorToHex, minmax, shortToLong; minmax = function(base) { if (base < 0) { @@ -13630,12 +13630,6 @@ } }; - calcRGB = function(value) { - var hex; - hex = parseInt(value, 16); - return [(hex >> 16) & 0xFF, (hex >> 8) & 0xFF, hex & 0xFF]; - }; - shortToLong = function(hex) { var i, longHex; longHex = []; @@ -13682,10 +13676,6 @@ return "#" + this.raw; }; - Color.prototype.privateRGB = function() { - return calc_rgb(this.raw); - }; - Color.prototype.rgb = function() { return this.privateRGB().join(""); }; @@ -13695,7 +13685,15 @@ }; Color.prototype.isLight = function() { - return (this.privateRGB[0] * 0.299 + this.privateRGB[1] * 0.587 + this.privateRGB[2] * 0.114) > 125; + var rgb; + rgb = this.privateRGB(); + return (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125; + }; + + Color.prototype.privateRGB = function() { + var hex; + hex = parseInt(this.raw, 16); + return [(hex >> 16) & 0xFF, (hex >> 8) & 0xFF, hex & 0xFF]; }; Color.prototype.shiftRGB = function(shift, smart) { diff --git a/builds/crx/script.js b/builds/crx/script.js index 9eae81628..633e215bc 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -13629,7 +13629,7 @@ }; Color = (function() { - var calcRGB, colorToHex, minmax, shortToLong; + var colorToHex, minmax, shortToLong; minmax = function(base) { if (base < 0) { @@ -13641,12 +13641,6 @@ } }; - calcRGB = function(value) { - var hex; - hex = parseInt(value, 16); - return [(hex >> 16) & 0xFF, (hex >> 8) & 0xFF, hex & 0xFF]; - }; - shortToLong = function(hex) { var i, longHex; longHex = []; @@ -13693,10 +13687,6 @@ return "#" + this.raw; }; - Color.prototype.privateRGB = function() { - return calc_rgb(this.raw); - }; - Color.prototype.rgb = function() { return this.privateRGB().join(""); }; @@ -13706,7 +13696,15 @@ }; Color.prototype.isLight = function() { - return (this.privateRGB[0] * 0.299 + this.privateRGB[1] * 0.587 + this.privateRGB[2] * 0.114) > 125; + var rgb; + rgb = this.privateRGB(); + return (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125; + }; + + Color.prototype.privateRGB = function() { + var hex; + hex = parseInt(this.raw, 16); + return [(hex >> 16) & 0xFF, (hex >> 8) & 0xFF, hex & 0xFF]; }; Color.prototype.shiftRGB = function(shift, smart) { diff --git a/src/Theming/color.coffee b/src/Theming/color.coffee index b51ec25c8..43b467d3e 100644 --- a/src/Theming/color.coffee +++ b/src/Theming/color.coffee @@ -1,14 +1,6 @@ class Color minmax = (base) -> if base < 0 then 0 else if base > 255 then 255 else base - calcRGB = (value) -> - hex = parseInt value, 16 - return [ # 0xRRGGBB to [R, G, B] - (hex >> 16) & 0xFF - (hex >> 8) & 0xFF - hex & 0xFF - ] - shortToLong = (hex) -> longHex = [] i = 0 @@ -43,13 +35,24 @@ class Color "000000" constructor: (value) -> - @raw = colorToHex value + @raw = colorToHex value hex: -> "#" + @raw - privateRGB: -> calc_rgb @raw rgb: -> @privateRGB().join "" hover: -> @shiftRGB 16, true - isLight: -> (@privateRGB[0] * 0.299 + @privateRGB[1] * 0.587 + @privateRGB[2] * 0.114) > 125 + + isLight: -> + rgb = @privateRGB() + (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 + + privateRGB: -> + hex = parseInt @raw, 16 + return [ + # 0xRRGGBB to [R, G, B] + (hex >> 16) & 0xFF + (hex >> 8) & 0xFF + hex & 0xFF + ] shiftRGB: (shift, smart) -> shift = (if @isLight() then -1 else 1) * Math.abs shift if smart