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;
}
/**
* 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
* 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) {
var e = {
"<": "&lt;",
@ -9,45 +34,49 @@ function escape(text) {
});
}
Handlebars.registerHelper(
"parse", function(text) {
text = uri(text);
text = wraplong(text);
function uri(text) {
return URI.withinString(text, function(url) {
if (url.indexOf("javascript:") !== 0) {
console.log(url);
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
} else {
return url;
}
});
}
function colors(text) {
if (!text) {
return text;
}
);
function uri(text) {
var urls = [];
text = URI.withinString(text, function(url) {
urls.push(url);
return "$(" + (urls.length - 1) + ")";
});
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>";
var regex = /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/;
if (regex.test(text)) {
var match;
while (match = regex.exec(text)) {
var color = "color-" + match[1];
var bg = match[2];
if (bg) {
color += " bg-" + bg;
}
text = text.replace(
"$(" + i + ")", replace
var text = text.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;
}
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;
}
}