Skip to content
Browse files

Add color support

  • Loading branch information...
1 parent 72d42f4 commit 66f7aefa784adba7d1e57cd810a4658ef0014705 @badosu badosu committed Aug 8, 2013
View
33 assets/css/irc-colors.css
@@ -0,0 +1,33 @@
+.irc-00 { color: white }
+.irc-01 { color: black }
+.irc-02 { color: navy }
+.irc-03 { color: green }
+.irc-04 { color: red }
+.irc-05 { color: brown }
+.irc-06 { color: purple }
+.irc-07 { color: olive }
+.irc-08 { color: #C8C800 }
+.irc-09 { color: #00C800 }
+.irc-10 { color: teal }
+.irc-11 { color: #00C3C3 }
+.irc-12 { color: blue }
+.irc-13 { color: #FF4D6C }
+.irc-14 { color: #555 }
+.irc-15 { color: #777 }
+
+.irc-bg00 { border: 1px dotted white }
+.irc-bg01 { border: 1px dotted black }
+.irc-bg02 { border: 1px dotted navy }
+.irc-bg03 { border: 1px dotted green }
+.irc-bg04 { border: 1px dotted red }
+.irc-bg05 { border: 1px dotted brown }
+.irc-bg06 { border: 1px dotted purple }
+.irc-bg07 { border: 1px dotted olive }
+.irc-bg08 { border: 1px dotted #C8C800 }
+.irc-bg09 { border: 1px dotted #00C800 }
+.irc-bg10 { border: 1px dotted teal }
+.irc-bg11 { border: 1px dotted #00C3C3 }
+.irc-bg12 { border: 1px dotted blue }
+.irc-bg13 { border: 1px dotted #FF4D6C }
+.irc-bg14 { border: 1px dotted #555 }
+.irc-bg15 { border: 1px dotted #777 }
View
2 assets/js/client.js
@@ -3,6 +3,7 @@
//= require 'libs/backbone-min.js'
//= require 'libs/ICanHaz.min.js'
//= require 'libs/bootstrap.min.js'
+//= require 'libs/ircparser.min.js'
//= require 'utils.js'
//= require 'models.js'
//= require 'collections.js'
@@ -24,6 +25,7 @@ window.unity = {
$(function() {
// window.app = new ChatApplicationRouter;
irc.appView = new ChatApplicationView();
+ irc.parser = new IrcParser();
try {
window.unity.api = external.getUnityObject(1.0);
View
2 assets/js/libs/ircparser.min.js
@@ -0,0 +1,2 @@
+// http://github.com/badosu/ircparser.js
+IrcParser=function(){var b={};var a=/\x03(\d?\d)(,(\d?\d))?([^\x03\x0f]*)((\x03((\d\d?)(,\d\d?)?)?)|(\x0f))/;b.colors={white:{code:"00"},black:{code:"01"},navy:{code:"02"},green:{code:"03"},red:{code:"04"},brown:{code:"05"},purple:{code:"06"},olive:{code:"07"},yellow:{code:"08"},lightgreen:{code:"09"},teal:{code:"10"},cyan:{code:"11"},blue:{code:"12"},pink:{code:"13"},gray:{code:"14"},lightgray:{code:"15"}};b.styles={normal:{code:"\x00",replacement:"$2",regexp:/(\x00)([^\x00]*)\x00/g},bold:{code:"\x02",replacement:"<strong>$2</strong>",regexp:/(\x02)([^\x02]*)\x02/g},italic:{code:"\x16",replacement:"<em>$2</em>",regexp:/(\x16)([^\x16]*)\x16/g},underline:{code:"\x1f",replacement:"<u>$2</u>",regexp:/(\x1f)([^\x1f]*)\x1f/g}};b.bgcolors={};b.colorNames={};b.parse=function(c){c=this.replaceStyles(c);c=this.replaceColors(c);return c};b.replaceStyles=function(d){for(var e in this.styles){var c=this.styles[e];d=d.replace(c.regexp,c.replacement)}return d};b.replaceColors=function(l){var h=l.match(a);while(h){var k=("0"+h[1]).slice(-2);var c=h[2];var f=h[7];var m=h[8];var e=h[9];var g=this.colors[this.colorNames[k]];var d=g.replacement;if(c){var i=("0"+h[3]).slice(-2);var j=this.bgcolors[this.colorNames[i]];d="\x03"+k+j.replacement+"\x03";if(h[3].length==1){d=d.replace("$3","0$3")}if(f){d+=m;d+=e?e:","+i}}else{if(f){d=g.replacement+"\x03"+m;if(e){d+=e}}}if(h[1].length==1){d=d.replace("$1","0$1")}l=l.replace(a,d);h=l.match(a)}if(l.match(/\x03\d/g)){l=this.parse(l+"\x03")}return l};b.init=function(){for(var c in this.colors){var d=this.colors[c];d.replacement='<span class="irc-$1">$4</span>';this.colorNames[d.code]=c;this.bgcolors[c]={replacement:'<span class="irc-bg$3">$4</span>'}}};b.init();return b};
View
5 assets/js/views/message.js
@@ -26,6 +26,11 @@ var MessageView = Backbone.View.extend({
content: this.model.get('text'),
renderedTime: utils.formatDate(Date.now())
}, true);
+
+ if (!irc.me.get('stripColors')) {
+ html = irc.parser.parse(html);
+ }
+
html = this.model.parse(html);
}
View
2 assets/js/views/overview.js
@@ -72,6 +72,7 @@ var OverviewView = Backbone.View.extend({
selfSigned = $('#connect-selfSigned').is(':checked'),
password = $('#connect-password').val(),
encoding = $('#connect-encoding').val(),
+ stripColors = $('#connect-stripColors').is(':checked'),
keepAlive = false;
if (!server) {
@@ -100,6 +101,7 @@ var OverviewView = Backbone.View.extend({
realName: realName,
password: password,
encoding: encoding,
+ stripColors: stripColors,
keepAlive: keepAlive
};
View
2 lib/irclink.js
@@ -63,7 +63,7 @@ module.exports = function IRCLink(connID, app) {
selfSigned: userConn.selfSigned,
encoding: userConn.encoding,
certExpired: false,
- stripColors: true
+ stripColors: userConn.stripColors
});
// add ourself as a connection
View
3 lib/models.js
@@ -26,6 +26,7 @@ module.exports = function (schema) {
, disabled_timeout: { type: Date } // do not allow the user to re-enable this connection until this date
, disabled_reason: { type: String } // why is this connection disabled? (could be user-initiated)
, keep_alive: { type: Boolean } // keep this connection active even if the user is disconnected
+ , stripColors: { type: Boolean } // Do not highlight colors
, temporary: { type: Boolean } // this was created for a guest (no account)
});
@@ -54,4 +55,4 @@ module.exports = function (schema) {
schema.autoupdate();
return schema;
-};
+};
View
1 lib/socket.js
@@ -149,6 +149,7 @@ module.exports = function(socket, app) {
, disabled_timeout: Date.now()
, disabled_reason: ''
, keep_alive: keepAlive
+ , stripColors: data.stripColors
, temporary: temp
}, function (err, item) {
if (!err) {
View
1 views/layout.jade
@@ -6,6 +6,7 @@ html
!= css('bootstrap.min')
!= css('subway')
!= css('subway-mobile')
+ != css('irc-colors')
script
var ENV = '#{env}',
View
3 views/templates.jade
@@ -89,6 +89,9 @@ script(id="overview_connection", type="text/html")
option(value="CP1251") CP1251 (Cyrillic)
option(value="CP1256") CP1256 (Arabic)
option(value="CP1257") CP1257 (baltic)
+ .control-group
+ label(for="connect-stripColors") No Colors
+ input#connect-stripColors(type="checkbox")
.control-group
{{#loggedIn}}
label.checkbox(for="connect-keep-alive", style="width:100%") Keep connection alive after browser closed

0 comments on commit 66f7aef

Please sign in to comment.
Something went wrong with that request. Please try again.