-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from gabceb/added_rgb_and_hex_color_plugin
Added plugins to show hex and rgb colors on messages
- Loading branch information
Showing
4 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/assets/javascripts/backbone/plugins/hex_color_embed.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Kandan.Plugins.HexColorEmbed | ||
@options: | ||
regex: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g | ||
|
||
template: _.template '''<span class="color-preview" style="background-color:<%= hex %>;"/>''' | ||
|
||
@init: ()-> | ||
Kandan.Modifiers.register @options.regex, (message, state) => | ||
for hex in message.content.match(@options.regex) | ||
replacement = @options.template({hex: hex}) + hex | ||
message.content = message.content.replace(hex, replacement) | ||
|
||
return Kandan.Helpers.Activities.buildFromMessageTemplate(message) |
14 changes: 14 additions & 0 deletions
14
app/assets/javascripts/backbone/plugins/rgb_color_embed.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Kandan.Plugins.RgbColorEmbed | ||
@options: | ||
regex: /rgb\((\d{1,3}),\s?(\d{1,3}),\s?(\d{1,3})\)/g | ||
|
||
template: _.template '''<span class="color-preview" style="background-color:<%= rgb %>;"/>''' | ||
|
||
@init: ()-> | ||
Kandan.Modifiers.register @options.regex, (message, state) => | ||
for rgb in message.content.match(@options.regex) | ||
replacement = @options.template({rgb: rgb}) + rgb | ||
message.content = message.content.replace(rgb, replacement) | ||
|
||
return Kandan.Helpers.Activities.buildFromMessageTemplate(message) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters