Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
settings.json
static/js/jquery.min.js
static/js/jquery.js
APIKEY.txt
bin/abiword.exe
bin/node.exe
Expand Down
6 changes: 3 additions & 3 deletions bin/installDeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ npm install || {
echo "Ensure jQuery is downloaded and up to date..."
DOWNLOAD_JQUERY="true"
NEEDED_VERSION="1.7"
if [ -f "static/js/jquery.min.js" ]; then
VERSION=$(cat static/js/jquery.min.js | head -n 3 | grep -o "v[0-9].[0-9]");
if [ -f "static/js/jquery.js" ]; then
VERSION=$(cat static/js/jquery.js | head -n 3 | grep -o "v[0-9].[0-9]");

if [ ${VERSION#v} = $NEEDED_VERSION ]; then
DOWNLOAD_JQUERY="false"
fi
fi

if [ $DOWNLOAD_JQUERY = "true" ]; then
curl -lo static/js/jquery.min.js http://code.jquery.com/jquery-$NEEDED_VERSION.min.js || exit 1
curl -lo static/js/jquery.js http://code.jquery.com/jquery-$NEEDED_VERSION.js || exit 1
fi

#Remove all minified data to force node creating it new
Expand Down
35 changes: 7 additions & 28 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async.waterfall([
{
//create server
var app = express.createServer();


app.use(function (req, res, next) {
res.header("Server", serverName);
next();
});

//load modules that needs a initalized db
readOnlyManager = require("./db/ReadOnlyManager");
exporthtml = require("./utils/ExportHtml");
Expand Down Expand Up @@ -112,28 +117,13 @@ async.waterfall([
//serve static files
app.get('/static/*', function(req, res)
{
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/.." +
req.url.replace(/\.\./g, '').split("?")[0]);
res.sendfile(filePath, { maxAge: exports.maxAge });
});

//serve minified files
app.get('/minified/:id', function(req, res, next)
{
res.header("Server", serverName);

var id = req.params.id;

if(id == "pad.js" || id == "timeslider.js")
{
minify.minifyJS(req,res,id);
}
else
{
next();
}
});
app.get('/minified/:filename', minify.minifyJS);

//checks for padAccess
function hasPadAccess(req, res, callback)
Expand Down Expand Up @@ -178,8 +168,6 @@ async.waterfall([
//serve read only pad
app.get('/ro/:id', function(req, res)
{
res.header("Server", serverName);

var html;
var padId;
var pad;
Expand Down Expand Up @@ -264,7 +252,6 @@ async.waterfall([
app.get('/p/:pad', function(req, res, next)
{
goToPad(req, res, function() {
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/pad.html");
res.sendfile(filePath, { maxAge: exports.maxAge });
});
Expand All @@ -274,7 +261,6 @@ async.waterfall([
app.get('/p/:pad/timeslider', function(req, res, next)
{
goToPad(req, res, function() {
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/timeslider.html");
res.sendfile(filePath, { maxAge: exports.maxAge });
});
Expand All @@ -301,7 +287,6 @@ async.waterfall([
}

res.header("Access-Control-Allow-Origin", "*");
res.header("Server", serverName);

hasPadAccess(req, res, function()
{
Expand All @@ -321,8 +306,6 @@ async.waterfall([
return;
}

res.header("Server", serverName);

hasPadAccess(req, res, function()
{
importHandler.doImport(req, res, req.params.pad);
Expand All @@ -335,7 +318,6 @@ async.waterfall([
//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(fields));
Expand Down Expand Up @@ -396,23 +378,20 @@ async.waterfall([
//serve index.html under /
app.get('/', function(req, res)
{
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/index.html");
res.sendfile(filePath, { maxAge: exports.maxAge });
});

//serve robots.txt
app.get('/robots.txt', function(req, res)
{
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/robots.txt");
res.sendfile(filePath, { maxAge: exports.maxAge });
});

//serve favicon.ico
app.get('/favicon.ico', function(req, res)
{
res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico");
res.sendfile(filePath, { maxAge: exports.maxAge }, function(err)
{
Expand Down
32 changes: 18 additions & 14 deletions node/utils/Minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var gzip = require('gzip');
var server = require('../server');
var os = require('os');

var ROOT_DIR = path.normalize(__dirname + "/../" );
var JS_DIR = ROOT_DIR + '../static/js/';
var CSS_DIR = ROOT_DIR + '../static/css/';
var CACHE_DIR = ROOT_DIR + '../var/';
var TAR_PATH = path.join(__dirname, 'tar.json');
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));

Expand All @@ -40,20 +44,20 @@ var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
* @param req the Express request
* @param res the Express response
*/
exports.minifyJS = function(req, res, jsFilename)
exports.minifyJS = function(req, res, next)
{
res.header("Content-Type","text/javascript");
var jsFilename = req.params['filename'];

//choose the js files we need
var jsFiles = undefined;
if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) {
jsFiles = tar[jsFilename];
} else {
throw new Error("there is no profile for creating " + name);
return next();
}

var rootPath = path.normalize(__dirname + "/../../" );

res.header("Content-Type","text/javascript");
//minifying is enabled
if(settings.minify)
{
Expand All @@ -65,7 +69,7 @@ exports.minifyJS = function(req, res, jsFilename)
//find out the highest modification date
function(callback)
{
var folders2check = [rootPath + "static/css", rootPath + "static/js"];
var folders2check = [CSS_DIR, JS_DIR];

//go trough this two folders
async.forEach(folders2check, function(path, callback)
Expand Down Expand Up @@ -104,7 +108,7 @@ exports.minifyJS = function(req, res, jsFilename)
function(callback)
{
//check the modification time of the minified js
fs.stat(rootPath + "var/minified_" + jsFilename, function(err, stats)
fs.stat(CACHE_DIR + "/minified_" + jsFilename, function(err, stats)
{
if(err && err.code != "ENOENT")
{
Expand All @@ -129,7 +133,7 @@ exports.minifyJS = function(req, res, jsFilename)
{
async.forEach(jsFiles, function (item, callback)
{
fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data)
fs.readFile(JS_DIR + item, "utf-8", function(err, data)
{
if(ERR(err, callback)) return;
fileValues[item] = data;
Expand Down Expand Up @@ -158,7 +162,7 @@ exports.minifyJS = function(req, res, jsFilename)
var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length);

//read the included file
fs.readFile(filename, "utf-8", function(err, data)
fs.readFile(ROOT_DIR + filename, "utf-8", function(err, data)
{
if(ERR(err, callback)) return;

Expand Down Expand Up @@ -207,7 +211,7 @@ exports.minifyJS = function(req, res, jsFilename)
//write the results plain in a file
function(callback)
{
fs.writeFile(rootPath + "var/minified_" + jsFilename, result, "utf8", callback);
fs.writeFile(CACHE_DIR + "minified_" + jsFilename, result, "utf8", callback);
},
//write the results compressed in a file
function(callback)
Expand All @@ -221,7 +225,7 @@ exports.minifyJS = function(req, res, jsFilename)

if(ERR(err, callback)) return;

fs.writeFile(rootPath + "var/minified_" + jsFilename + ".gz", compressedResult, callback);
fs.writeFile(CACHE_DIR + "minified_" + jsFilename + ".gz", compressedResult, callback);
});
}
//skip this step on windows
Expand All @@ -245,12 +249,12 @@ exports.minifyJS = function(req, res, jsFilename)
var pathStr;
if(gzipSupport && os.type().indexOf("Windows") == -1)
{
pathStr = path.normalize(rootPath + "var/minified_" + jsFilename + ".gz");
pathStr = path.normalize(CACHE_DIR + "minified_" + jsFilename + ".gz");
res.header('Content-Encoding', 'gzip');
}
else
{
pathStr = path.normalize(rootPath + "var/minified_" + jsFilename );
pathStr = path.normalize(CACHE_DIR + "minified_" + jsFilename );
}

res.sendfile(pathStr, { maxAge: server.maxAge });
Expand All @@ -264,7 +268,7 @@ exports.minifyJS = function(req, res, jsFilename)
//read all js files
async.forEach(jsFiles, function (item, callback)
{
fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data)
fs.readFile(JS_DIR + item, "utf-8", function(err, data)
{
if(ERR(err, callback)) return;
fileValues[item] = data;
Expand Down
4 changes: 2 additions & 2 deletions node/utils/tar.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pad.js": [
"jquery.min.js"
"jquery.js"
, "pad_utils.js"
, "plugins.js"
, "undo-xpopup.js"
Expand All @@ -23,7 +23,7 @@
, "farbtastic.js"
]
, "timeslider.js": [
"jquery.min.js"
"jquery.js"
, "plugins.js"
, "undo-xpopup.js"
, "json2.js"
Expand Down
5 changes: 4 additions & 1 deletion static/js/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Ace2Editor.registry = {

function Ace2Editor()
{
var thisFunctionsName = "Ace2Editor";
var ace2 = Ace2Editor;

var editor = {};
Expand Down Expand Up @@ -323,6 +322,10 @@ function Ace2Editor()
iframeHTML.push('<style type="text/css" title="dynamicsyntax"></style>');
iframeHTML.push('</head><body id="innerdocbody" class="syntax" spellcheck="false">&nbsp;</body></html>');

// Expose myself to global for my child frame.
var thisFunctionsName = "ChildAccessibleAce2Editor";
(function () {return this}())[thisFunctionsName] = Ace2Editor;

var outerScript = 'editorId = "' + info.id + '"; editorInfo = parent.' + thisFunctionsName + '.registry[editorId]; ' + 'window.onload = function() ' + '{ window.onload = null; setTimeout' + '(function() ' + '{ var iframe = document.createElement("IFRAME"); ' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE
'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');doc.write(text); doc.close(); ' + '}, 0); }';

Expand Down
10 changes: 2 additions & 8 deletions static/js/ace2_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ function isArray(testObject)
return testObject && typeof testObject === 'object' && !(testObject.propertyIsEnumerable('length')) && typeof testObject.length === 'number';
}

if (typeof exports !== "undefined")
{
userAgent = "node-js";
}
else
{
userAgent = navigator.userAgent.toLowerCase();
}
var userAgent = (((function () {return this;})().navigator || {}).userAgent || 'node-js').toLowerCase();

// Figure out what browser is being used (stolen from jquery 1.2.1)
var browser = {
version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
Expand Down
20 changes: 14 additions & 6 deletions static/js/collab_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ $(window).bind("load", function()
getCollabClient.windowLoaded = true;
});

// Dependency fill on init. This exists for `pad.socket` only.
// TODO: bind directly to the socket.
var pad = undefined;
function getSocket() {
return pad && pad.socket;
}

/** Call this when the document is ready, and a new Ace2Editor() has been created and inited.
ACE's ready callback does not need to have fired yet.
"serverVars" are from calling doc.getCollabClientVars() on the server. */
function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
{
var editor = ace2editor;
pad = _pad; // Inject pad to avoid a circular dependency.

var rev = serverVars.rev;
var padId = serverVars.padId;
Expand Down Expand Up @@ -81,7 +89,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)

$(window).bind("unload", function()
{
if (socket)
if (getSocket())
{
setChannelState("DISCONNECTED", "unload");
}
Expand Down Expand Up @@ -111,7 +119,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)

function handleUserChanges()
{
if ((!socket) || channelState == "CONNECTING")
if ((!getSocket()) || channelState == "CONNECTING")
{
if (channelState == "CONNECTING" && (((+new Date()) - initialStartConnectTime) > 20000))
{
Expand Down Expand Up @@ -295,7 +303,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)

function sendMessage(msg)
{
socket.json.send(
getSocket().json.send(
{
type: "COLLABROOM",
component: "pad",
Expand Down Expand Up @@ -337,7 +345,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
{
if (window.console) console.log(evt);

if (!socket) return;
if (!getSocket()) return;
if (!evt.data) return;
var wrapper = evt;
if (wrapper.type != "COLLABROOM") return;
Expand Down Expand Up @@ -442,7 +450,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
userInfo.userId = userId;
userSet[userId] = userInfo;
tellAceActiveAuthorInfo(userInfo);
if (!socket) return;
if (!getSocket()) return;
sendMessage(
{
type: "USERINFO_UPDATE",
Expand Down
Loading