mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
Merge branch 'master' of git://github.com/Pita/etherpad-lite
This commit is contained in:
commit
464b70a066
31 changed files with 1264 additions and 330 deletions
22
README.md
22
README.md
|
@ -9,8 +9,14 @@ documented codebase makes it easier for developers to improve the code and contr
|
|||
|
||||
Etherpad Lite is optimized to be easy embeddable. It provides a [HTTP API](https://github.com/Pita/etherpad-lite/wiki/HTTP-API)
|
||||
that allows your web application to manage pads, users and groups.
|
||||
You can use this [PHP Client](https://github.com/TomNomNom/etherpad-lite-client) to work with the API
|
||||
(If you don't want to use PHP, feel free to create a client for your favourite web development language).
|
||||
There are several clients in for this API:
|
||||
|
||||
* [PHP](https://github.com/TomNomNom/etherpad-lite-client), thx to [TomNomNom](https://github.com/TomNomNom)
|
||||
* [.Net](https://github.com/ja-jo/EtherpadLiteDotNet), thx to [ja-jo](https://github.com/ja-jo)
|
||||
* [Node.js](https://github.com/tomassedovic/etherpad-lite-client-js), thx to [tomassedovic](https://github.com/tomassedovic)
|
||||
* [Ruby](https://github.com/jhollinger/ruby-etherpad-lite), thx to [jhollinger](https://github.com/jhollinger)
|
||||
* [Python](https://github.com/devjones/PyEtherpadLite), thx to [devjones](https://github.com/devjones)
|
||||
|
||||
There is also a [jQuery plugin](https://github.com/johnyma22/etherpad-lite-jquery-plugin) that helps you to embed Pads into your website
|
||||
|
||||
**Online demo**<br>
|
||||
|
@ -51,12 +57,14 @@ Here is the **[FAQ](https://github.com/Pita/etherpad-lite/wiki/FAQ)**
|
|||
**As root:**
|
||||
|
||||
<ol>
|
||||
<li>Install the dependencies. We need the gzip, git, curl, libssl develop libraries and python <br><code>apt-get install gzip git-core curl python libssl-dev build-essential</code></li><br>
|
||||
<li>Install the dependencies. We need gzip, git, curl, libssl develop libraries, python and gcc. <br><i>For Debian/Ubuntu</i> <code>apt-get install gzip git-core curl python libssl-dev build-essential</code><br>
|
||||
<i>For Fedora/CentOS</i> <code>yum install gzip git-core curl python openssl-dev && yum groupinstall "Development Tools"</code>
|
||||
</li><br>
|
||||
<li>Install node.js
|
||||
<ol type="a">
|
||||
<li>Download the latest <b>0.4.x</b> node.js release from <a href="http://nodejs.org/#download">http://nodejs.org/#download</a></li>
|
||||
<li>Extract it with <code>tar xf node-v0.4*</code></li>
|
||||
<li>Move into the node folder <code>cd node-v0.4*</code> and build node with <code>./configure && make && make install</code></li>
|
||||
<li>Download the latest <b>0.6.x</b> node.js release from <a href="http://nodejs.org/#download">http://nodejs.org/#download</a></li>
|
||||
<li>Extract it with <code>tar xf node-v0.6*</code></li>
|
||||
<li>Move into the node folder <code>cd node-v0.6*</code> and build node with <code>./configure && make && make install</code></li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>Install npm <code>curl http://npmjs.org/install.sh | sh</code></li>
|
||||
|
@ -74,6 +82,8 @@ Here is the **[FAQ](https://github.com/Pita/etherpad-lite/wiki/FAQ)**
|
|||
## Next Steps
|
||||
You can modify the settings in the file `settings.json`
|
||||
|
||||
You should use a dedicated database such as "mysql" if you are planning on using etherpad-lite in a production environment, the "dirty" database driver is only for testing and/or development purposes.
|
||||
|
||||
You can update to the latest version with `git pull origin`. The next start with bin/run.sh will update the dependencies
|
||||
|
||||
Look at this wiki pages:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
NODE_VERSION="0.5.4"
|
||||
NODE_VERSION="0.6.1"
|
||||
|
||||
#Move to the folder where ep-lite is installed
|
||||
cd `dirname $0`
|
||||
|
@ -48,16 +48,6 @@ cp -rL node_modules node_modules_resolved
|
|||
rm -rf node_modules
|
||||
mv node_modules_resolved node_modules
|
||||
|
||||
echo "remove sqlite, cause we can't use it with windows..."
|
||||
rm -rf node_modules/ueberDB/node_modules/sqlite3
|
||||
|
||||
echo "replace log4js with a patched log4js, this log4js runs on windows too..."
|
||||
rm -rf node_modules/log4js/*
|
||||
wget https://github.com/Pita/log4js-node/zipball/master -O log4js.zip
|
||||
unzip log4js.zip
|
||||
mv Pita-log4js-node*/* node_modules/log4js
|
||||
rm -rf log4js.zip Pita-log4js-node*
|
||||
|
||||
echo "download windows node..."
|
||||
cd bin
|
||||
wget "http://nodejs.org/dist/v$NODE_VERSION/node.exe" -O node.exe
|
||||
|
|
|
@ -52,7 +52,7 @@ async.series([
|
|||
{
|
||||
log("get all padIds out of the database...");
|
||||
|
||||
etherpadDB.query("SELECT ID FROM PAD_META LIMIT", [], function(err, _padIDs)
|
||||
etherpadDB.query("SELECT ID FROM PAD_META", [], function(err, _padIDs)
|
||||
{
|
||||
padIDs = _padIDs;
|
||||
callback(err);
|
||||
|
@ -152,12 +152,15 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse the pages
|
||||
for(var i=0,length=results.length;i<length;i++)
|
||||
{
|
||||
parsePage(chatMessages, results[i].PAGESTART, results[i].OFFSETS, results[i].DATA, true);
|
||||
}
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
@ -171,12 +174,15 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse the pages
|
||||
for(var i=0,length=results.length;i<length;i++)
|
||||
{
|
||||
parsePage(changesets, results[i].PAGESTART, results[i].OFFSETS, results[i].DATA, false);
|
||||
}
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
@ -190,12 +196,15 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse the pages
|
||||
for(var i=0,length=results.length;i<length;i++)
|
||||
{
|
||||
parsePage(changesetsMeta, results[i].PAGESTART, results[i].OFFSETS, results[i].DATA, true);
|
||||
}
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
@ -209,8 +218,11 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
apool=JSON.parse(results[0].JSON).x;
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
@ -224,12 +236,15 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse the pages
|
||||
for(var i=0, length=results.length;i<length;i++)
|
||||
{
|
||||
parsePage(authors, results[i].PAGESTART, results[i].OFFSETS, results[i].DATA, true);
|
||||
}
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
@ -243,8 +258,11 @@ function convertPad(padId, callback)
|
|||
etherpadDB.query(sql, [padId], function(err, results)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
try
|
||||
{
|
||||
padmeta = JSON.parse(results[0].JSON).x;
|
||||
}catch(e) {err = e}
|
||||
}
|
||||
|
||||
callback(err);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"etherpad-db":
|
||||
"etherpadDB":
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
|
|
89
bin/extractPadData.js
Normal file
89
bin/extractPadData.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
This is a debug tool. It helps to extract all datas of a pad and move it from an productive enviroment and to a develop enviroment to reproduce bugs there. It outputs a dirtydb file
|
||||
*/
|
||||
|
||||
if(process.argv.length != 3)
|
||||
{
|
||||
console.error("Use: node extractPadData.js $PADID");
|
||||
process.exit(1);
|
||||
}
|
||||
//get the padID
|
||||
var padId = process.argv[2];
|
||||
|
||||
//initalize the database
|
||||
var log4js = require("log4js");
|
||||
log4js.setGlobalLogLevel("INFO");
|
||||
var async = require("async");
|
||||
var db = require('../node/db/DB');
|
||||
var dirty = require("dirty")(padId + ".db");
|
||||
var padManager;
|
||||
var pad;
|
||||
var neededDBValues = ["pad:"+padId];
|
||||
|
||||
async.series([
|
||||
//intallize the database
|
||||
function (callback)
|
||||
{
|
||||
db.init(callback);
|
||||
},
|
||||
//get the pad
|
||||
function (callback)
|
||||
{
|
||||
padManager = require('../node/db/PadManager');
|
||||
|
||||
padManager.getPad(padId, function(err, _pad)
|
||||
{
|
||||
pad = _pad;
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function (callback)
|
||||
{
|
||||
//add all authors
|
||||
var authors = pad.getAllAuthors();
|
||||
for(var i=0;i<authors.length;i++)
|
||||
{
|
||||
neededDBValues.push("globalAuthor:" + authors[i]);
|
||||
}
|
||||
|
||||
//add all revisions
|
||||
var revHead = pad.head;
|
||||
for(var i=0;i<=revHead;i++)
|
||||
{
|
||||
neededDBValues.push("pad:"+padId+":revs:" + i);
|
||||
}
|
||||
|
||||
//get all chat values
|
||||
var chatHead = pad.chatHead;
|
||||
for(var i=0;i<=chatHead;i++)
|
||||
{
|
||||
neededDBValues.push("pad:"+padId+":chat:" + i);
|
||||
}
|
||||
|
||||
//get and set all values
|
||||
async.forEach(neededDBValues, function(dbkey, callback)
|
||||
{
|
||||
db.db.db.wrappedDB.get(dbkey, function(err, dbvalue)
|
||||
{
|
||||
if(err) { callback(err); return}
|
||||
dbvalue=JSON.parse(dbvalue);
|
||||
|
||||
dirty.set(dbkey, dbvalue, callback);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
], function (err)
|
||||
{
|
||||
if(err) throw err;
|
||||
else
|
||||
{
|
||||
console.log("finished");
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
//get the pad object
|
||||
//get all revisions of this pad
|
||||
//get all authors related to this pad
|
||||
//get the readonly link releated to this pad
|
||||
//get the chat entrys releated to this pad
|
|
@ -47,9 +47,9 @@ npm install || {
|
|||
|
||||
echo "Ensure jQuery is downloaded and up to date..."
|
||||
DOWNLOAD_JQUERY="true"
|
||||
NEEDED_VERSION="1.6.2"
|
||||
NEEDED_VERSION="1.7"
|
||||
if [ -f "static/js/jquery.min.js" ]; then
|
||||
VERSION=$(cat static/js/jquery.min.js | head -n 2 | tail -n 1 | grep -o "v[0-9]*\.[0-9]*\.[0-9]*");
|
||||
VERSION=$(cat static/js/jquery.min.js | head -n 3 | grep -o "v[0-9].[0-9]");
|
||||
|
||||
if [ ${VERSION#v} = $NEEDED_VERSION ]; then
|
||||
DOWNLOAD_JQUERY="false"
|
||||
|
|
|
@ -26,6 +26,8 @@ var authorManager = require("./AuthorManager");
|
|||
var sessionManager = require("./SessionManager");
|
||||
var async = require("async");
|
||||
var exportHtml = require("../utils/ExportHtml");
|
||||
var importHtml = require("../utils/ImportHtml");
|
||||
var cleanText = require("./Pad").cleanText;
|
||||
|
||||
/**********************/
|
||||
/**GROUP FUNCTIONS*****/
|
||||
|
@ -254,6 +256,26 @@ exports.getHTML = function(padID, rev, callback)
|
|||
});
|
||||
}
|
||||
|
||||
exports.setHTML = function(padID, html, callback)
|
||||
{
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// add a new changeset with the new html to the pad
|
||||
importHtml.setPadHTML(pad, cleanText(html));
|
||||
|
||||
//update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/**PAD FUNCTIONS */
|
||||
/*****************/
|
||||
|
|
|
@ -23,6 +23,7 @@ var async = require("async");
|
|||
var authorManager = require("./AuthorManager");
|
||||
var padManager = require("./PadManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
var settings = require("../utils/Settings")
|
||||
|
||||
/**
|
||||
* This function controlls the access to a pad, it checks if the user can access a pad.
|
||||
|
@ -34,19 +35,53 @@ var sessionManager = require("./SessionManager");
|
|||
*/
|
||||
exports.checkAccess = function (padID, sessionID, token, password, callback)
|
||||
{
|
||||
var statusObject;
|
||||
|
||||
// a valid session is required (api-only mode)
|
||||
if(settings.requireSession)
|
||||
{
|
||||
// no sessionID, access is denied
|
||||
if(!sessionID)
|
||||
{
|
||||
callback(null, {accessStatus: "deny"});
|
||||
return;
|
||||
}
|
||||
}
|
||||
// a session is not required, so we'll check if it's a public pad
|
||||
else
|
||||
{
|
||||
// it's not a group pad, means we can grant access
|
||||
if(padID.indexOf("$") == -1)
|
||||
{
|
||||
//get author for this token
|
||||
authorManager.getAuthor4Token(token, function(err, author)
|
||||
{
|
||||
// assume user has access
|
||||
statusObject = {accessStatus: "grant", authorID: author};
|
||||
// user can't create pads
|
||||
if(settings.editOnly)
|
||||
{
|
||||
// check if pad exists
|
||||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
// pad doesn't exist - user can't have access
|
||||
if(!exists) statusObject.accessStatus = "deny";
|
||||
// grant or deny access, with author of token
|
||||
callback(err, statusObject);
|
||||
});
|
||||
}
|
||||
// user may create new pads - no need to check anything
|
||||
else
|
||||
{
|
||||
// grant access, with author of token
|
||||
callback(err, {accessStatus: "grant", authorID: author});
|
||||
callback(err, statusObject);
|
||||
}
|
||||
})
|
||||
|
||||
//don't continue
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var groupID = padID.split("$")[0];
|
||||
var padExists = false;
|
||||
|
@ -57,8 +92,6 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
var isPasswordProtected;
|
||||
var passwordStatus = password == null ? "notGiven" : "wrong"; // notGiven, correct, wrong
|
||||
|
||||
var statusObject;
|
||||
|
||||
async.series([
|
||||
//get basic informations from the database
|
||||
function(callback)
|
||||
|
@ -180,6 +213,8 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
{
|
||||
//--> grant access
|
||||
statusObject = {accessStatus: "grant", authorID: sessionAuthor};
|
||||
//--> deny access if user isn't allowed to create the pad
|
||||
if(settings.editOnly) statusObject.accessStatus = "deny";
|
||||
}
|
||||
// there is no valid session avaiable AND pad exists
|
||||
else if(!validSession && padExists)
|
||||
|
|
|
@ -51,6 +51,7 @@ var functions = {
|
|||
"getText" : ["padID", "rev"],
|
||||
"setText" : ["padID", "text"],
|
||||
"getHTML" : ["padID", "rev"],
|
||||
"setHTML" : ["padID", "html"],
|
||||
"getRevisionsCount" : ["padID"],
|
||||
"deletePad" : ["padID"],
|
||||
"getReadOnlyID" : ["padID"],
|
||||
|
@ -70,7 +71,7 @@ var functions = {
|
|||
exports.handle = function(functionName, fields, req, res)
|
||||
{
|
||||
//check the api key!
|
||||
if(fields["apikey"] != apikey)
|
||||
if(fields["apikey"] != apikey.trim())
|
||||
{
|
||||
res.send({code: 4, message: "no or wrong API Key", data: null});
|
||||
return;
|
||||
|
|
|
@ -81,7 +81,7 @@ exports.doImport = function(req, res, padId)
|
|||
//this allows us to accept source code files like .c or .java
|
||||
function(callback)
|
||||
{
|
||||
var fileEnding = srcFile.split(".")[1];
|
||||
var fileEnding = srcFile.split(".")[1].toLowerCase();
|
||||
var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"];
|
||||
|
||||
//find out if this is a known file ending
|
||||
|
@ -112,7 +112,7 @@ exports.doImport = function(req, res, padId)
|
|||
//convert file to text
|
||||
function(callback)
|
||||
{
|
||||
var randNum = Math.floor(Math.random()*new Date().getTime());
|
||||
var randNum = Math.floor(Math.random()*0xFFFFFFFF);
|
||||
destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
|
||||
abiword.convertFile(srcFile, destFile, "txt", callback);
|
||||
},
|
||||
|
@ -136,10 +136,13 @@ exports.doImport = function(req, res, padId)
|
|||
|
||||
//node on windows has a delay on releasing of the file lock.
|
||||
//We add a 100ms delay to work around this
|
||||
if(os.type().indexOf("Windows") > -1)
|
||||
{
|
||||
setTimeout(function()
|
||||
{
|
||||
callback(err);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -190,10 +190,10 @@ exports.handleMessage = function(client, message)
|
|||
{
|
||||
handleSuggestUserName(client, message);
|
||||
}
|
||||
//if the message type is unkown, throw an exception
|
||||
//if the message type is unknown, throw an exception
|
||||
else
|
||||
{
|
||||
messageLogger.warn("Dropped message, unkown Message Type " + message.type + ": " + JSON.stringify(message));
|
||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,22 +600,22 @@ function handleClientReady(client, message)
|
|||
//check if all ok
|
||||
if(!message.token)
|
||||
{
|
||||
messageLogger.warn("Dropped message, CLIENT_READY message has no token!");
|
||||
messageLogger.warn("Dropped message, CLIENT_READY Message has no token!");
|
||||
return;
|
||||
}
|
||||
if(!message.padId)
|
||||
{
|
||||
messageLogger.warn("Dropped message, CLIENT_READY message has no padId!");
|
||||
messageLogger.warn("Dropped message, CLIENT_READY Message has no padId!");
|
||||
return;
|
||||
}
|
||||
if(!message.protocolVersion)
|
||||
{
|
||||
messageLogger.warn("Dropped message, CLIENT_READY message has no protocolVersion!");
|
||||
messageLogger.warn("Dropped message, CLIENT_READY Message has no protocolVersion!");
|
||||
return;
|
||||
}
|
||||
if(message.protocolVersion != 2)
|
||||
{
|
||||
messageLogger.warn("Dropped message, CLIENT_READY message has an unkown protocolVersion '" + message.protocolVersion + "'!");
|
||||
messageLogger.warn("Dropped message, CLIENT_READY Message has a unknown protocolVersion '" + message.protocolVersion + "'!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -806,8 +806,20 @@ function handleClientReady(client, message)
|
|||
clientVars.userName = authorName;
|
||||
}
|
||||
|
||||
//This is a reconnect, so we don't have to send the client the ClientVars again
|
||||
if(message.reconnect == true)
|
||||
{
|
||||
//Save the revision in sessioninfos, we take the revision from the info the client send to us
|
||||
sessioninfos[client.id].rev = message.client_rev;
|
||||
}
|
||||
//This is a normal first connect
|
||||
else
|
||||
{
|
||||
//Send the clientVars to the Client
|
||||
client.json.send(clientVars);
|
||||
//Save the revision in sessioninfos
|
||||
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
||||
}
|
||||
|
||||
//Save the revision and the author id in sessioninfos
|
||||
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
||||
|
|
|
@ -128,7 +128,7 @@ exports.setSocketIO = function(_socket)
|
|||
//drop message
|
||||
else
|
||||
{
|
||||
messageLogger.warn("Droped message cause of bad permissions:" + stringifyWithoutPassword(message));
|
||||
messageLogger.warn("Dropped message cause of bad permissions:" + stringifyWithoutPassword(message));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -77,7 +77,7 @@ exports.handleMessage = function(client, message)
|
|||
//if the message type is unkown, throw an exception
|
||||
else
|
||||
{
|
||||
messageLogger.warn("Dropped message, unkown Message Type: '" + message.type + "'");
|
||||
messageLogger.warn("Dropped message, unknown Message Type: '" + message.type + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,9 @@ async.waterfall([
|
|||
var httpLogger = log4js.getLogger("http");
|
||||
app.configure(function()
|
||||
{
|
||||
// If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158.
|
||||
// Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway.
|
||||
if (!(settings.loglevel === "WARN" || settings.loglevel == "ERROR"))
|
||||
app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.INFO, format: ':status, :method :url'}));
|
||||
app.use(express.cookieParser());
|
||||
});
|
||||
|
@ -288,13 +291,12 @@ async.waterfall([
|
|||
|
||||
var apiLogger = log4js.getLogger("API");
|
||||
|
||||
//This is a api call, collect all post informations and pass it to the apiHandler
|
||||
app.get('/api/1/:func', function(req, res)
|
||||
{
|
||||
//This is for making an api call, collecting all post information and passing it to the apiHandler
|
||||
var apiCaller = function(req, res, fields) {
|
||||
res.header("Server", serverName);
|
||||
res.header("Content-Type", "application/json; charset=utf-8");
|
||||
|
||||
apiLogger.info("REQUEST, " + req.params.func + ", " + JSON.stringify(req.query));
|
||||
apiLogger.info("REQUEST, " + req.params.func + ", " + JSON.stringify(fields));
|
||||
|
||||
//wrap the send function so we can log the response
|
||||
res._send = res.send;
|
||||
|
@ -311,7 +313,22 @@ async.waterfall([
|
|||
}
|
||||
|
||||
//call the api handler
|
||||
apiHandler.handle(req.params.func, req.query, req, res);
|
||||
apiHandler.handle(req.params.func, fields, req, res);
|
||||
}
|
||||
|
||||
//This is a api GET call, collect all post informations and pass it to the apiHandler
|
||||
app.get('/api/1/:func', function(req, res)
|
||||
{
|
||||
apiCaller(req, res, req.query)
|
||||
});
|
||||
|
||||
//This is a api POST call, collect all post informations and pass it to the apiHandler
|
||||
app.post('/api/1/:func', function(req, res)
|
||||
{
|
||||
new formidable.IncomingForm().parse(req, function(err, fields, files)
|
||||
{
|
||||
apiCaller(req, res, fields)
|
||||
});
|
||||
});
|
||||
|
||||
//The Etherpad client side sends information about how a disconnect happen
|
||||
|
@ -425,19 +442,19 @@ async.waterfall([
|
|||
io.set('logger', {
|
||||
debug: function (str)
|
||||
{
|
||||
socketIOLogger.debug(str);
|
||||
socketIOLogger.debug.apply(socketIOLogger, arguments);
|
||||
},
|
||||
info: function (str)
|
||||
{
|
||||
socketIOLogger.info(str);
|
||||
socketIOLogger.info.apply(socketIOLogger, arguments);
|
||||
},
|
||||
warn: function (str)
|
||||
{
|
||||
socketIOLogger.warn(str);
|
||||
socketIOLogger.warn.apply(socketIOLogger, arguments);
|
||||
},
|
||||
error: function (str)
|
||||
{
|
||||
socketIOLogger.error(str);
|
||||
socketIOLogger.error.apply(socketIOLogger, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
92
node/utils/ImportHtml.js
Normal file
92
node/utils/ImportHtml.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* Copyright Yaco Sistemas S.L. 2011.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var jsdom = require('jsdom').jsdom;
|
||||
var log4js = require('log4js');
|
||||
|
||||
var Changeset = require("./Changeset");
|
||||
var contentcollector = require("./contentcollector");
|
||||
var map = require("../../static/js/ace2_common.js").map;
|
||||
|
||||
function setPadHTML(pad, html, callback)
|
||||
{
|
||||
var apiLogger = log4js.getLogger("ImportHtml");
|
||||
|
||||
// Clean the pad. This makes the rest of the code easier
|
||||
// by several orders of magnitude.
|
||||
pad.setText("");
|
||||
var padText = pad.text();
|
||||
|
||||
// Parse the incoming HTML with jsdom
|
||||
var doc = jsdom(html.replace(/>\n+</g, '><'));
|
||||
apiLogger.debug('html:');
|
||||
apiLogger.debug(html);
|
||||
|
||||
// Convert a dom tree into a list of lines and attribute liens
|
||||
// using the content collector object
|
||||
var cc = contentcollector.makeContentCollector(true, null, pad.pool);
|
||||
cc.collectContent(doc.childNodes[0]);
|
||||
var result = cc.finish();
|
||||
apiLogger.debug('Lines:');
|
||||
var i;
|
||||
for (i = 0; i < result.lines.length; i += 1)
|
||||
{
|
||||
apiLogger.debug('Line ' + (i + 1) + ' text: ' + result.lines[i]);
|
||||
apiLogger.debug('Line ' + (i + 1) + ' attributes: ' + result.lineAttribs[i]);
|
||||
}
|
||||
|
||||
// Get the new plain text and its attributes
|
||||
var newText = map(result.lines, function (e) {
|
||||
return e + '\n';
|
||||
}).join('');
|
||||
apiLogger.debug('newText:');
|
||||
apiLogger.debug(newText);
|
||||
var newAttribs = result.lineAttribs.join('|1+1') + '|1+1';
|
||||
|
||||
function eachAttribRun(attribs, func /*(startInNewText, endInNewText, attribs)*/ )
|
||||
{
|
||||
var attribsIter = Changeset.opIterator(attribs);
|
||||
var textIndex = 0;
|
||||
var newTextStart = 0;
|
||||
var newTextEnd = newText.length - 1;
|
||||
while (attribsIter.hasNext())
|
||||
{
|
||||
var op = attribsIter.next();
|
||||
var nextIndex = textIndex + op.chars;
|
||||
if (!(nextIndex <= newTextStart || textIndex >= newTextEnd))
|
||||
{
|
||||
func(Math.max(newTextStart, textIndex), Math.min(newTextEnd, nextIndex), op.attribs);
|
||||
}
|
||||
textIndex = nextIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// create a new changeset with a helper builder object
|
||||
var builder = Changeset.builder(1);
|
||||
|
||||
// assemble each line into the builder
|
||||
eachAttribRun(newAttribs, function(start, end, attribs)
|
||||
{
|
||||
builder.insert(newText.substring(start, end), attribs);
|
||||
});
|
||||
|
||||
// the changeset is ready!
|
||||
var theChangeset = builder.toString();
|
||||
apiLogger.debug('The changeset: ' + theChangeset);
|
||||
pad.appendRevision(theChangeset);
|
||||
}
|
||||
|
||||
exports.setPadHTML = setPadHTML;
|
|
@ -42,6 +42,17 @@ exports.dbSettings = { "filename" : "../var/dirty.db" };
|
|||
* The default Text of a new pad
|
||||
*/
|
||||
exports.defaultPadText = "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n";
|
||||
|
||||
/**
|
||||
* A flag that requires any user to have a valid session (via the api) before accessing a pad
|
||||
*/
|
||||
exports.requireSession = false;
|
||||
|
||||
/**
|
||||
* A flag that prevents users from creating new pads
|
||||
*/
|
||||
exports.editOnly = false;
|
||||
|
||||
/**
|
||||
* A flag that shows if minification is enabled or not
|
||||
*/
|
||||
|
|
692
node/utils/contentcollector.js
Normal file
692
node/utils/contentcollector.js
Normal file
|
@ -0,0 +1,692 @@
|
|||
// THIS FILE IS ALSO AN APPJET MODULE: etherpad.collab.ace.contentcollector
|
||||
// %APPJET%: import("etherpad.collab.ace.easysync2.Changeset");
|
||||
// %APPJET%: import("etherpad.admin.plugins");
|
||||
/**
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Changeset = require("../utils/Changeset");
|
||||
|
||||
var _MAX_LIST_LEVEL = 8;
|
||||
|
||||
function sanitizeUnicode(s)
|
||||
{
|
||||
return s.replace(/[\uffff\ufffe\ufeff\ufdd0-\ufdef\ud800-\udfff]/g, '?');
|
||||
}
|
||||
|
||||
function makeContentCollector(collectStyles, browser, apool, domInterface, className2Author)
|
||||
{
|
||||
browser = browser || {};
|
||||
|
||||
var plugins_;
|
||||
if (typeof(plugins) != 'undefined')
|
||||
{
|
||||
plugins_ = plugins;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins_ = {callHook: function () {}};
|
||||
}
|
||||
|
||||
var dom = domInterface || {
|
||||
isNodeText: function(n)
|
||||
{
|
||||
return (n.nodeType == 3);
|
||||
},
|
||||
nodeTagName: function(n)
|
||||
{
|
||||
return n.tagName;
|
||||
},
|
||||
nodeValue: function(n)
|
||||
{
|
||||
return n.nodeValue;
|
||||
},
|
||||
nodeNumChildren: function(n)
|
||||
{
|
||||
return n.childNodes.length;
|
||||
},
|
||||
nodeChild: function(n, i)
|
||||
{
|
||||
return n.childNodes.item(i);
|
||||
},
|
||||
nodeProp: function(n, p)
|
||||
{
|
||||
return n[p];
|
||||
},
|
||||
nodeAttr: function(n, a)
|
||||
{
|
||||
return n.getAttribute(a);
|
||||
},
|
||||
optNodeInnerHTML: function(n)
|
||||
{
|
||||
return n.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
var _blockElems = {
|
||||
"div": 1,
|
||||
"p": 1,
|
||||
"pre": 1,
|
||||
"li": 1
|
||||
};
|
||||
|
||||
function isBlockElement(n)
|
||||
{
|
||||
return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()];
|
||||
}
|
||||
|
||||
function textify(str)
|
||||
{
|
||||
return sanitizeUnicode(
|
||||
str.replace(/[\n\r ]/g, ' ').replace(/\xa0/g, ' ').replace(/\t/g, ' '));
|
||||
}
|
||||
|
||||
function getAssoc(node, name)
|
||||
{
|
||||
return dom.nodeProp(node, "_magicdom_" + name);
|
||||
}
|
||||
|
||||
var lines = (function()
|
||||
{
|
||||
var textArray = [];
|
||||
var attribsArray = [];
|
||||
var attribsBuilder = null;
|
||||
var op = Changeset.newOp('+');
|
||||
var self = {
|
||||
length: function()
|
||||
{
|
||||
return textArray.length;
|
||||
},
|
||||
atColumnZero: function()
|
||||
{
|
||||
return textArray[textArray.length - 1] === "";
|
||||
},
|
||||
startNew: function()
|
||||
{
|
||||
textArray.push("");
|
||||
self.flush(true);
|
||||
attribsBuilder = Changeset.smartOpAssembler();
|
||||
},
|
||||
textOfLine: function(i)
|
||||
{
|
||||
return textArray[i];
|
||||
},
|
||||
appendText: function(txt, attrString)
|
||||
{
|
||||
textArray[textArray.length - 1] += txt;
|
||||
//dmesg(txt+" / "+attrString);
|
||||
op.attribs = attrString;
|
||||
op.chars = txt.length;
|
||||
attribsBuilder.append(op);
|
||||
},
|
||||
textLines: function()
|
||||
{
|
||||
return textArray.slice();
|
||||
},
|
||||
attribLines: function()
|
||||
{
|
||||
return attribsArray;
|
||||
},
|
||||
// call flush only when you're done
|
||||
flush: function(withNewline)
|
||||
{
|
||||
if (attribsBuilder)
|
||||
{
|
||||
attribsArray.push(attribsBuilder.toString());
|
||||
attribsBuilder = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
self.startNew();
|
||||
return self;
|
||||
}());
|
||||
var cc = {};
|
||||
|
||||
function _ensureColumnZero(state)
|
||||
{
|
||||
if (!lines.atColumnZero())
|
||||
{
|
||||
cc.startNewLine(state);
|
||||
}
|
||||
}
|
||||
var selection, startPoint, endPoint;
|
||||
var selStart = [-1, -1],
|
||||
selEnd = [-1, -1];
|
||||
var blockElems = {
|
||||
"div": 1,
|
||||
"p": 1,
|
||||
"pre": 1
|
||||
};
|
||||
|
||||
function _isEmpty(node, state)
|
||||
{
|
||||
// consider clean blank lines pasted in IE to be empty
|
||||
if (dom.nodeNumChildren(node) == 0) return true;
|
||||
if (dom.nodeNumChildren(node) == 1 && getAssoc(node, "shouldBeEmpty") && dom.optNodeInnerHTML(node) == " " && !getAssoc(node, "unpasted"))
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
var child = dom.nodeChild(node, 0);
|
||||
_reachPoint(child, 0, state);
|
||||
_reachPoint(child, 1, state);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _pointHere(charsAfter, state)
|
||||
{
|
||||
var ln = lines.length() - 1;
|
||||
var chr = lines.textOfLine(ln).length;
|
||||
if (chr == 0 && state.listType && state.listType != 'none')
|
||||
{
|
||||
chr += 1; // listMarker
|
||||
}
|
||||
chr += charsAfter;
|
||||
return [ln, chr];
|
||||
}
|
||||
|
||||
function _reachBlockPoint(nd, idx, state)
|
||||
{
|
||||
if (!dom.isNodeText(nd)) _reachPoint(nd, idx, state);
|
||||
}
|
||||
|
||||
function _reachPoint(nd, idx, state)
|
||||
{
|
||||
if (startPoint && nd == startPoint.node && startPoint.index == idx)
|
||||
{
|
||||
selStart = _pointHere(0, state);
|
||||
}
|
||||
if (endPoint && nd == endPoint.node && endPoint.index == idx)
|
||||
{
|
||||
selEnd = _pointHere(0, state);
|
||||
}
|
||||
}
|
||||
cc.incrementFlag = function(state, flagName)
|
||||
{
|
||||
state.flags[flagName] = (state.flags[flagName] || 0) + 1;
|
||||
}
|
||||
cc.decrementFlag = function(state, flagName)
|
||||
{
|
||||
state.flags[flagName]--;
|
||||
}
|
||||
cc.incrementAttrib = function(state, attribName)
|
||||
{
|
||||
if (!state.attribs[attribName])
|
||||
{
|
||||
state.attribs[attribName] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.attribs[attribName]++;
|
||||
}
|
||||
_recalcAttribString(state);
|
||||
}
|
||||
cc.decrementAttrib = function(state, attribName)
|
||||
{
|
||||
state.attribs[attribName]--;
|
||||
_recalcAttribString(state);
|
||||
}
|
||||
|
||||
function _enterList(state, listType)
|
||||
{
|
||||
var oldListType = state.listType;
|
||||
state.listLevel = (state.listLevel || 0) + 1;
|
||||
if (listType != 'none')
|
||||
{
|
||||
state.listNesting = (state.listNesting || 0) + 1;
|
||||
}
|
||||
state.listType = listType;
|
||||
_recalcAttribString(state);
|
||||
return oldListType;
|
||||
}
|
||||
|
||||
function _exitList(state, oldListType)
|
||||
{
|
||||
state.listLevel--;
|
||||
if (state.listType != 'none')
|
||||
{
|
||||
state.listNesting--;
|
||||
}
|
||||
state.listType = oldListType;
|
||||
_recalcAttribString(state);
|
||||
}
|
||||
|
||||
function _enterAuthor(state, author)
|
||||
{
|
||||
var oldAuthor = state.author;
|
||||
state.authorLevel = (state.authorLevel || 0) + 1;
|
||||
state.author = author;
|
||||
_recalcAttribString(state);
|
||||
return oldAuthor;
|
||||
}
|
||||
|
||||
function _exitAuthor(state, oldAuthor)
|
||||
{
|
||||
state.authorLevel--;
|
||||
state.author = oldAuthor;
|
||||
_recalcAttribString(state);
|
||||
}
|
||||
|
||||
function _recalcAttribString(state)
|
||||
{
|
||||
var lst = [];
|
||||
for (var a in state.attribs)
|
||||
{
|
||||
if (state.attribs[a])
|
||||
{
|
||||
lst.push([a, 'true']);
|
||||
}
|
||||
}
|
||||
if (state.authorLevel > 0)
|
||||
{
|
||||
var authorAttrib = ['author', state.author];
|
||||
if (apool.putAttrib(authorAttrib, true) >= 0)
|
||||
{
|
||||
// require that author already be in pool
|
||||
// (don't add authors from other documents, etc.)
|
||||
lst.push(authorAttrib);
|
||||
}
|
||||
}
|
||||
state.attribString = Changeset.makeAttribsString('+', lst, apool);
|
||||
}
|
||||
|
||||
function _produceListMarker(state)
|
||||
{
|
||||
lines.appendText('*', Changeset.makeAttribsString('+', [
|
||||
['list', state.listType],
|
||||
['insertorder', 'first']
|
||||
], apool));
|
||||
}
|
||||
cc.startNewLine = function(state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0;
|
||||
if (atBeginningOfLine && state.listType && state.listType != 'none')
|
||||
{
|
||||
_produceListMarker(state);
|
||||
}
|
||||
}
|
||||
lines.startNew();
|
||||
}
|
||||
cc.notifySelection = function(sel)
|
||||
{
|
||||
if (sel)
|
||||
{
|
||||
selection = sel;
|
||||
startPoint = selection.startPoint;
|
||||
endPoint = selection.endPoint;
|
||||
}
|
||||
};
|
||||
cc.doAttrib = function(state, na)
|
||||
{
|
||||
state.localAttribs = (state.localAttribs || []);
|
||||
state.localAttribs.push(na);
|
||||
cc.incrementAttrib(state, na);
|
||||
};
|
||||
cc.collectContent = function(node, state)
|
||||
{
|
||||
if (!state)
|
||||
{
|
||||
state = {
|
||||
flags: { /*name -> nesting counter*/
|
||||
},
|
||||
localAttribs: null,
|
||||
attribs: { /*name -> nesting counter*/
|
||||
},
|
||||
attribString: ''
|
||||
};
|
||||
}
|
||||
var localAttribs = state.localAttribs;
|
||||
state.localAttribs = null;
|
||||
var isBlock = isBlockElement(node);
|
||||
var isEmpty = _isEmpty(node, state);
|
||||
if (isBlock) _ensureColumnZero(state);
|
||||
var startLine = lines.length() - 1;
|
||||
_reachBlockPoint(node, 0, state);
|
||||
if (dom.isNodeText(node))
|
||||
{
|
||||
var txt = dom.nodeValue(node);
|
||||
var rest = '';
|
||||
var x = 0; // offset into original text
|
||||
if (txt.length == 0)
|
||||
{
|
||||
if (startPoint && node == startPoint.node)
|
||||
{
|
||||
selStart = _pointHere(0, state);
|
||||
}
|
||||
if (endPoint && node == endPoint.node)
|
||||
{
|
||||
selEnd = _pointHere(0, state);
|
||||
}
|
||||
}
|
||||
while (txt.length > 0)
|
||||
{
|
||||
var consumed = 0;
|
||||
if (state.flags.preMode)
|
||||
{
|
||||
var firstLine = txt.split('\n', 1)[0];
|
||||
consumed = firstLine.length + 1;
|
||||
rest = txt.substring(consumed);
|
||||
txt = firstLine;
|
||||
}
|
||||
else
|
||||
{ /* will only run this loop body once */
|
||||
}
|
||||
if (startPoint && node == startPoint.node && startPoint.index - x <= txt.length)
|
||||
{
|
||||
selStart = _pointHere(startPoint.index - x, state);
|
||||
}
|
||||
if (endPoint && node == endPoint.node && endPoint.index - x <= txt.length)
|
||||
{
|
||||
selEnd = _pointHere(endPoint.index - x, state);
|
||||
}
|
||||
var txt2 = txt;
|
||||
if ((!state.flags.preMode) && /^[\r\n]*$/.exec(txt))
|
||||
{
|
||||
// prevents textnodes containing just "\n" from being significant
|
||||
// in safari when pasting text, now that we convert them to
|
||||
// spaces instead of removing them, because in other cases
|
||||
// removing "\n" from pasted HTML will collapse words together.
|
||||
txt2 = "";
|
||||
}
|
||||
var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0;
|
||||
if (atBeginningOfLine)
|
||||
{
|
||||
// newlines in the source mustn't become spaces at beginning of line box
|
||||
txt2 = txt2.replace(/^\n*/, '');
|
||||
}
|
||||
if (atBeginningOfLine && state.listType && state.listType != 'none')
|
||||
{
|
||||
_produceListMarker(state);
|
||||
}
|
||||
lines.appendText(textify(txt2), state.attribString);
|
||||
x += consumed;
|
||||
txt = rest;
|
||||
if (txt.length > 0)
|
||||
{
|
||||
cc.startNewLine(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var tname = (dom.nodeTagName(node) || "").toLowerCase();
|
||||
if (tname == "br")
|
||||
{
|
||||
cc.startNewLine(state);
|
||||
}
|
||||
else if (tname == "script" || tname == "style")
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
else if (!isEmpty)
|
||||
{
|
||||
var styl = dom.nodeAttr(node, "style");
|
||||
var cls = dom.nodeProp(node, "className");
|
||||
|
||||
var isPre = (tname == "pre");
|
||||
if ((!isPre) && browser.safari)
|
||||
{
|
||||
isPre = (styl && /\bwhite-space:\s*pre\b/i.exec(styl));
|
||||
}
|
||||
if (isPre) cc.incrementFlag(state, 'preMode');
|
||||
var oldListTypeOrNull = null;
|
||||
var oldAuthorOrNull = null;
|
||||
if (collectStyles)
|
||||
{
|
||||
plugins_.callHook('collectContentPre', {
|
||||
cc: cc,
|
||||
state: state,
|
||||
tname: tname,
|
||||
styl: styl,
|
||||
cls: cls
|
||||
});
|
||||
if (tname == "b" || (styl && /\bfont-weight:\s*bold\b/i.exec(styl)) || tname == "strong")
|
||||
{
|
||||
cc.doAttrib(state, "bold");
|
||||
}
|
||||
if (tname == "i" || (styl && /\bfont-style:\s*italic\b/i.exec(styl)) || tname == "em")
|
||||
{
|
||||
cc.doAttrib(state, "italic");
|
||||
}
|
||||
if (tname == "u" || (styl && /\btext-decoration:\s*underline\b/i.exec(styl)) || tname == "ins")
|
||||
{
|
||||
cc.doAttrib(state, "underline");
|
||||
}
|
||||
if (tname == "s" || (styl && /\btext-decoration:\s*line-through\b/i.exec(styl)) || tname == "del")
|
||||
{
|
||||
cc.doAttrib(state, "strikethrough");
|
||||
}
|
||||
if (tname == "ul")
|
||||
{
|
||||
var type;
|
||||
var rr = cls && /(?:^| )list-(bullet[12345678])\b/.exec(cls);
|
||||
type = rr && rr[1] || "bullet" + String(Math.min(_MAX_LIST_LEVEL, (state.listNesting || 0) + 1));
|
||||
oldListTypeOrNull = (_enterList(state, type) || 'none');
|
||||
}
|
||||
else if ((tname == "div" || tname == "p") && cls && cls.match(/(?:^| )ace-line\b/))
|
||||
{
|
||||
oldListTypeOrNull = (_enterList(state, type) || 'none');
|
||||
}
|
||||
if (className2Author && cls)
|
||||
{
|
||||
var classes = cls.match(/\S+/g);
|
||||
if (classes && classes.length > 0)
|
||||
{
|
||||
for (var i = 0; i < classes.length; i++)
|
||||
{
|
||||
var c = classes[i];
|
||||
var a = className2Author(c);
|
||||
if (a)
|
||||
{
|
||||
oldAuthorOrNull = (_enterAuthor(state, a) || 'none');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var nc = dom.nodeNumChildren(node);
|
||||
for (var i = 0; i < nc; i++)
|
||||
{
|
||||
var c = dom.nodeChild(node, i);
|
||||
cc.collectContent(c, state);
|
||||
}
|
||||
|
||||
if (collectStyles)
|
||||
{
|
||||
plugins_.callHook('collectContentPost', {
|
||||
cc: cc,
|
||||
state: state,
|
||||
tname: tname,
|
||||
styl: styl,
|
||||
cls: cls
|
||||
});
|
||||
}
|
||||
|
||||
if (isPre) cc.decrementFlag(state, 'preMode');
|
||||
if (state.localAttribs)
|
||||
{
|
||||
for (var i = 0; i < state.localAttribs.length; i++)
|
||||
{
|
||||
cc.decrementAttrib(state, state.localAttribs[i]);
|
||||
}
|
||||
}
|
||||
if (oldListTypeOrNull)
|
||||
{
|
||||
_exitList(state, oldListTypeOrNull);
|
||||
}
|
||||
if (oldAuthorOrNull)
|
||||
{
|
||||
_exitAuthor(state, oldAuthorOrNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!browser.msie)
|
||||
{
|
||||
_reachBlockPoint(node, 1, state);
|
||||
}
|
||||
if (isBlock)
|
||||
{
|
||||
if (lines.length() - 1 == startLine)
|
||||
{
|
||||
cc.startNewLine(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ensureColumnZero(state);
|
||||
}
|
||||
}
|
||||
|
||||
if (browser.msie)
|
||||
{
|
||||
// in IE, a point immediately after a DIV appears on the next line
|
||||
_reachBlockPoint(node, 1, state);
|
||||
}
|
||||
|
||||
state.localAttribs = localAttribs;
|
||||
};
|
||||
// can pass a falsy value for end of doc
|
||||
cc.notifyNextNode = function(node)
|
||||
{
|
||||
// an "empty block" won't end a line; this addresses an issue in IE with
|
||||
// typing into a blank line at the end of the document. typed text
|
||||
// goes into the body, and the empty line div still looks clean.
|
||||
// it is incorporated as dirty by the rule that a dirty region has
|
||||
// to end a line.
|
||||
if ((!node) || (isBlockElement(node) && !_isEmpty(node)))
|
||||
{
|
||||
_ensureColumnZero(null);
|
||||
}
|
||||
};
|
||||
// each returns [line, char] or [-1,-1]
|
||||
var getSelectionStart = function()
|
||||
{
|
||||
return selStart;
|
||||
};
|
||||
var getSelectionEnd = function()
|
||||
{
|
||||
return selEnd;
|
||||
};
|
||||
|
||||
// returns array of strings for lines found, last entry will be "" if
|
||||
// last line is complete (i.e. if a following span should be on a new line).
|
||||
// can be called at any point
|
||||
cc.getLines = function()
|
||||
{
|
||||
return lines.textLines();
|
||||
};
|
||||
|
||||
cc.finish = function()
|
||||
{
|
||||
lines.flush();
|
||||
var lineAttribs = lines.attribLines();
|
||||
var lineStrings = cc.getLines();
|
||||
|
||||
lineStrings.length--;
|
||||
lineAttribs.length--;
|
||||
|
||||
var ss = getSelectionStart();
|
||||
var se = getSelectionEnd();
|
||||
|
||||
function fixLongLines()
|
||||
{
|
||||
// design mode does not deal with with really long lines!
|
||||
var lineLimit = 2000; // chars
|
||||
var buffer = 10; // chars allowed over before wrapping
|
||||
var linesWrapped = 0;
|
||||
var numLinesAfter = 0;
|
||||
for (var i = lineStrings.length - 1; i >= 0; i--)
|
||||
{
|
||||
var oldString = lineStrings[i];
|
||||
var oldAttribString = lineAttribs[i];
|
||||
if (oldString.length > lineLimit + buffer)
|
||||
{
|
||||
var newStrings = [];
|
||||
var newAttribStrings = [];
|
||||
while (oldString.length > lineLimit)
|
||||
{
|
||||
//var semiloc = oldString.lastIndexOf(';', lineLimit-1);
|
||||
//var lengthToTake = (semiloc >= 0 ? (semiloc+1) : lineLimit);
|
||||
lengthToTake = lineLimit;
|
||||
newStrings.push(oldString.substring(0, lengthToTake));
|
||||
oldString = oldString.substring(lengthToTake);
|
||||
newAttribStrings.push(Changeset.subattribution(oldAttribString, 0, lengthToTake));
|
||||
oldAttribString = Changeset.subattribution(oldAttribString, lengthToTake);
|
||||
}
|
||||
if (oldString.length > 0)
|
||||
{
|
||||
newStrings.push(oldString);
|
||||
newAttribStrings.push(oldAttribString);
|
||||
}
|
||||
|
||||
function fixLineNumber(lineChar)
|
||||
{
|
||||
if (lineChar[0] < 0) return;
|
||||
var n = lineChar[0];
|
||||
var c = lineChar[1];
|
||||
if (n > i)
|
||||
{
|
||||
n += (newStrings.length - 1);
|
||||
}
|
||||
else if (n == i)
|
||||
{
|
||||
var a = 0;
|
||||
while (c > newStrings[a].length)
|
||||
{
|
||||
c -= newStrings[a].length;
|
||||
a++;
|
||||
}
|
||||
n += a;
|
||||
}
|
||||
lineChar[0] = n;
|
||||
lineChar[1] = c;
|
||||
}
|
||||
fixLineNumber(ss);
|
||||
fixLineNumber(se);
|
||||
linesWrapped++;
|
||||
numLinesAfter += newStrings.length;
|
||||
|
||||
newStrings.unshift(i, 1);
|
||||
lineStrings.splice.apply(lineStrings, newStrings);
|
||||
newAttribStrings.unshift(i, 1);
|
||||
lineAttribs.splice.apply(lineAttribs, newAttribStrings);
|
||||
}
|
||||
}
|
||||
return {
|
||||
linesWrapped: linesWrapped,
|
||||
numLinesAfter: numLinesAfter
|
||||
};
|
||||
}
|
||||
var wrapData = fixLongLines();
|
||||
|
||||
return {
|
||||
selStart: ss,
|
||||
selEnd: se,
|
||||
linesWrapped: wrapData.linesWrapped,
|
||||
numLinesAfter: wrapData.numLinesAfter,
|
||||
lines: lineStrings,
|
||||
lineAttribs: lineAttribs
|
||||
};
|
||||
}
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
exports.makeContentCollector = makeContentCollector;
|
|
@ -19,7 +19,8 @@
|
|||
"uglify-js" : "1.1.1",
|
||||
"gzip" : "0.1.0",
|
||||
"formidable" : "1.0.7",
|
||||
"log4js" : "0.3.9"
|
||||
"log4js" : "0.3.9",
|
||||
"jsdom" : "0.2.9"
|
||||
},
|
||||
"version" : "1.0.0"
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
"ip": "0.0.0.0",
|
||||
"port" : 9001,
|
||||
|
||||
//The Type of the database. You can choose between sqlite and mysql
|
||||
//The Type of the database. You can choose between dirty, sqlite and mysql
|
||||
//You should use mysql or sqlite for anything else than testing or development
|
||||
"dbType" : "dirty",
|
||||
//the database specific settings
|
||||
"dbSettings" : {
|
||||
|
@ -28,6 +29,12 @@
|
|||
//the default text of a pad
|
||||
"defaultPadText" : "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n",
|
||||
|
||||
/* Users must have a session to access pads. This effectively allows only group pads to be accessed. */
|
||||
"requireSession" : false,
|
||||
|
||||
/* Users may edit pads but not create new ones. Pad creation is only via the API. This applies both to group pads and regular pads. */
|
||||
"editOnly" : false,
|
||||
|
||||
/* if true, all css & js will be minified before sending to the client. This will improve the loading performance massivly,
|
||||
but makes it impossible to debug the javascript/css */
|
||||
"minify" : true,
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
//the default text of a pad
|
||||
"defaultPadText" : "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n",
|
||||
|
||||
/* Users must have a session to access pads. This effectively allows only group pads to be accessed. */
|
||||
"requireSession" : false,
|
||||
|
||||
/* Users may edit pads but not create new ones. Pad creation is only via the API. This applies both to group pads and regular pads. */
|
||||
"editOnly" : false,
|
||||
|
||||
/* if true, all css & js will be minified before sending to the client. This will improve the loading performance massivly,
|
||||
but makes it impossible to debug the javascript/css */
|
||||
"minify" : false,
|
||||
|
|
|
@ -469,7 +469,7 @@ table#otheruserstable { display: none; }
|
|||
|
||||
.modaldialog.cboxreconnecting .modaldialog-inner,
|
||||
.modaldialog.cboxconnecting .modaldialog-inner {
|
||||
background: url(static/img/connectingbar.gif) no-repeat center 60px;
|
||||
background: url(../../static/img/connectingbar.gif) no-repeat center 60px;
|
||||
height: 100px;
|
||||
}
|
||||
.modaldialog.cboxreconnecting {
|
||||
|
@ -786,11 +786,15 @@ padding: 10px;
|
|||
border-radius: 6px;
|
||||
}
|
||||
|
||||
#embedcode, #readonlyUrl {
|
||||
#embedreadonly {
|
||||
float:right;
|
||||
}
|
||||
|
||||
#embedcode, #readonlyUrl, #linkcode {
|
||||
margin-left:10px;
|
||||
}
|
||||
|
||||
#embedinput, #readonlyInput{
|
||||
#embedinput, #readonlyInput, #linkinput {
|
||||
width:375px;
|
||||
height:24px;
|
||||
display:inline;
|
||||
|
@ -1147,3 +1151,12 @@ width:33px !important;
|
|||
padding: 4px 1px;
|
||||
}
|
||||
}
|
||||
|
||||
#embedreadonlyqr{
|
||||
padding-top:20px;
|
||||
margin-left:100px;
|
||||
}
|
||||
|
||||
#qrcode{
|
||||
margin-left:10px;
|
||||
}
|
||||
|
|
BIN
static/img/connectingbar.gif
Normal file
BIN
static/img/connectingbar.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -74,8 +74,12 @@ function isArray(testObject)
|
|||
return testObject && typeof testObject === 'object' && !(testObject.propertyIsEnumerable('length')) && typeof testObject.length === 'number';
|
||||
}
|
||||
|
||||
if (typeof exports !== "undefined")
|
||||
{
|
||||
var navigator = {userAgent: "node-js"};
|
||||
}
|
||||
// Figure out what browser is being used (stolen from jquery 1.2.1)
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
userAgent = navigator.userAgent.toLowerCase();
|
||||
var browser = {
|
||||
version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
|
||||
safari: /webkit/.test(userAgent),
|
||||
|
@ -85,6 +89,7 @@ var browser = {
|
|||
windows: /windows/.test(userAgent) // dgreensp
|
||||
};
|
||||
|
||||
|
||||
function getAssoc(obj, name)
|
||||
{
|
||||
return obj["_magicdom_" + name];
|
||||
|
@ -130,3 +135,8 @@ function htmlPrettyEscape(str)
|
|||
{
|
||||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\r?\n/g, '\\n');
|
||||
}
|
||||
|
||||
if (typeof exports !== "undefined")
|
||||
{
|
||||
exports.map = map;
|
||||
}
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
var chat = (function()
|
||||
{
|
||||
var chatMentions = 0;
|
||||
var title = document.title;
|
||||
var self = {
|
||||
show: function ()
|
||||
{
|
||||
|
@ -43,6 +45,8 @@ var chat = (function()
|
|||
}
|
||||
});
|
||||
});
|
||||
chatMentions = 0;
|
||||
document.title = title;
|
||||
},
|
||||
hide: function ()
|
||||
{
|
||||
|
@ -54,8 +58,6 @@ var chat = (function()
|
|||
},
|
||||
scrollDown: function()
|
||||
{
|
||||
//console.log($('#chatbox').css("display"));
|
||||
|
||||
if($('#chatbox').css("display") != "none")
|
||||
$('#chattext').animate({scrollTop: $('#chattext')[0].scrollHeight}, "slow");
|
||||
},
|
||||
|
@ -87,6 +89,17 @@ var chat = (function()
|
|||
});
|
||||
|
||||
var text = padutils.escapeHtmlWithClickableLinks(padutils.escapeHtml(msg.text), "_blank");
|
||||
|
||||
/* Performs an action if your name is mentioned */
|
||||
var myName = $('#myusernameedit').val();
|
||||
myName = myName.toLowerCase();
|
||||
var chatText = text.toLowerCase();
|
||||
var wasMentioned = false;
|
||||
if (chatText.indexOf(myName) !== -1 && myName != "undefined"){
|
||||
wasMentioned = true;
|
||||
}
|
||||
/* End of new action */
|
||||
|
||||
var authorName = msg.userName == null ? "unnamed" : padutils.escapeHtml(msg.userName);
|
||||
|
||||
var html = "<p class='" + authorClass + "'><b>" + authorName + ":</b><span class='time'>" + timeStr + "</span> " + text + "</p>";
|
||||
|
@ -98,10 +111,23 @@ var chat = (function()
|
|||
var count = Number($("#chatcounter").text());
|
||||
count++;
|
||||
$("#chatcounter").text(count);
|
||||
// chat throb stuff -- Just make it throb in for ~2 secs then fadeotu
|
||||
// chat throb stuff -- Just make it throw for twice as long
|
||||
if(wasMentioned)
|
||||
{ // If the user was mentioned show for twice as long and flash the browser window
|
||||
if (chatMentions == 0){
|
||||
title = document.title;
|
||||
}
|
||||
$('#chatthrob').html("<b>"+authorName+"</b>" + ": " + text);
|
||||
$('#chatthrob').effect("pulsate", {times:1,mode:"hide"},4000);
|
||||
chatMentions++;
|
||||
document.title = "("+chatMentions+") " + title;
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#chatthrob').html("<b>"+authorName+"</b>" + ": " + text);
|
||||
$('#chatthrob').effect("pulsate", {times:1,mode:"hide"},2000);
|
||||
}
|
||||
}
|
||||
|
||||
self.scrollDown();
|
||||
|
||||
|
|
|
@ -77,10 +77,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
{
|
||||
if (socket)
|
||||
{
|
||||
/*socket.onclosed = function() {};
|
||||
socket.onhiccup = function() {};
|
||||
socket.disconnect(true);*/
|
||||
socket.disconnect();
|
||||
setChannelState("DISCONNECTED", "unload");
|
||||
}
|
||||
});
|
||||
if ($.browser.mozilla)
|
||||
|
@ -100,18 +97,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
editor.setBaseAttributedText(serverVars.initialAttributedText, serverVars.apool);
|
||||
editor.setUserChangeNotificationCallback(wrapRecordingErrors("handleUserChanges", handleUserChanges));
|
||||
|
||||
function abandonConnection(reason)
|
||||
{
|
||||
if (socket)
|
||||
{
|
||||
/*socket.onclosed = function() {};
|
||||
socket.onhiccup = function() {};*/
|
||||
socket.disconnect();
|
||||
}
|
||||
socket = null;
|
||||
setChannelState("DISCONNECTED", reason);
|
||||
}
|
||||
|
||||
function dmesg(str)
|
||||
{
|
||||
if (typeof window.ajlog == "string") window.ajlog += str + '\n';
|
||||
|
@ -124,7 +109,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
{
|
||||
if (channelState == "CONNECTING" && (((+new Date()) - initialStartConnectTime) > 20000))
|
||||
{
|
||||
abandonConnection("initsocketfail"); // give up
|
||||
setChannelState("DISCONNECTED", "initsocketfail");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -141,8 +126,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
if (state == "COMMITTING" && (t - lastCommitTime) > 20000)
|
||||
{
|
||||
// a commit is taking too long
|
||||
appLevelDisconnectReason = "slowcommit";
|
||||
socket.disconnect();
|
||||
setChannelState("DISCONNECTED", "slowcommit");
|
||||
}
|
||||
else if (state == "COMMITTING" && (t - lastCommitTime) > 5000)
|
||||
{
|
||||
|
@ -230,11 +214,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
handleMessageFromServer(obj);
|
||||
});*/
|
||||
|
||||
socket.on('disconnect', function(obj)
|
||||
{
|
||||
handleSocketClosed(true);
|
||||
});
|
||||
|
||||
/*var success = false;
|
||||
callCatchingErrors("setUpSocket", function() {
|
||||
appLevelDisconnectReason = null;
|
||||
|
@ -366,7 +345,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
if (newRev != (rev + 1))
|
||||
{
|
||||
dmesg("bad message revision on NEW_CHANGES: " + newRev + " not " + (rev + 1));
|
||||
socket.disconnect();
|
||||
setChannelState("DISCONNECTED", "badmessage_newchanges");
|
||||
return;
|
||||
}
|
||||
rev = newRev;
|
||||
|
@ -378,7 +357,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
if (newRev != (rev + 1))
|
||||
{
|
||||
dmesg("bad message revision on ACCEPT_COMMIT: " + newRev + " not " + (rev + 1));
|
||||
socket.disconnect();
|
||||
setChannelState("DISCONNECTED", "badmessage_acceptcommit");
|
||||
return;
|
||||
}
|
||||
rev = newRev;
|
||||
|
@ -520,48 +499,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
//pad.dmesg($.map(getConnectedUsers(), function(u) { return u.userId.slice(-2); }).join(','));
|
||||
}
|
||||
|
||||
function handleSocketClosed(params)
|
||||
{
|
||||
socket = null;
|
||||
|
||||
$.each(keys(userSet), function()
|
||||
{
|
||||
var uid = String(this);
|
||||
if (uid != userId)
|
||||
{
|
||||
var userInfo = userSet[uid];
|
||||
delete userSet[uid];
|
||||
callbacks.onUserLeave(userInfo);
|
||||
dmesgUsers();
|
||||
}
|
||||
});
|
||||
|
||||
var reason = appLevelDisconnectReason || params.reason;
|
||||
var shouldReconnect = params.reconnect;
|
||||
if (shouldReconnect)
|
||||
{
|
||||
|
||||
// determine if this is a tight reconnect loop due to weird connectivity problems
|
||||
reconnectTimes.push(+new Date());
|
||||
var TOO_MANY_RECONNECTS = 8;
|
||||
var TOO_SHORT_A_TIME_MS = 10000;
|
||||
if (reconnectTimes.length >= TOO_MANY_RECONNECTS && ((+new Date()) - reconnectTimes[reconnectTimes.length - TOO_MANY_RECONNECTS]) < TOO_SHORT_A_TIME_MS)
|
||||
{
|
||||
setChannelState("DISCONNECTED", "looping");
|
||||
}
|
||||
else
|
||||
{
|
||||
setChannelState("RECONNECTING", reason);
|
||||
setUpSocket();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
setChannelState("DISCONNECTED", reason);
|
||||
}
|
||||
}
|
||||
|
||||
function setChannelState(newChannelState, moreInfo)
|
||||
{
|
||||
if (newChannelState != channelState)
|
||||
|
@ -650,128 +587,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
return rev;
|
||||
}
|
||||
|
||||
function getDiagnosticInfo()
|
||||
{
|
||||
var maxCaughtErrors = 3;
|
||||
var maxAceErrors = 3;
|
||||
var maxDebugMessages = 50;
|
||||
var longStringCutoff = 500;
|
||||
|
||||
function trunc(str)
|
||||
{
|
||||
return String(str).substring(0, longStringCutoff);
|
||||
}
|
||||
|
||||
var info = {
|
||||
errors: {
|
||||
length: 0
|
||||
}
|
||||
};
|
||||
|
||||
function addError(e, catcher, time)
|
||||
{
|
||||
var error = {
|
||||
catcher: catcher
|
||||
};
|
||||
if (time) error.time = time;
|
||||
|
||||
// a little over-cautious?
|
||||
try
|
||||
{
|
||||
if (e.description) error.description = e.description;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.fileName) error.fileName = e.fileName;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.lineNumber) error.lineNumber = e.lineNumber;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.message) error.message = e.message;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.name) error.name = e.name;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.number) error.number = e.number;
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
try
|
||||
{
|
||||
if (e.stack) error.stack = trunc(e.stack);
|
||||
}
|
||||
catch (x)
|
||||
{}
|
||||
|
||||
info.errors[info.errors.length] = error;
|
||||
info.errors.length++;
|
||||
}
|
||||
for (var i = 0;
|
||||
((i < caughtErrors.length) && (i < maxCaughtErrors)); i++)
|
||||
{
|
||||
addError(caughtErrors[i], caughtErrorCatchers[i], caughtErrorTimes[i]);
|
||||
}
|
||||
if (editor)
|
||||
{
|
||||
var aceErrors = editor.getUnhandledErrors();
|
||||
for (var i = 0;
|
||||
((i < aceErrors.length) && (i < maxAceErrors)); i++)
|
||||
{
|
||||
var errorRecord = aceErrors[i];
|
||||
addError(errorRecord.error, "ACE", errorRecord.time);
|
||||
}
|
||||
}
|
||||
|
||||
info.time = +new Date();
|
||||
info.collabState = state;
|
||||
info.channelState = channelState;
|
||||
info.lastCommitTime = lastCommitTime;
|
||||
info.numSocketReconnects = reconnectTimes.length;
|
||||
info.userId = userId;
|
||||
info.currentRev = rev;
|
||||
info.participants = (function()
|
||||
{
|
||||
var pp = [];
|
||||
for (var u in userSet)
|
||||
{
|
||||
pp.push(u);
|
||||
}
|
||||
return pp.join(',');
|
||||
})();
|
||||
|
||||
if (debugMessages.length > maxDebugMessages)
|
||||
{
|
||||
debugMessages = debugMessages.slice(debugMessages.length - maxDebugMessages, debugMessages.length);
|
||||
}
|
||||
|
||||
info.debugMessages = {
|
||||
length: 0
|
||||
};
|
||||
for (var i = 0; i < debugMessages.length; i++)
|
||||
{
|
||||
info.debugMessages[i] = trunc(debugMessages[i]);
|
||||
info.debugMessages.length++;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
function getMissedChanges()
|
||||
{
|
||||
var obj = {};
|
||||
|
@ -863,10 +678,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
sendClientMessage: sendClientMessage,
|
||||
sendMessage: sendMessage,
|
||||
getCurrentRevisionNumber: getCurrentRevisionNumber,
|
||||
getDiagnosticInfo: getDiagnosticInfo,
|
||||
getMissedChanges: getMissedChanges,
|
||||
callWhenNotCommitting: callWhenNotCommitting,
|
||||
addHistoricalAuthors: tellAceAboutHistoricalAuthors
|
||||
addHistoricalAuthors: tellAceAboutHistoricalAuthors,
|
||||
setChannelState: setChannelState
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -152,6 +152,10 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
|
|||
{
|
||||
if (href)
|
||||
{
|
||||
if(!~href.indexOf("http")) // if the url doesn't include http or https etc prefix it.
|
||||
{
|
||||
href = "http://"+href;
|
||||
}
|
||||
extraOpenTags = extraOpenTags + '<a href="' + href.replace(/\"/g, '"') + '">';
|
||||
extraCloseTags = '</a>' + extraCloseTags;
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ linestylefilter.getRegexpFilter = function(regExp, tag)
|
|||
|
||||
linestylefilter.REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/;
|
||||
linestylefilter.REGEX_URLCHAR = new RegExp('(' + /[-:@a-zA-Z0-9_.,~%+\/\\?=&#;()$]/.source + '|' + linestylefilter.REGEX_WORDCHAR.source + ')');
|
||||
linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source + linestylefilter.REGEX_URLCHAR.source + '*(?![:.,;])' + linestylefilter.REGEX_URLCHAR.source, 'g');
|
||||
linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:|www\.)/.source + linestylefilter.REGEX_URLCHAR.source + '*(?![:.,;])' + linestylefilter.REGEX_URLCHAR.source, 'g');
|
||||
linestylefilter.getURLFilter = linestylefilter.getRegexpFilter(
|
||||
linestylefilter.REGEX_URL, 'url');
|
||||
|
||||
|
|
|
@ -79,12 +79,13 @@ function randomString()
|
|||
|
||||
function getParams()
|
||||
{
|
||||
var showControls = getUrlVars()["showControls"];
|
||||
var showChat = getUrlVars()["showChat"];
|
||||
var userName = unescape(getUrlVars()["userName"]);
|
||||
var showLineNumbers = getUrlVars()["showLineNumbers"];
|
||||
var useMonospaceFont = getUrlVars()["useMonospaceFont"];
|
||||
var IsnoColors = getUrlVars()["noColors"];
|
||||
var params = getUrlVars()
|
||||
var showControls = params["showControls"];
|
||||
var showChat = params["showChat"];
|
||||
var userName = params["userName"];
|
||||
var showLineNumbers = params["showLineNumbers"];
|
||||
var useMonospaceFont = params["useMonospaceFont"];
|
||||
var IsnoColors = params["noColors"];
|
||||
|
||||
if(IsnoColors)
|
||||
{
|
||||
|
@ -130,7 +131,7 @@ function getParams()
|
|||
if(userName)
|
||||
{
|
||||
// If the username is set as a parameter we should set a global value that we can call once we have initiated the pad.
|
||||
globalUserName = userName;
|
||||
globalUserName = unescape(userName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,14 +167,16 @@ function handshake()
|
|||
var resource = loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "socket.io";
|
||||
//connect
|
||||
socket = io.connect(url, {
|
||||
resource: resource
|
||||
resource: resource,
|
||||
'max reconnection attempts': 3
|
||||
});
|
||||
|
||||
socket.once('connect', function()
|
||||
function sendClientReady(isReconnect)
|
||||
{
|
||||
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
|
||||
padId = unescape(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
||||
|
||||
if(!isReconnect)
|
||||
document.title = document.title + " | " + padId;
|
||||
|
||||
var token = readCookie("token");
|
||||
|
@ -195,7 +198,43 @@ function handshake()
|
|||
"token": token,
|
||||
"protocolVersion": 2
|
||||
};
|
||||
|
||||
//this is a reconnect, lets tell the server our revisionnumber
|
||||
if(isReconnect == true)
|
||||
{
|
||||
msg.client_rev=pad.collabClient.getCurrentRevisionNumber();
|
||||
msg.reconnect=true;
|
||||
}
|
||||
|
||||
socket.json.send(msg);
|
||||
};
|
||||
|
||||
var disconnectTimeout;
|
||||
|
||||
socket.once('connect', function () {
|
||||
sendClientReady(false);
|
||||
});
|
||||
|
||||
socket.on('reconnect', function () {
|
||||
//reconnect is before the timeout, lets stop the timeout
|
||||
if(disconnectTimeout)
|
||||
{
|
||||
clearTimeout(disconnectTimeout);
|
||||
}
|
||||
|
||||
pad.collabClient.setChannelState("CONNECTED");
|
||||
sendClientReady(true);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
function disconnectEvent()
|
||||
{
|
||||
pad.collabClient.setChannelState("DISCONNECTED", "reconnect_timeout");
|
||||
}
|
||||
|
||||
pad.collabClient.setChannelState("RECONNECTING");
|
||||
|
||||
disconnectTimeout = setTimeout(disconnectEvent, 10000);
|
||||
});
|
||||
|
||||
var receivedClientVars = false;
|
||||
|
@ -351,7 +390,6 @@ var pad = {
|
|||
|
||||
//initialize the chat
|
||||
chat.init();
|
||||
pad.diagnosticInfo.uniqueId = padutils.uniqueId();
|
||||
pad.initTime = +(new Date());
|
||||
pad.padOptions = clientVars.initialOptions;
|
||||
|
||||
|
@ -648,7 +686,22 @@ var pad = {
|
|||
else if (newState == "DISCONNECTED")
|
||||
{
|
||||
pad.diagnosticInfo.disconnectedMessage = message;
|
||||
pad.diagnosticInfo.padInitTime = pad.initTime;
|
||||
pad.diagnosticInfo.padId = pad.getPadId();
|
||||
pad.diagnosticInfo.socket = {};
|
||||
|
||||
//we filter non objects from the socket object and put them in the diagnosticInfo
|
||||
//this ensures we have no cyclic data - this allows us to stringify the data
|
||||
for(var i in socket.socket)
|
||||
{
|
||||
var value = socket.socket[i];
|
||||
var type = typeof value;
|
||||
|
||||
if(type == "string" || type == "number")
|
||||
{
|
||||
pad.diagnosticInfo.socket[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
pad.asyncSendDiagnosticInfo();
|
||||
if (typeof window.ajlog == "string")
|
||||
{
|
||||
|
@ -720,7 +773,6 @@ var pad = {
|
|||
},
|
||||
asyncSendDiagnosticInfo: function()
|
||||
{
|
||||
pad.diagnosticInfo.collabDiagnosticInfo = pad.collabClient.getDiagnosticInfo();
|
||||
window.setTimeout(function()
|
||||
{
|
||||
$.ajax(
|
||||
|
@ -728,7 +780,6 @@ var pad = {
|
|||
type: 'post',
|
||||
url: '/ep/pad/connection-diagnostic-info',
|
||||
data: {
|
||||
padId: pad.getPadId(),
|
||||
diagnosticInfo: JSON.stringify(pad.diagnosticInfo)
|
||||
},
|
||||
success: function()
|
||||
|
@ -808,7 +859,7 @@ var pad = {
|
|||
},
|
||||
preloadImages: function()
|
||||
{
|
||||
var images = []; // Removed as we now use CSS and JS for colorpicker
|
||||
var images = ["../static/img/connectingbar.gif"];
|
||||
|
||||
function loadNextImage()
|
||||
{
|
||||
|
|
|
@ -100,25 +100,15 @@ var padeditbar = (function()
|
|||
}
|
||||
else if (cmd == 'embed')
|
||||
{
|
||||
var padurl = window.location.href.split("?")[0];
|
||||
$('#embedinput').val("<iframe src='" + padurl + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
|
||||
self.toogleDropDown("embed");
|
||||
self.setEmbedLinks();
|
||||
$('#embedinput').focus().select();
|
||||
self.toogleDropDown("embed");
|
||||
}
|
||||
else if (cmd == 'import_export')
|
||||
{
|
||||
self.toogleDropDown("importexport");
|
||||
}
|
||||
|
||||
else if (cmd == 'readonly')
|
||||
{
|
||||
var basePath = document.location.href.substring(0, document.location.href.indexOf("/p/"));
|
||||
var readonlyLink = basePath + "/ro/" + clientVars.readOnlyId;
|
||||
$('#readonlyImage').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=H|0&chl=" + readonlyLink);
|
||||
$('#readonlyInput').val(readonlyLink);
|
||||
self.toogleDropDown("readonly");
|
||||
$('#readonlyInput').focus().select();
|
||||
}
|
||||
else if (cmd == 'save')
|
||||
{
|
||||
padsavedrevs.saveNow();
|
||||
|
@ -211,6 +201,25 @@ var padeditbar = (function()
|
|||
{
|
||||
syncAnimation.done();
|
||||
}
|
||||
},
|
||||
setEmbedLinks: function()
|
||||
{
|
||||
if ($('#readonlyinput').is(':checked'))
|
||||
{
|
||||
$('#qrcode').show();
|
||||
var basePath = document.location.href.substring(0, document.location.href.indexOf("/p/"));
|
||||
var readonlyLink = basePath + "/ro/" + clientVars.readOnlyId;
|
||||
$('#embedinput').val("<iframe src='" + readonlyLink + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
|
||||
$('#linkinput').val(readonlyLink);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#qrcode').hide();
|
||||
var padurl = window.location.href.split("?")[0];
|
||||
$('#embedinput').val("<iframe src='" + padurl + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
|
||||
$('#linkinput').val(padurl);
|
||||
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=H|0&chl=" + padurl);
|
||||
}
|
||||
}
|
||||
};
|
||||
return self;
|
||||
|
|
|
@ -711,6 +711,7 @@ var paduserlist = (function()
|
|||
}
|
||||
|
||||
$("#myswatch").css({'background-color': myUserInfo.colorId});
|
||||
$("#usericon").css({'box-shadow': 'inset 0 0 30px ' + myUserInfo.colorId});
|
||||
}
|
||||
};
|
||||
return self;
|
||||
|
|
|
@ -80,11 +80,6 @@
|
|||
|
||||
<ul id="menu_right">
|
||||
|
||||
<li onClick="window.pad&&pad.editbarClick('readonly');return false;" >
|
||||
<a id="readonlylink" title="Create a readonly link for this pad">
|
||||
<div class="buttonicon" style="background-position:0px -150px"></div>
|
||||
</a>
|
||||
</li>
|
||||
<li onClick="window.pad&&pad.editbarClick('import_export');return false;">
|
||||
<a id="exportlink" title="Import/Export from/to different document formats">
|
||||
<div class="buttonicon" style="background-position:0px -68px"></div>
|
||||
|
@ -103,7 +98,7 @@
|
|||
</li>
|
||||
<li id="usericon" onClick="window.pad&&pad.editbarClick('showusers');return false;" >
|
||||
<a title="Show connected users">
|
||||
<div class="buttonicon" style="background-position:0px -184px;display:inline-block;"></div>
|
||||
<div class="buttonicon" id="usericonback" style="background-position:0px -184px;display:inline-block;"></div>
|
||||
<span id="online_count">1</span>
|
||||
</a>
|
||||
</li>
|
||||
|
@ -217,17 +212,21 @@
|
|||
|
||||
<!-- the embed code -->
|
||||
<div id="embed">
|
||||
<div id="embedcode">
|
||||
Embed code:<input id="embedinput" type="text" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- the embed code -->
|
||||
<div id="readonly">
|
||||
<div id="readonlyUrl">
|
||||
Use this link to share a read-only version of your pad:<input id="readonlyInput" type="text" value="">
|
||||
<img id="readonlyImage" src="" alt="" style="margin: 10px 90px">
|
||||
</div>
|
||||
<div id="embedreadonly">
|
||||
<input type="checkbox" id="readonlyinput" onClick="padeditbar.setEmbedLinks();"/><label for="readonlyinput">Read only</label>
|
||||
</div>
|
||||
Share:
|
||||
<br/>
|
||||
<div id="linkcode">
|
||||
<label for="linkinput">Link:</label><input id="linkinput" type="text" value="">
|
||||
</div><br/>
|
||||
<div id="embedcode">
|
||||
<label for="embedinput">Embed code:</label><input id="embedinput" type="text" value="">
|
||||
</div><br/>
|
||||
<div id="qrcode">
|
||||
<label for="embedreadonlyqr">QR code:</label><br/>
|
||||
<img id="embedreadonlyqr">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="chatthrob">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue