Unified color conversion methods combining both to make it better, placed it in globals.coffee as a coffeescript function, and added a global handlebars helper that calls it too.

This commit is contained in:
perroned 2014-08-21 07:40:19 -07:00
parent f0738dda62
commit 64ff5f1da2
4 changed files with 10 additions and 13 deletions

View File

@ -1,3 +1,9 @@
# Convert a color `value` as integer to a hex color (e.g. 255 to #0000ff)
@colourToHex = (value) ->
hex = parseInt(value).toString(16)
hex = "0" + hex while hex.length < 6
"##{hex}"
# retrieve account for selected user
@getCurrentUserFromSession = ->
Meteor.Users.findOne("userId": getInSession("userId"))
@ -45,6 +51,9 @@
user.user.name
else null
Handlebars.registerHelper "colourToHex", (value) =>
@window.colourToHex(value)
Handlebars.registerHelper 'equals', (a, b) -> # equals operator was dropped in Meteor's migration from Handlebars to Spacebars
a is b

View File

@ -161,12 +161,6 @@ Template.message.helpers
res = str.replace /\n/gim, '<br/>'
res = res.replace /\r/gim, '<br/>'
getHexColor: (c) ->
if parseInt(c).toString(16).length is 4
"#00#{parseInt(c).toString(16)}"
else
"##{parseInt(c).toString(16)}"
# make links received from Flash client clickable in HTML
toClickable: (str) ->
res = str.replace /<a href='event:/gim, "<a target='_blank' href='"

View File

@ -49,7 +49,7 @@
</td>
</tr>
</table>
<div style="color:{{getHexColor message.from_color}}">{{{sanitizeAndFormat message.message}}}</div> <!-- Messages must be safely filtered and stripped -->
<div style="color:{{colourToHex message.from_color}}">{{{sanitizeAndFormat message.message}}}</div> <!-- Messages must be safely filtered and stripped -->
</template>
<!-- Displays the list of options available -->

View File

@ -34,9 +34,3 @@ Meteor.methods
stroke: if stroke.toString().match(/\#.*/) then stroke else colourToHex(stroke)
"stroke-width": if thickness.toString().match(/.*px$/) then thickness else "#{thickness}px"
r
# Convert a color `value` as integer to a hex color (e.g. 255 to #0000ff)
colourToHex = (value) ->
hex = value.toString(16)
hex = "0" + hex while hex.length < 6
"##{hex}"