mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Added colors to pad diff
This commit is contained in:
parent
dcfb1b2ea4
commit
07a267be7a
6 changed files with 89 additions and 21 deletions
|
@ -618,7 +618,6 @@ exports.createDiff = function(padID, startRev, endRev, callback){
|
||||||
try {
|
try {
|
||||||
var padDiff = new PadDiff(pad, startRev, endRev);
|
var padDiff = new PadDiff(pad, startRev, endRev);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// console.warn(e.stack);
|
|
||||||
return callback({stop:e.message});
|
return callback({stop:e.message});
|
||||||
}
|
}
|
||||||
var html, authors;
|
var html, authors;
|
||||||
|
|
|
@ -24,6 +24,10 @@ var db = require("./DB").db;
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
||||||
|
|
||||||
|
exports.getColorPalette = function(){
|
||||||
|
return ["#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1", "#ff8f8f", "#ffe38f", "#c7ff8f", "#8fffab", "#8fffff", "#8fabff", "#c78fff", "#ff8fe3", "#d97979", "#d9c179", "#a9d979", "#79d991", "#79d9d9", "#7991d9", "#a979d9", "#d979c1", "#d9a9a9", "#d9cda9", "#c1d9a9", "#a9d9b5", "#a9d9d9", "#a9b5d9", "#c1a9d9", "#d9a9cd", "#4c9c82", "#12d1ad", "#2d8e80", "#7485c3", "#a091c7", "#3185ab", "#6818b4", "#e6e76d", "#a42c64", "#f386e5", "#4ecc0c", "#c0c236", "#693224", "#b5de6a", "#9b88fd", "#358f9b", "#496d2f", "#e267fe", "#d23056", "#1a1a64", "#5aa335", "#d722bb", "#86dc6c", "#b5a714", "#955b6a", "#9f2985", "#4b81c8", "#3d6a5b", "#434e16", "#d16084", "#af6a0e", "#8c8bd8"];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the author exists
|
* Checks if the author exists
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -227,7 +227,8 @@ Pad.prototype.getAllAuthorColors = function getAllAuthorColors(callback){
|
||||||
if(err){
|
if(err){
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
returnTable[author]=colorPalette[colorId];
|
//colorId might be a hex color or an number out of the palette
|
||||||
|
returnTable[author]=colorPalette[colorId] || colorId;
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1028,7 +1028,7 @@ function handleClientReady(client, message)
|
||||||
"globalPadId": message.padId,
|
"globalPadId": message.padId,
|
||||||
"time": currentTime,
|
"time": currentTime,
|
||||||
},
|
},
|
||||||
"colorPalette": ["#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1", "#ff8f8f", "#ffe38f", "#c7ff8f", "#8fffab", "#8fffff", "#8fabff", "#c78fff", "#ff8fe3", "#d97979", "#d9c179", "#a9d979", "#79d991", "#79d9d9", "#7991d9", "#a979d9", "#d979c1", "#d9a9a9", "#d9cda9", "#c1d9a9", "#a9d9b5", "#a9d9d9", "#a9b5d9", "#c1a9d9", "#d9a9cd", "#4c9c82", "#12d1ad", "#2d8e80", "#7485c3", "#a091c7", "#3185ab", "#6818b4", "#e6e76d", "#a42c64", "#f386e5", "#4ecc0c", "#c0c236", "#693224", "#b5de6a", "#9b88fd", "#358f9b", "#496d2f", "#e267fe", "#d23056", "#1a1a64", "#5aa335", "#d722bb", "#86dc6c", "#b5a714", "#955b6a", "#9f2985", "#4b81c8", "#3d6a5b", "#434e16", "#d16084", "#af6a0e", "#8c8bd8"],
|
"colorPalette": authorManager.getColorPalette(),
|
||||||
"clientIp": "127.0.0.1",
|
"clientIp": "127.0.0.1",
|
||||||
"userIsGuest": true,
|
"userIsGuest": true,
|
||||||
"userColor": authorColorId,
|
"userColor": authorColorId,
|
||||||
|
|
|
@ -92,7 +92,7 @@ function getPadHTML(pad, revNum, callback)
|
||||||
|
|
||||||
exports.getPadHTML = getPadHTML;
|
exports.getPadHTML = getPadHTML;
|
||||||
|
|
||||||
exports.getHTMLFromAtext = function(pad, atext)
|
exports.getHTMLFromAtext = function(pad, atext, authorColors)
|
||||||
{
|
{
|
||||||
var apool = pad.apool();
|
var apool = pad.apool();
|
||||||
var textLines = atext.text.slice(0, -1).split('\n');
|
var textLines = atext.text.slice(0, -1).split('\n');
|
||||||
|
@ -101,6 +101,42 @@ exports.getHTMLFromAtext = function(pad, atext)
|
||||||
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
||||||
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
||||||
var anumMap = {};
|
var anumMap = {};
|
||||||
|
var css = "";
|
||||||
|
|
||||||
|
var stripDotFromAuthorID = function(id){
|
||||||
|
return id.replace(/\./g,'_');
|
||||||
|
};
|
||||||
|
|
||||||
|
if(authorColors){
|
||||||
|
css+="<style>\n";
|
||||||
|
|
||||||
|
for (var a in apool.numToAttrib) {
|
||||||
|
var attr = apool.numToAttrib[a];
|
||||||
|
|
||||||
|
//skip non author attributes
|
||||||
|
if(attr[0] === "author" && attr[1] !== ""){
|
||||||
|
//add to props array
|
||||||
|
var propName = "author" + stripDotFromAuthorID(attr[1]);
|
||||||
|
var newLength = props.push(propName);
|
||||||
|
anumMap[a] = newLength -1;
|
||||||
|
|
||||||
|
css+="." + propName + " {background-color: " + authorColors[attr[1]]+ "}\n";
|
||||||
|
} else if(attr[0] === "removed") {
|
||||||
|
var propName = "removed";
|
||||||
|
|
||||||
|
var newLength = props.push(propName);
|
||||||
|
anumMap[a] = newLength -1;
|
||||||
|
|
||||||
|
css+=".removed {text-decoration: line-through; " +
|
||||||
|
"-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)'; "+
|
||||||
|
"filter: alpha(opacity=80); "+
|
||||||
|
"opacity: 0.8; "+
|
||||||
|
"}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
css+="</style>";
|
||||||
|
}
|
||||||
|
|
||||||
props.forEach(function (propName, i)
|
props.forEach(function (propName, i)
|
||||||
{
|
{
|
||||||
|
@ -125,22 +161,53 @@ exports.getHTMLFromAtext = function(pad, atext)
|
||||||
// <b>Just bold <i>Bold and italics</i></b> <i>Just italics</i>
|
// <b>Just bold <i>Bold and italics</i></b> <i>Just italics</i>
|
||||||
var taker = Changeset.stringIterator(text);
|
var taker = Changeset.stringIterator(text);
|
||||||
var assem = Changeset.stringAssembler();
|
var assem = Changeset.stringAssembler();
|
||||||
|
|
||||||
var openTags = [];
|
var openTags = [];
|
||||||
|
|
||||||
|
function getSpanClassFor(i){
|
||||||
|
//return if author colors are disabled
|
||||||
|
if (!authorColors) return false;
|
||||||
|
|
||||||
|
var property = props[i];
|
||||||
|
|
||||||
|
if(property.substr(0,6) === "author"){
|
||||||
|
return stripDotFromAuthorID(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(property === "removed"){
|
||||||
|
return "removed";
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function emitOpenTag(i)
|
function emitOpenTag(i)
|
||||||
{
|
{
|
||||||
openTags.unshift(i);
|
openTags.unshift(i);
|
||||||
assem.append('<');
|
var spanClass = getSpanClassFor(i);
|
||||||
assem.append(tags[i]);
|
|
||||||
assem.append('>');
|
if(spanClass){
|
||||||
|
assem.append('<span class="');
|
||||||
|
assem.append(spanClass);
|
||||||
|
assem.append('">');
|
||||||
|
} else {
|
||||||
|
assem.append('<');
|
||||||
|
assem.append(tags[i]);
|
||||||
|
assem.append('>');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitCloseTag(i)
|
function emitCloseTag(i)
|
||||||
{
|
{
|
||||||
openTags.shift();
|
openTags.shift();
|
||||||
assem.append('</');
|
var spanClass = getSpanClassFor(i);
|
||||||
assem.append(tags[i]);
|
|
||||||
assem.append('>');
|
if(spanClass){
|
||||||
|
assem.append('</span>');
|
||||||
|
} else {
|
||||||
|
assem.append('</');
|
||||||
|
assem.append(tags[i]);
|
||||||
|
assem.append('>');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function orderdCloseTags(tags2close)
|
function orderdCloseTags(tags2close)
|
||||||
|
@ -303,7 +370,7 @@ exports.getHTMLFromAtext = function(pad, atext)
|
||||||
|
|
||||||
return _processSpaces(assem.toString());
|
return _processSpaces(assem.toString());
|
||||||
} // end getLineHTML
|
} // end getLineHTML
|
||||||
var pieces = [];
|
var pieces = [css];
|
||||||
|
|
||||||
// Need to deal with constraints imposed on HTML lists; can
|
// Need to deal with constraints imposed on HTML lists; can
|
||||||
// only gain one level of nesting at once, can't change type
|
// only gain one level of nesting at once, can't change type
|
||||||
|
|
|
@ -244,17 +244,14 @@ PadDiff.prototype.getHtml = function(callback){
|
||||||
},
|
},
|
||||||
//get the authorColor table
|
//get the authorColor table
|
||||||
function(callback){
|
function(callback){
|
||||||
/*
|
self._pad.getAllAuthorColors(function(err, _authorColors){
|
||||||
self._pad.getAllAuthorColors(function(err, _authorColors){ // TODO
|
|
||||||
if(err){
|
if(err){
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
authorColors = _authorColors;
|
authorColors = _authorColors;
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
authorColors = {};
|
|
||||||
callback();
|
|
||||||
},
|
},
|
||||||
//convert the atext to html
|
//convert the atext to html
|
||||||
function(callback){
|
function(callback){
|
||||||
|
@ -265,7 +262,7 @@ PadDiff.prototype.getHtml = function(callback){
|
||||||
], function(err){
|
], function(err){
|
||||||
callback(err, html);
|
callback(err, html);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
PadDiff.prototype.getAuthors = function(callback){
|
PadDiff.prototype.getAuthors = function(callback){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
Loading…
Reference in a new issue