Files
mozo-backend/app/assets/javascripts/supplier/app/services/css-object.js.coffee
T

26 lines
864 B
CoffeeScript

App.CssObject = Ember.Object.extend
pixel_fields: ['width', 'height', 'left', 'top', 'line-height']
isNumeric: /^[-+]?(\d+|\d+\.\d+)$/
toString: ->
ret = ""
for k, v of JSON.parse(JSON.stringify(@))
if @pixel_fields.indexOf(k) > -1
v = "#{v}px" if @isNumeric.test(v)
ret += "#{k}:#{v};"
ret.htmlSafe()
App.CssObject.reopenClass
rgb_to_numeric: (rgb_hex)->
#http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black
rgb_hex = rgb_hex.substring(1)
rgb = parseInt(rgb_hex, 16)
r = (rgb >> 16) & 0xff
g = (rgb >> 8) & 0xff
b = (rgb >> 0) & 0xff
[r, g, b]
isColorDark: (rgb_hex)->
return false unless rgb_hex and rbg_hex.match /#[0-9a-zA-Z]{6}/
[r, g, b] = @rgb_to_numeric(rgb_hex)
luma = 0.2126 * r + 0.7152 * g + 0.0722 * b # per ITU-R BT.709
luma < 40