Added text color

This commit is contained in:
Mattias Erming 2014-10-11 01:11:57 +02:00
parent 681d3dac1a
commit d86005e84a
3 changed files with 112 additions and 45 deletions

View File

@ -870,6 +870,44 @@ button {
width: 58px; width: 58px;
} }
/**
* Colors
* http://clrs.cc/
*/
.color-0 { color: #fff; }
.color-1 { color: #000; }
.color-2 { color: #001f3f; }
.color-3 { color: #2ecc40; }
.color-4 { color: #ff4136; }
.color-5 { color: #85144b; }
.color-6 { color: #b10dc9; }
.color-7 { color: #ff851b; }
.color-8 { color: #ffdc00; }
.color-9 { color: #01ff70; }
.color-10 { color: #39cccc; }
.color-11 { color: #7fdbff; }
.color-12 { color: #0074d9; }
.color-13 { color: #f012be; }
.color-14 { color: #aaa; }
.color-15 { color: #ddd; }
.bg-0 { background: #fff; }
.bg-1 { background: #000; }
.bg-2 { background: #001f3f; }
.bg-3 { background: #2ecc40; }
.bg-4 { background: #ff4136; }
.bg-5 { background: #85144b; }
.bg-6 { background: #b10dc9; }
.bg-7 { background: #ff851b; }
.bg-8 { background: #ffdc00; }
.bg-9 { background: #01ff70; }
.bg-10 { background: #39cccc; }
.bg-11 { background: #7fdbff; }
.bg-12 { background: #0074d9; }
.bg-13 { background: #f012be; }
.bg-14 { background: #aaa; }
.bg-15 { background: #ddd; }
/** /**
* TrackpadScrollEmulator * TrackpadScrollEmulator
* Version: 1.0.6 * Version: 1.0.6

22
client/js/libs.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,28 @@
Handlebars.registerHelper(
"parse", function(text) {
var wrap = wraplong(text);
text = escape(text);
text = colors(text);
text = uri(text);
if (wrap) {
return "<i class='wrap'>" + text + "</i>";
} else {
return text;
}
}
);
function wraplong(text) {
var wrap = false;
var split = text.split(" ");
for (var i in split) {
if (split[i].length > 40) {
wrap = true;
}
}
return wrap;
}
function escape(text) { function escape(text) {
var e = { var e = {
"<": "&lt;", "<": "&lt;",
@ -9,45 +34,49 @@ function escape(text) {
}); });
} }
Handlebars.registerHelper( function uri(text) {
"parse", function(text) { return URI.withinString(text, function(url) {
text = uri(text); if (url.indexOf("javascript:") !== 0) {
text = wraplong(text); console.log(url);
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
} else {
return url;
}
});
}
function colors(text) {
if (!text) {
return text; return text;
} }
); var regex = /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/;
if (regex.test(text)) {
function uri(text) { var match;
var urls = []; while (match = regex.exec(text)) {
text = URI.withinString(text, function(url) { var color = "color-" + match[1];
urls.push(url); var bg = match[2];
return "$(" + (urls.length - 1) + ")"; if (bg) {
}); color += " bg-" + bg;
text = escape(text);
for (var i in urls) {
var url = escape(urls[i]);
var replace = url;
if (url.indexOf("javascript:") !== 0) {
replace = "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
} }
text = text.replace( var text = text.replace(
"$(" + i + ")", replace match[0],
"<span class='" + color + "'>" + match[3] + "</span>"
); );
} }
}
var styles = [
[/\002([^\002]+)(\002)?/, ["<b>", "</b>"]],
[/\037([^\037]+)(\037)?/, ["<u>", "</u>"]],
];
for (var i in styles) {
var regex = styles[i][0];
var style = styles[i][1];
if (regex.test(text)) {
var match;
while (match = regex.exec(text)) {
text = text.replace(match[0], style[0] + match[1] + style[1]);
}
}
}
return text; return text;
} }
function wraplong(text) {
var wrap = false;
var split = text.split(" ");
for (var i in split) {
if (split[i].length > 40) {
wrap = true;
}
}
if (wrap) {
return "<i class='wrap'>" + text + "</i>";
} else {
return text;
}
}