use shared functions from Ace2Common

pull/466/head
Matthias Bartelmeß 2012-02-19 15:47:20 +01:00
parent 9ede14a546
commit 465f6c2de7
1 changed files with 20 additions and 48 deletions

View File

@ -26,47 +26,16 @@ var AttribPool = require('/AttributePoolFactory').createAttributePool;
var Changeset = require('/Changeset'); var Changeset = require('/Changeset');
var linestylefilter = require('/linestylefilter').linestylefilter; var linestylefilter = require('/linestylefilter').linestylefilter;
var colorutils = require('/colorutils').colorutils; var colorutils = require('/colorutils').colorutils;
var Ace2Common = require('./ace2_common');
var map = Ace2Common.map;
var forEach = Ace2Common.forEach;
// These parameters were global, now they are injected. A reference to the // These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate. // Timeslider controller would probably be more appropriate.
function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider) function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider)
{ {
var changesetLoader = undefined; var changesetLoader = undefined;
// just in case... (todo: this must be somewhere else in the client code.)
// Below Array#map code was direct pasted by AppJet/Etherpad, licence unknown. Possible source: http://www.tutorialspoint.com/javascript/array_map.htm
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp*/ )
{
var len = this.length >>> 0;
if (typeof fun != "function") throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this) res[i] = fun.call(thisp, this[i], i, this);
}
return res;
};
}
// Below Array#forEach code was direct pasted by AppJet/Etherpad, licence unknown. Possible source: http://www.tutorialspoint.com/javascript/array_foreach.htm
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/ )
{
var len = this.length >>> 0;
if (typeof fun != "function") throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this) fun.call(thisp, this[i], i, this);
}
};
}
// Below Array#indexOf code was direct pasted by AppJet/Etherpad, licence unknown. Possible source: http://www.tutorialspoint.com/javascript/array_indexof.htm // Below Array#indexOf code was direct pasted by AppJet/Etherpad, licence unknown. Possible source: http://www.tutorialspoint.com/javascript/array_indexof.htm
if (!Array.prototype.indexOf) if (!Array.prototype.indexOf)
@ -191,10 +160,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
// splice the lines // splice the lines
splice: function(start, numRemoved, newLinesVA) splice: function(start, numRemoved, newLinesVA)
{ {
var newLines = Array.prototype.slice.call(arguments, 2).map( var newLines = map(Array.prototype.slice.call(arguments, 2), function(s) {
function(s)
{
return s; return s;
}); });
@ -316,10 +282,13 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
padContents.currentTime += timeDelta * 1000; padContents.currentTime += timeDelta * 1000;
debugLog('Time Delta: ', timeDelta) debugLog('Time Delta: ', timeDelta)
updateTimer(); updateTimer();
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
var authors = map(padContents.getActiveAuthors(), function(name)
{ {
return authorData[name]; return authorData[name];
})); });
BroadcastSlider.setAuthors(authors);
} }
function updateTimer() function updateTimer()
@ -419,10 +388,11 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
changesetLoader.queueUp(start, 1, update); changesetLoader.queueUp(start, 1, update);
} }
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
{ var authors = map(padContents.getActiveAuthors(), function(name){
return authorData[name]; return authorData[name];
})); });
BroadcastSlider.setAuthors(authors);
} }
changesetLoader = { changesetLoader = {
@ -561,10 +531,12 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
var authorMap = {}; var authorMap = {};
authorMap[obj.author] = obj.data; authorMap[obj.author] = obj.data;
receiveAuthorData(authorMap); receiveAuthorData(authorMap);
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
{ var authors = map(padContents.getActiveAuthors(),function(name) {
return authorData[name]; return authorData[name];
})); });
BroadcastSlider.setAuthors(authors);
} }
else if (obj['type'] == "NEW_SAVEDREV") else if (obj['type'] == "NEW_SAVEDREV")
{ {
@ -691,7 +663,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
window.onload = function () window.onload = function ()
{ {
window['isloaded'] = true; window['isloaded'] = true;
window['onloadFuncts'].forEach(function (funct) forEach(window['onloadFuncts'],function (funct)
{ {
funct(); funct();
}); });