mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Cleanup cruft. Start wiring things up
This commit is contained in:
parent
360bb55dac
commit
11146ce1cd
4 changed files with 40 additions and 225 deletions
|
@ -1,128 +0,0 @@
|
||||||
/**
|
|
||||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
|
||||||
* This helps other people to understand this code better and helps them to improve it.
|
|
||||||
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
// revision info is a skip list whos entries represent a particular revision
|
|
||||||
// of the document. These revisions are connected together by various
|
|
||||||
// changesets, or deltas, between any two revisions.
|
|
||||||
|
|
||||||
function loadBroadcastRevisionsJS(clientVars)
|
|
||||||
{
|
|
||||||
function Revision(revNum)
|
|
||||||
{
|
|
||||||
this.rev = revNum;
|
|
||||||
this.changesets = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
Revision.prototype.addChangeset = function(destIndex, changeset, timeDelta)
|
|
||||||
{
|
|
||||||
var changesetWrapper = {
|
|
||||||
deltaRev: destIndex - this.rev,
|
|
||||||
deltaTime: timeDelta,
|
|
||||||
getValue: function()
|
|
||||||
{
|
|
||||||
return changeset;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.changesets.push(changesetWrapper);
|
|
||||||
this.changesets.sort(function(a, b)
|
|
||||||
{
|
|
||||||
return (b.deltaRev - a.deltaRev);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
revisionInfo = {};
|
|
||||||
revisionInfo.addChangeset = function(fromIndex, toIndex, changeset, backChangeset, timeDelta)
|
|
||||||
{
|
|
||||||
var startRevision = revisionInfo[fromIndex] || revisionInfo.createNew(fromIndex);
|
|
||||||
var endRevision = revisionInfo[toIndex] || revisionInfo.createNew(toIndex);
|
|
||||||
startRevision.addChangeset(toIndex, changeset, timeDelta);
|
|
||||||
endRevision.addChangeset(fromIndex, backChangeset, -1 * timeDelta);
|
|
||||||
}
|
|
||||||
|
|
||||||
revisionInfo.latest = clientVars.collab_client_vars.rev || -1;
|
|
||||||
|
|
||||||
revisionInfo.createNew = function(index)
|
|
||||||
{
|
|
||||||
revisionInfo[index] = new Revision(index);
|
|
||||||
if (index > revisionInfo.latest)
|
|
||||||
{
|
|
||||||
revisionInfo.latest = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return revisionInfo[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
// assuming that there is a path from fromIndex to toIndex, and that the links
|
|
||||||
// are laid out in a skip-list format
|
|
||||||
revisionInfo.getPath = function(fromIndex, toIndex)
|
|
||||||
{
|
|
||||||
var changesets = [];
|
|
||||||
var spans = [];
|
|
||||||
var times = [];
|
|
||||||
var elem = revisionInfo[fromIndex] || revisionInfo.createNew(fromIndex);
|
|
||||||
if (elem.changesets.length != 0 && fromIndex != toIndex)
|
|
||||||
{
|
|
||||||
var reverse = !(fromIndex < toIndex)
|
|
||||||
while (((elem.rev < toIndex) && !reverse) || ((elem.rev > toIndex) && reverse))
|
|
||||||
{
|
|
||||||
var couldNotContinue = false;
|
|
||||||
var oldRev = elem.rev;
|
|
||||||
|
|
||||||
for (var i = reverse ? elem.changesets.length - 1 : 0;
|
|
||||||
reverse ? i >= 0 : i < elem.changesets.length;
|
|
||||||
i += reverse ? -1 : 1)
|
|
||||||
{
|
|
||||||
if (((elem.changesets[i].deltaRev < 0) && !reverse) || ((elem.changesets[i].deltaRev > 0) && reverse))
|
|
||||||
{
|
|
||||||
couldNotContinue = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((elem.rev + elem.changesets[i].deltaRev <= toIndex) && !reverse) || ((elem.rev + elem.changesets[i].deltaRev >= toIndex) && reverse))
|
|
||||||
{
|
|
||||||
var topush = elem.changesets[i];
|
|
||||||
changesets.push(topush.getValue());
|
|
||||||
spans.push(elem.changesets[i].deltaRev);
|
|
||||||
times.push(topush.deltaTime);
|
|
||||||
elem = revisionInfo[elem.rev + elem.changesets[i].deltaRev];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (couldNotContinue || oldRev == elem.rev) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var status = 'partial';
|
|
||||||
if (elem.rev == toIndex) status = 'complete';
|
|
||||||
|
|
||||||
return {
|
|
||||||
'fromRev': fromIndex,
|
|
||||||
'rev': elem.rev,
|
|
||||||
'status': status,
|
|
||||||
'changesets': changesets,
|
|
||||||
'spans': spans,
|
|
||||||
'times': times
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS;
|
|
|
@ -1,9 +1,3 @@
|
||||||
/**
|
|
||||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
|
||||||
* This helps other people to understand this code better and helps them to improve it.
|
|
||||||
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 Google Inc.
|
* Copyright 2009 Google Inc.
|
||||||
*
|
*
|
||||||
|
@ -20,8 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// These parameters were global, now they are injected. A reference to the
|
|
||||||
// Timeslider controller would probably be more appropriate.
|
|
||||||
var _ = require('./underscore');
|
var _ = require('./underscore');
|
||||||
var padmodals = require('./pad_modals').padmodals;
|
var padmodals = require('./pad_modals').padmodals;
|
||||||
var sliderui = require('./sliderui');
|
var sliderui = require('./sliderui');
|
||||||
|
@ -31,9 +23,9 @@ $.Class("RevisionSlider",
|
||||||
{//statics
|
{//statics
|
||||||
},
|
},
|
||||||
{//instance
|
{//instance
|
||||||
init: function (timeslider, root_element) {
|
init: function (connection, root_element) {
|
||||||
this.timeslider = timeslider;
|
this.connection = connection;
|
||||||
this.revision_number = this.timeslider.head_revision;
|
this.revision_number = this.connection.head_revision;
|
||||||
console.log("New RevisionSlider, head_revision = %d", this.revision_number);
|
console.log("New RevisionSlider, head_revision = %d", this.revision_number);
|
||||||
// parse the various elements we need:
|
// parse the various elements we need:
|
||||||
this.elements = {};
|
this.elements = {};
|
||||||
|
@ -41,12 +33,13 @@ $.Class("RevisionSlider",
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.slider = new SliderUI(this.elements.slider_bar,
|
this.slider = new SliderUI(this.elements.slider_bar,
|
||||||
options = {
|
options = {
|
||||||
max: this.timeslider.head_revision,
|
value: this.revision_number,
|
||||||
|
max: this.connection.head_revision,
|
||||||
change: function () { _this.onChange.apply(_this, arguments); },
|
change: function () { _this.onChange.apply(_this, arguments); },
|
||||||
slide: function () { _this.onSlide.apply(_this, arguments); },
|
slide: function () { _this.onSlide.apply(_this, arguments); },
|
||||||
});
|
});
|
||||||
this.loadSavedRevisionHandles();
|
this.loadSavedRevisionHandles();
|
||||||
|
this.slider.render();
|
||||||
this._mouseInit();
|
this._mouseInit();
|
||||||
},
|
},
|
||||||
onChange: function (value) {
|
onChange: function (value) {
|
||||||
|
@ -69,8 +62,8 @@ $.Class("RevisionSlider",
|
||||||
this.elements.authors = root_element.first("#authorsList");
|
this.elements.authors = root_element.first("#authorsList");
|
||||||
},
|
},
|
||||||
loadSavedRevisionHandles: function () {
|
loadSavedRevisionHandles: function () {
|
||||||
for (var r in this.timeslider.savedRevisions) {
|
for (var r in this.connection.savedRevisions) {
|
||||||
var rev = this.timeslider.savedRevisions[r];
|
var rev = this.connection.savedRevisions[r];
|
||||||
this.slider.createHandle(rev.revNum, "star");
|
this.slider.createHandle(rev.revNum, "star");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -79,8 +72,8 @@ $.Class("RevisionSlider",
|
||||||
//and changeset rendering that that implies), and perform the setPosition in a callback.
|
//and changeset rendering that that implies), and perform the setPosition in a callback.
|
||||||
//TODO: we need some kind of callback for setting revision metadata.
|
//TODO: we need some kind of callback for setting revision metadata.
|
||||||
//TODO: at some point we need to set window.location.hash
|
//TODO: at some point we need to set window.location.hash
|
||||||
if (revNum > this.timeslider.head_revision)
|
if (revNum > this.connection.head_revision)
|
||||||
revNum = this.timeslider.latest_revision;
|
revNum = this.connection.latest_revision;
|
||||||
if (revNum < 0)
|
if (revNum < 0)
|
||||||
revNum = 0;
|
revNum = 0;
|
||||||
console.log("GO TO REVISION", revNum);
|
console.log("GO TO REVISION", revNum);
|
||||||
|
@ -105,7 +98,7 @@ $.Class("RevisionSlider",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
|
function init(tsclient, fireWhenAllScriptsAreLoaded)
|
||||||
{
|
{
|
||||||
var BroadcastSlider;
|
var BroadcastSlider;
|
||||||
|
|
||||||
|
@ -119,6 +112,8 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
|
||||||
var rev = Number(window.location.hash.substr(1));
|
var rev = Number(window.location.hash.substr(1));
|
||||||
if(!isNaN(rev))
|
if(!isNaN(rev))
|
||||||
tsui.goToRevision(rev);
|
tsui.goToRevision(rev);
|
||||||
|
} else {
|
||||||
|
//tsui.goToRevision()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -490,4 +485,4 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
|
||||||
return BroadcastSlider;
|
return BroadcastSlider;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.loadBroadcastSliderJS = loadBroadcastSliderJS;
|
exports.init = init;
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
/**
|
|
||||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
|
||||||
* This helps other people to understand this code better and helps them to improve it.
|
|
||||||
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 Google Inc.
|
* Copyright 2009 Google Inc.
|
||||||
*
|
*
|
||||||
|
@ -19,12 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
// revision info is a skip list whos entries represent a particular revision
|
require('./jquery.class');
|
||||||
// of the document. These revisions are connected together by various
|
var libchangeset = require("./Changeset");
|
||||||
// changesets, or deltas, between any two revisions.
|
|
||||||
|
|
||||||
//require('./jquery.class');
|
|
||||||
|
|
||||||
|
|
||||||
$.Class("Changeset",
|
$.Class("Changeset",
|
||||||
{//statics
|
{//statics
|
||||||
|
@ -39,6 +29,17 @@ $.Class("Changeset",
|
||||||
getValue: function () {
|
getValue: function () {
|
||||||
return this.value;
|
return this.value;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Apply this changeset to the passed pad.
|
||||||
|
* @param {PadClient} pad - The pad to apply the changeset to.
|
||||||
|
*/
|
||||||
|
apply: function (pad) {
|
||||||
|
// must mutate attribution lines before text lines
|
||||||
|
libchangeset.mutateAttributionLines(this.value, pad.alines, pad.apool);
|
||||||
|
|
||||||
|
// Looks like this function can take a regular array of strings
|
||||||
|
libchangeset.mutateTextLines(this.value, /* padcontents */ /*this.lines */ pad.divs);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 'Follow' the Changeset in a given direction, returning the revision at
|
* 'Follow' the Changeset in a given direction, returning the revision at
|
||||||
* the specified end of the edge.
|
* the specified end of the edge.
|
||||||
|
@ -52,33 +53,6 @@ $.Class("Changeset",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO: cruft! remove?
|
|
||||||
$.Class("DirectionalIterator",
|
|
||||||
{//statics
|
|
||||||
},
|
|
||||||
{//instance
|
|
||||||
init: function (list, direction) {
|
|
||||||
self.list = list;
|
|
||||||
self.direction = direction;
|
|
||||||
self.current = self.direction ? self.list.length - 1 : 0;
|
|
||||||
},
|
|
||||||
haveNext: function () {
|
|
||||||
if ((self.direction && self.current > 0) ||
|
|
||||||
(!self.direction && self.current < self.list.length))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
next: function () {
|
|
||||||
if (self.direction && self.current > 0)
|
|
||||||
return self.list[self.current--];
|
|
||||||
if (!self.direction && self.current < self.list.length)
|
|
||||||
return self.list[self.current++];
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revision class. Represents a specific revision. Each instance has three
|
* Revision class. Represents a specific revision. Each instance has three
|
||||||
* possible edges in each direction. Each edge is essentially a Changeset.
|
* possible edges in each direction. Each edge is essentially a Changeset.
|
||||||
|
@ -360,25 +334,6 @@ $.Class("RevisionCache",
|
||||||
//Something went wrong!
|
//Something went wrong!
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Iterate over the list of changesets required to go from one revision to another.
|
|
||||||
* @param {number} from - The starting revision.
|
|
||||||
* @param {number} to - The end revision.
|
|
||||||
* @param {function} callback - The function to apply to each changeset.
|
|
||||||
*/
|
|
||||||
iterChangesets: function (from, to, callback) {
|
|
||||||
// first try to build a path from the cache:
|
|
||||||
var path = this.findPath(from, to);
|
|
||||||
if (!path.is_complete) {
|
|
||||||
// TODO: request load of any other changesets.
|
|
||||||
// before we start iterating over existing
|
|
||||||
// in the hope that some of them will be
|
|
||||||
// fulfilled soon.bt
|
|
||||||
}
|
|
||||||
// we have a partial path
|
|
||||||
console.log(from, to, path.current.revnum);
|
|
||||||
// TODO: loop over existing changesets and apply
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -558,7 +513,6 @@ Thread("ChangesetLoader",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var libchangeset = require("./Changeset");
|
|
||||||
var AttribPool = require("./AttributePool");
|
var AttribPool = require("./AttributePool");
|
||||||
var domline = require("./domline").domline;
|
var domline = require("./domline").domline;
|
||||||
var linestylefilter = require("./linestylefilter").linestylefilter;
|
var linestylefilter = require("./linestylefilter").linestylefilter;
|
||||||
|
@ -659,15 +613,14 @@ $.Class("PadClient",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
function loadBroadcastRevisionsJS(clientVars, connection)
|
function init(clientVars, connection)
|
||||||
{
|
{
|
||||||
|
|
||||||
revisionCache = new RevisionCache(connection, clientVars.collab_client_vars.rev || 0);
|
revisionCache = new RevisionCache(connection, clientVars.collab_client_vars.rev || 0);
|
||||||
// revisionInfo.latest = clientVars.collab_client_vars.rev || -1;
|
|
||||||
|
|
||||||
var collabClientVars = clientVars.collab_client_vars;
|
var collabClientVars = clientVars.collab_client_vars;
|
||||||
p = new PadClient(collabClientVars.rev, collabClientVars.time, collabClientVars.initialAttributedText.text, collabClientVars.initialAttributedText.attribs, collabClientVars.apool);
|
p = new PadClient(collabClientVars.rev, collabClientVars.time, collabClientVars.initialAttributedText.text, collabClientVars.initialAttributedText.attribs, collabClientVars.apool);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS;
|
exports.init = init;
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
/**
|
|
||||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
|
||||||
* This helps other people to understand this code better and helps them to improve it.
|
|
||||||
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 Google Inc.
|
* Copyright 2009 Google Inc.
|
||||||
*
|
*
|
||||||
|
@ -178,6 +172,7 @@ SocketClient("AuthenticatedSocketClient",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
require('./revisioncache');
|
||||||
AuthenticatedSocketClient("TimesliderClient",
|
AuthenticatedSocketClient("TimesliderClient",
|
||||||
{ //statics
|
{ //statics
|
||||||
},
|
},
|
||||||
|
@ -197,15 +192,16 @@ AuthenticatedSocketClient("TimesliderClient",
|
||||||
this.clientVars = data;
|
this.clientVars = data;
|
||||||
this.current_revision = this.head_revision = this.clientVars.collab_client_vars.rev;
|
this.current_revision = this.head_revision = this.clientVars.collab_client_vars.rev;
|
||||||
this.savedRevisions = this.clientVars.savedRevisions;
|
this.savedRevisions = this.clientVars.savedRevisions;
|
||||||
|
|
||||||
|
this.revisionCache = new RevisionCache(this, this.clientVars.collab_client_vars.rev || 0);
|
||||||
|
|
||||||
|
var collabClientVars = this.clientVars.collab_client_vars;
|
||||||
|
this.padClient = new PadClient(collabClientVars.rev, collabClientVars.time, collabClientVars.initialAttributedText.text, collabClientVars.initialAttributedText.attribs, collabClientVars.apool);
|
||||||
},
|
},
|
||||||
|
|
||||||
handle_COLLABROOM: function(data) {
|
handle_COLLABROOM: function(data) {
|
||||||
console.log("[timeslider_client] handle_COLLABROOM: ", data);
|
console.log("[timeslider_client] handle_COLLABROOM: ", data);
|
||||||
},
|
},
|
||||||
|
|
||||||
//handle_CHANGESET_REQ: function(data) {
|
|
||||||
//console.log("[timeslider_client] handle_CHANGESET_REQ: ", data);
|
|
||||||
//},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -243,10 +239,9 @@ function init(baseURL) {
|
||||||
var timesliderclient = new TimesliderClient(url, padId)
|
var timesliderclient = new TimesliderClient(url, padId)
|
||||||
.on("CLIENT_VARS", function(data, context, callback) {
|
.on("CLIENT_VARS", function(data, context, callback) {
|
||||||
//load all script that doesn't work without the clientVars
|
//load all script that doesn't work without the clientVars
|
||||||
BroadcastSlider = require('./broadcast_slider').loadBroadcastSliderJS(this,fireWhenAllScriptsAreLoaded);
|
BroadcastSlider = require('./broadcast_slider').init(this,fireWhenAllScriptsAreLoaded);
|
||||||
cl = require('./revisioncache').loadBroadcastRevisionsJS(this.clientVars, this);
|
//cl = require('./revisioncache').init(this.clientVars, this);
|
||||||
//require('./broadcast_revisions').loadBroadcastRevisionsJS(this.clientVars);
|
//changesetLoader = require('./broadcast').loadBroadcastJS(this, fireWhenAllScriptsAreLoaded, BroadcastSlider);
|
||||||
changesetLoader = require('./broadcast').loadBroadcastJS(this, fireWhenAllScriptsAreLoaded, BroadcastSlider);
|
|
||||||
|
|
||||||
//initialize export ui
|
//initialize export ui
|
||||||
require('./pad_impexp').padimpexp.init();
|
require('./pad_impexp').padimpexp.init();
|
||||||
|
@ -266,7 +261,7 @@ function init(baseURL) {
|
||||||
{
|
{
|
||||||
fireWhenAllScriptsAreLoaded[i]();
|
fireWhenAllScriptsAreLoaded[i]();
|
||||||
}
|
}
|
||||||
$("#ui-slider-handle").css('left', $("#ui-slider-bar").width() - 2);
|
//$("#ui-slider-handle").css('left', $("#ui-slider-bar").width() - 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
//get all the export links
|
//get all the export links
|
||||||
|
|
Loading…
Reference in a new issue