Merge branch 'pita'

Resolved conflicts:
	.gitignore
	src/static/js/ace.js
	src/static/js/ace2_inner.js
	src/static/js/broadcast.js
	src/static/js/domline.js
	src/static/pad.html
	src/static/timeslider.html

Ignored conflicts (please merge manually later):
	node/server.js
	src/node/utils/Minify.js
This commit is contained in:
Egil Moeller 2012-03-02 22:00:20 +01:00
commit ce5d2d8685
35 changed files with 1839 additions and 1037 deletions

View file

@ -29,12 +29,26 @@ var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFact
var _opt = null;
//var exports = {};
/**
* ==================== General Util Functions =======================
*/
/**
* This method is called whenever there is an error in the sync process
* @param msg {string} Just some message
*/
exports.error = function error(msg) {
var e = new Error(msg);
e.easysync = true;
throw e;
};
/**
* This method is user for assertions with Messages
* if assert fails, the error function called.
* @param b {boolean} assertion condition
* @param msgParts {string} error to be passed if it fails
*/
exports.assert = function assert(b, msgParts) {
if (!b) {
var msg = Array.prototype.slice.call(arguments, 1).join('');
@ -42,12 +56,30 @@ exports.assert = function assert(b, msgParts) {
}
};
/**
* Parses a number from string base 36
* @param str {string} string of the number in base 36
* @returns {int} number
*/
exports.parseNum = function (str) {
return parseInt(str, 36);
};
/**
* Writes a number in base 36 and puts it in a string
* @param num {int} number
* @returns {string} string
*/
exports.numToString = function (num) {
return num.toString(36).toLowerCase();
};
/**
* Converts stuff before $ to base 10
* @obsolete not really used anywhere??
* @param cs {string} the string
* @return integer
*/
exports.toBaseTen = function (cs) {
var dollarIndex = cs.indexOf('$');
var beforeDollar = cs.substring(0, dollarIndex);
@ -57,13 +89,34 @@ exports.toBaseTen = function (cs) {
}) + fromDollar;
};
/**
* ==================== Changeset Functions =======================
*/
/**
* returns the required length of the text before changeset
* can be applied
* @param cs {string} String representation of the Changeset
*/
exports.oldLen = function (cs) {
return exports.unpack(cs).oldLen;
};
/**
* returns the length of the text after changeset is applied
* @param cs {string} String representation of the Changeset
*/
exports.newLen = function (cs) {
return exports.unpack(cs).newLen;
};
/**
* this function creates an iterator which decodes string changeset operations
* @param opsStr {string} String encoding of the change operations to be performed
* @param optStartIndex {int} from where in the string should the iterator start
* @return {Op} type object iterator
*/
exports.opIterator = function (opsStr, optStartIndex) {
//print(opsStr);
var regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g;
@ -129,12 +182,21 @@ exports.opIterator = function (opsStr, optStartIndex) {
};
};
/**
* Cleans an Op object
* @param {Op} object to be cleared
*/
exports.clearOp = function (op) {
op.opcode = '';
op.chars = 0;
op.lines = 0;
op.attribs = '';
};
/**
* Creates a new Op object
* @param optOpcode the type operation of the Op object
*/
exports.newOp = function (optOpcode) {
return {
opcode: (optOpcode || ''),
@ -143,6 +205,11 @@ exports.newOp = function (optOpcode) {
attribs: ''
};
};
/**
* Clones an Op
* @param op Op to be cloned
*/
exports.cloneOp = function (op) {
return {
opcode: op.opcode,
@ -151,12 +218,22 @@ exports.cloneOp = function (op) {
attribs: op.attribs
};
};
/**
* Copies op1 to op2
* @param op1 src Op
* @param op2 dest Op
*/
exports.copyOp = function (op1, op2) {
op2.opcode = op1.opcode;
op2.chars = op1.chars;
op2.lines = op1.lines;
op2.attribs = op1.attribs;
};
/**
* Writes the Op in a string the way that changesets need it
*/
exports.opString = function (op) {
// just for debugging
if (!op.opcode) return 'null';
@ -164,11 +241,19 @@ exports.opString = function (op) {
assem.append(op);
return assem.toString();
};
/**
* Used just for debugging
*/
exports.stringOp = function (str) {
// just for debugging
return exports.opIterator(str).next();
};
/**
* Used to check if a Changeset if valid
* @param cs {Changeset} Changeset to be checked
*/
exports.checkRep = function (cs) {
// doesn't check things that require access to attrib pool (e.g. attribute order)
// or original string (e.g. newline positions)
@ -218,6 +303,15 @@ exports.checkRep = function (cs) {
return cs;
}
/**
* ==================== Util Functions =======================
*/
/**
* creates an object that allows you to append operations (type Op) and also
* compresses them if possible
*/
exports.smartOpAssembler = function () {
// Like opAssembler but able to produce conforming exportss
// from slightly looser input, at the cost of speed.
@ -474,6 +568,10 @@ if (_opt) {
};
}
/**
* A custom made String Iterator
* @param str {string} String to be iterated over
*/
exports.stringIterator = function (str) {
var curIndex = 0;
@ -510,6 +608,9 @@ exports.stringIterator = function (str) {
};
};
/**
* A custom made StringBuffer
*/
exports.stringAssembler = function () {
var pieces = [];
@ -526,7 +627,11 @@ exports.stringAssembler = function () {
};
};
// "lines" need not be an array as long as it supports certain calls (lines_foo inside).
/**
* This class allows to iterate and modify texts which have several lines
* It is used for applying Changesets on arrays of lines
* Note from prev docs: "lines" need not be an array as long as it supports certain calls (lines_foo inside).
*/
exports.textLinesMutator = function (lines) {
// Mutates lines, an array of strings, in place.
// Mutation operations have the same constraints as exports operations
@ -781,6 +886,21 @@ exports.textLinesMutator = function (lines) {
return self;
};
/**
* Function allowing iterating over two Op strings.
* @params in1 {string} first Op string
* @params idx1 {int} integer where 1st iterator should start
* @params in2 {string} second Op string
* @params idx2 {int} integer where 2nd iterator should start
* @params func {function} which decides how 1st or 2nd iterator
* advances. When opX.opcode = 0, iterator X advances to
* next element
* func has signature f(op1, op2, opOut)
* op1 - current operation of the first iterator
* op2 - current operation of the second iterator
* opOut - result operator to be put into Changeset
* @return {string} the integrated changeset
*/
exports.applyZip = function (in1, idx1, in2, idx2, func) {
var iter1 = exports.opIterator(in1, idx1);
var iter2 = exports.opIterator(in2, idx2);
@ -802,6 +922,11 @@ exports.applyZip = function (in1, idx1, in2, idx2, func) {
return assem.toString();
};
/**
* Unpacks a string encoded Changeset into a proper Changeset object
* @params cs {string} String encoded Changeset
* @returns {Changeset} a Changeset class
*/
exports.unpack = function (cs) {
var headerRegex = /Z:([0-9a-z]+)([><])([0-9a-z]+)|/;
var headerMatch = headerRegex.exec(cs);
@ -823,6 +948,14 @@ exports.unpack = function (cs) {
};
};
/**
* Packs Changeset object into a string
* @params oldLen {int} Old length of the Changeset
* @params newLen {int] New length of the Changeset
* @params opsStr {string} String encoding of the changes to be made
* @params bank {string} Charbank of the Changeset
* @returns {Changeset} a Changeset class
*/
exports.pack = function (oldLen, newLen, opsStr, bank) {
var lenDiff = newLen - oldLen;
var lenDiffStr = (lenDiff >= 0 ? '>' + exports.numToString(lenDiff) : '<' + exports.numToString(-lenDiff));
@ -831,6 +964,11 @@ exports.pack = function (oldLen, newLen, opsStr, bank) {
return a.join('');
};
/**
* Applies a Changeset to a string
* @params cs {string} String encoded Changeset
* @params str {string} String to which a Changeset should be applied
*/
exports.applyToText = function (cs, str) {
var unpacked = exports.unpack(cs);
exports.assert(str.length == unpacked.oldLen, "mismatched apply: ", str.length, " / ", unpacked.oldLen);
@ -856,6 +994,11 @@ exports.applyToText = function (cs, str) {
return assem.toString();
};
/**
* applies a changeset on an array of lines
* @param CS {Changeset} the changeset to be applied
* @param lines The lines to which the changeset needs to be applied
*/
exports.mutateTextLines = function (cs, lines) {
var unpacked = exports.unpack(cs);
var csIter = exports.opIterator(unpacked.ops);
@ -878,6 +1021,13 @@ exports.mutateTextLines = function (cs, lines) {
mut.close();
};
/**
* Composes two attribute strings (see below) into one.
* @param att1 {string} first attribute string
* @param att2 {string} second attribue string
* @param resultIsMutaton {boolean}
* @param pool {AttribPool} attribute pool
*/
exports.composeAttributes = function (att1, att2, resultIsMutation, pool) {
// att1 and att2 are strings like "*3*f*1c", asMutation is a boolean.
// Sometimes attribute (key,value) pairs are treated as attribute presence
@ -935,6 +1085,10 @@ exports.composeAttributes = function (att1, att2, resultIsMutation, pool) {
return buf.toString();
};
/**
* Function used as parameter for applyZip to apply a Changeset to an
* attribute
*/
exports._slicerZipperFunc = function (attOp, csOp, opOut, pool) {
// attOp is the op from the sequence that is being operated on, either an
// attribution string or the earlier of two exportss being composed.
@ -1021,6 +1175,12 @@ exports._slicerZipperFunc = function (attOp, csOp, opOut, pool) {
}
};
/**
* Applies a Changeset to the attribs string of a AText.
* @param cs {string} Changeset
* @param astr {string} the attribs string of a AText
* @param pool {AttribsPool} the attibutes pool
*/
exports.applyToAttribution = function (cs, astr, pool) {
var unpacked = exports.unpack(cs);
@ -1129,6 +1289,11 @@ exports.mutateAttributionLines = function (cs, lines, pool) {
//dmesg("-> "+lines.toSource());
};
/**
* joins several Attribution lines
* @param theAlines collection of Attribution lines
* @returns {string} joined Attribution lines
*/
exports.joinAttributionLines = function (theAlines) {
var assem = exports.mergingOpAssembler();
for (var i = 0; i < theAlines.length; i++) {
@ -1179,10 +1344,20 @@ exports.splitAttributionLines = function (attrOps, text) {
return lines;
};
/**
* splits text into lines
* @param {string} text to be splitted
*/
exports.splitTextLines = function (text) {
return text.match(/[^\n]*(?:\n|[^\n]$)/g);
};
/**
* compose two Changesets
* @param cs1 {Changeset} first Changeset
* @param cs2 {Changeset} second Changeset
* @param pool {AtribsPool} Attribs pool
*/
exports.compose = function (cs1, cs2, pool) {
var unpacked1 = exports.unpack(cs1);
var unpacked2 = exports.unpack(cs2);
@ -1225,10 +1400,14 @@ exports.compose = function (cs1, cs2, pool) {
return exports.pack(len1, len3, newOps, bankAssem.toString());
};
/**
* returns a function that tests if a string of attributes
* (e.g. *3*4) contains a given attribute key,value that
* is already present in the pool.
* @param attribPair array [key,value] of the attribute
* @param pool {AttribPool} Attribute pool
*/
exports.attributeTester = function (attribPair, pool) {
// returns a function that tests if a string of attributes
// (e.g. *3*4) contains a given attribute key,value that
// is already present in the pool.
if (!pool) {
return never;
}
@ -1247,10 +1426,27 @@ exports.attributeTester = function (attribPair, pool) {
}
};
/**
* creates the identity Changeset of length N
* @param N {int} length of the identity changeset
*/
exports.identity = function (N) {
return exports.pack(N, N, "", "");
};
/**
* creates a Changeset which works on oldFullText and removes text
* from spliceStart to spliceStart+numRemoved and inserts newText
* instead. Also gives possibility to add attributes optNewTextAPairs
* for the new text.
* @param oldFullText {string} old text
* @param spliecStart {int} where splicing starts
* @param numRemoved {int} number of characters to be removed
* @param newText {string} string to be inserted
* @param optNewTextAPairs {string} new pairs to be inserted
* @param pool {AttribPool} Attribution Pool
*/
exports.makeSplice = function (oldFullText, spliceStart, numRemoved, newText, optNewTextAPairs, pool) {
var oldLen = oldFullText.length;
@ -1271,8 +1467,14 @@ exports.makeSplice = function (oldFullText, spliceStart, numRemoved, newText, op
return exports.pack(oldLen, newLen, assem.toString(), newText);
};
/**
* Transforms a changeset into a list of splices in the form
* [startChar, endChar, newText] meaning replace text from
* startChar to endChar with newText
* @param cs Changeset
*/
exports.toSplices = function (cs) {
// get a list of splices, [startChar, endChar, newText]
//
var unpacked = exports.unpack(cs);
var splices = [];
@ -1302,6 +1504,9 @@ exports.toSplices = function (cs) {
return splices;
};
/**
*
*/
exports.characterRangeFollow = function (cs, startChar, endChar, insertionsAfter) {
var newStartChar = startChar;
var newEndChar = endChar;
@ -1346,6 +1551,14 @@ exports.characterRangeFollow = function (cs, startChar, endChar, insertionsAfter
return [newStartChar, newEndChar];
};
/**
* Iterate over attributes in a changeset and move them from
* oldPool to newPool
* @param cs {Changeset} Chageset/attribution string to be iterated over
* @param oldPool {AttribPool} old attributes pool
* @param newPool {AttribPool} new attributes pool
* @return {string} the new Changeset
*/
exports.moveOpsToNewPool = function (cs, oldPool, newPool) {
// works on exports or attribution string
var dollarPos = cs.indexOf('$');
@ -1363,13 +1576,22 @@ exports.moveOpsToNewPool = function (cs, oldPool, newPool) {
}) + fromDollar;
};
/**
* create an attribution inserting a text
* @param text {string} text to be inserted
*/
exports.makeAttribution = function (text) {
var assem = exports.smartOpAssembler();
assem.appendOpWithText('+', text);
return assem.toString();
};
// callable on a exports, attribution string, or attribs property of an op
/**
* Iterates over attributes in exports, attribution string, or attribs property of an op
* and runs function func on them
* @param cs {Changeset} changeset
* @param func {function} function to be called
*/
exports.eachAttribNumber = function (cs, func) {
var dollarPos = cs.indexOf('$');
if (dollarPos < 0) {
@ -1383,12 +1605,21 @@ exports.eachAttribNumber = function (cs, func) {
});
};
// callable on a exports, attribution string, or attribs property of an op,
// though it may easily create adjacent ops that can be merged.
/**
* Filter attributes which should remain in a Changeset
* callable on a exports, attribution string, or attribs property of an op,
* though it may easily create adjacent ops that can be merged.
* @param cs {Changeset} changeset to be filtered
* @param filter {function} fnc which returns true if an
* attribute X (int) should be kept in the Changeset
*/
exports.filterAttribNumbers = function (cs, filter) {
return exports.mapAttribNumbers(cs, filter);
};
/**
* does exactly the same as exports.filterAttribNumbers
*/
exports.mapAttribNumbers = function (cs, func) {
var dollarPos = cs.indexOf('$');
if (dollarPos < 0) {
@ -1410,6 +1641,12 @@ exports.mapAttribNumbers = function (cs, func) {
return newUpToDollar + cs.substring(dollarPos);
};
/**
* Create a Changeset going from Identity to a certain state
* @params text {string} text of the final change
* @attribs attribs {string} optional, operations which insert
* the text and also puts the right attributes
*/
exports.makeAText = function (text, attribs) {
return {
text: text,
@ -1417,6 +1654,12 @@ exports.makeAText = function (text, attribs) {
};
};
/**
* Apply a Changeset to a AText
* @param cs {Changeset} Changeset to be applied
* @param atext {AText}
* @param pool {AttribPool} Attribute Pool to add to
*/
exports.applyToAText = function (cs, atext, pool) {
return {
text: exports.applyToText(cs, atext.text),
@ -1424,6 +1667,10 @@ exports.applyToAText = function (cs, atext, pool) {
};
};
/**
* Clones a AText structure
* @param atext {AText}
*/
exports.cloneAText = function (atext) {
return {
text: atext.text,
@ -1431,11 +1678,20 @@ exports.cloneAText = function (atext) {
};
};
/**
* Copies a AText structure from atext1 to atext2
* @param atext {AText}
*/
exports.copyAText = function (atext1, atext2) {
atext2.text = atext1.text;
atext2.attribs = atext1.attribs;
};
/**
* Append the set of operations from atext to an assembler
* @param atext {AText}
* @param assem Assembler like smartOpAssembler
*/
exports.appendATextToAssembler = function (atext, assem) {
// intentionally skips last newline char of atext
var iter = exports.opIterator(atext.attribs);
@ -1469,6 +1725,11 @@ exports.appendATextToAssembler = function (atext, assem) {
}
};
/**
* Creates a clone of a Changeset and it's APool
* @param cs {Changeset}
* @param pool {AtributePool}
*/
exports.prepareForWire = function (cs, pool) {
var newPool = AttributePoolFactory.createAttributePool();;
var newCs = exports.moveOpsToNewPool(cs, pool, newPool);
@ -1478,15 +1739,32 @@ exports.prepareForWire = function (cs, pool) {
};
};
/**
* Checks if a changeset s the identity changeset
*/
exports.isIdentity = function (cs) {
var unpacked = exports.unpack(cs);
return unpacked.ops == "" && unpacked.oldLen == unpacked.newLen;
};
/**
* returns all the values of attributes with a certain key
* in an Op attribs string
* @param attribs {string} Attribute string of a Op
* @param key {string} string to be seached for
* @param pool {AttribPool} attribute pool
*/
exports.opAttributeValue = function (op, key, pool) {
return exports.attribsAttributeValue(op.attribs, key, pool);
};
/**
* returns all the values of attributes with a certain key
* in an attribs string
* @param attribs {string} Attribute string
* @param key {string} string to be seached for
* @param pool {AttribPool} attribute pool
*/
exports.attribsAttributeValue = function (attribs, key, pool) {
var value = '';
if (attribs) {
@ -1499,6 +1777,11 @@ exports.attribsAttributeValue = function (attribs, key, pool) {
return value;
};
/**
* Creates a Changeset builder for a string with initial
* length oldLen. Allows to add/remove parts of it
* @param oldLen {int} Old length
*/
exports.builder = function (oldLen) {
var assem = exports.smartOpAssembler();
var o = exports.newOp();

View file

@ -49,8 +49,7 @@ function Ace2Editor()
{
var that = this;
var args = arguments;
function action()
var action = function()
{
func.apply(that, args);
}
@ -71,78 +70,47 @@ function Ace2Editor()
function doActionsPendingInit()
{
for (var i = 0; i < actionsPendingInit.length; i++)
{
actionsPendingInit[i]();
}
$.each(actionsPendingInit, function(i,fn){
fn()
});
actionsPendingInit = [];
}
ace2.registry[info.id] = info;
editor.importText = pendingInit(function(newCode, undoable)
{
info.ace_importText(newCode, undoable);
});
editor.importAText = pendingInit(function(newCode, apoolJsonObj, undoable)
{
info.ace_importAText(newCode, apoolJsonObj, undoable);
// The following functions (prefixed by 'ace_') are exposed by editor, but
// execution is delayed until init is complete
var aceFunctionsPendingInit = ['importText', 'importAText', 'focus',
'setEditable', 'getFormattedCode', 'setOnKeyPress', 'setOnKeyDown',
'setNotifyDirty', 'setProperty', 'setBaseText', 'setBaseAttributedText',
'applyChangesToBase', 'applyPreparedChangesetToBase',
'setUserChangeNotificationCallback', 'setAuthorInfo',
'setAuthorSelectionRange', 'callWithAce', 'execCommand', 'replaceRange'];
$.each(aceFunctionsPendingInit, function(i,fnName){
var prefix = 'ace_';
var name = prefix + fnName;
editor[fnName] = pendingInit(function(){
info[prefix + fnName].apply(this, arguments);
});
});
editor.exportText = function()
{
if (!loaded) return "(awaiting init)\n";
return info.ace_exportText();
};
editor.getFrame = function()
{
return info.frame || null;
};
editor.focus = pendingInit(function()
{
info.ace_focus();
});
editor.setEditable = pendingInit(function(newVal)
{
info.ace_setEditable(newVal);
});
editor.getFormattedCode = function()
{
return info.ace_getFormattedCode();
};
editor.setOnKeyPress = pendingInit(function(handler)
{
info.ace_setOnKeyPress(handler);
});
editor.setOnKeyDown = pendingInit(function(handler)
{
info.ace_setOnKeyDown(handler);
});
editor.setNotifyDirty = pendingInit(function(handler)
{
info.ace_setNotifyDirty(handler);
});
editor.setProperty = pendingInit(function(key, value)
{
info.ace_setProperty(key, value);
});
editor.getDebugProperty = function(prop)
{
return info.ace_getDebugProperty(prop);
};
editor.setBaseText = pendingInit(function(txt)
{
info.ace_setBaseText(txt);
});
editor.setBaseAttributedText = pendingInit(function(atxt, apoolJsonObj)
{
info.ace_setBaseAttributedText(atxt, apoolJsonObj);
});
editor.applyChangesToBase = pendingInit(function(changes, optAuthor, apoolJsonObj)
{
info.ace_applyChangesToBase(changes, optAuthor, apoolJsonObj);
});
// prepareUserChangeset:
// Returns null if no new changes or ACE not ready. Otherwise, bundles up all user changes
// to the latest base text into a Changeset, which is returned (as a string if encodeAsString).
@ -157,24 +125,6 @@ function Ace2Editor()
if (!loaded) return null;
return info.ace_prepareUserChangeset();
};
editor.applyPreparedChangesetToBase = pendingInit(
function()
{
info.ace_applyPreparedChangesetToBase();
});
editor.setUserChangeNotificationCallback = pendingInit(function(callback)
{
info.ace_setUserChangeNotificationCallback(callback);
});
editor.setAuthorInfo = pendingInit(function(author, authorInfo)
{
info.ace_setAuthorInfo(author, authorInfo);
});
editor.setAuthorSelectionRange = pendingInit(function(author, start, end)
{
info.ace_setAuthorSelectionRange(author, start, end);
});
editor.getUnhandledErrors = function()
{
@ -183,19 +133,7 @@ function Ace2Editor()
return info.ace_getUnhandledErrors();
};
editor.callWithAce = pendingInit(function(fn, callStack, normalize)
{
return info.ace_callWithAce(fn, callStack, normalize);
});
editor.execCommand = pendingInit(function(cmd, arg1)
{
info.ace_execCommand(cmd, arg1);
});
editor.replaceRange = pendingInit(function(start, end, text)
{
info.ace_replaceRange(start, end, text);
});
function sortFilesByEmbeded(files) {
var embededFiles = [];
@ -228,8 +166,8 @@ function Ace2Editor()
}
function pushScriptsTo(buffer) {
/* Folling is for packaging regular expression. */
/* $$INCLUDE_JS("../static/js/ace2_inner.js"); */
var ACE_SOURCE = '../static/js/ace2_inner.js';
/* $$INCLUDE_JS("../minified/ace2_inner.js?callback=require.define"); */
var ACE_SOURCE = '../minified/ace2_inner.js?callback=require.define';
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[ACE_SOURCE]) {
buffer.push('<script type="text/javascript">');
buffer.push(Ace2Editor.EMBEDED[ACE_SOURCE]);
@ -242,7 +180,7 @@ function Ace2Editor()
buffer.push('<script type="text/javascript">');
buffer.push('require.setRootURI("../minified/"); require.setLibraryURI("../minified/plugins/"); require.setGlobalKeyPath("require");');
buffer.push('<\/script>');
buffer.push('<script type="application/javascript" src="' + file + '"><\/script>');
buffer.push('<script type="application/javascript" src="' + ACE_SOURCE + '"><\/script>');
buffer.push('<script type="text/javascript">');
buffer.push('require("ep_etherpad-lite/static/js/ace2_inner");');
buffer.push('<\/script>');

View file

@ -141,6 +141,9 @@ function htmlPrettyEscape(str)
return Security.escapeHTML(str).replace(/\r?\n/g, '\\n');
}
var noop = function(){};
var identity = function(x){return x};
exports.isNodeText = isNodeText;
exports.object = object;
exports.extend = extend;
@ -155,3 +158,5 @@ exports.binarySearch = binarySearch;
exports.binarySearchInfinite = binarySearchInfinite;
exports.htmlPrettyEscape = htmlPrettyEscape;
exports.map = map;
exports.noop = noop;
exports.identity = identity;

File diff suppressed because it is too large Load diff

View file

@ -26,47 +26,16 @@ var AttribPool = require('ep_etherpad-lite/static/js/AttributePoolFactory').crea
var Changeset = require('ep_etherpad-lite/static/js/Changeset');
var linestylefilter = require('ep_etherpad-lite/static/js/linestylefilter').linestylefilter;
var colorutils = require('ep_etherpad-lite/static/js/colorutils').colorutils;
var Ace2Common = require('ep_etherpad-lite/static/js/ace2_common');
var map = Ace2Common.map;
var forEach = Ace2Common.forEach;
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.
function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider)
{
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
if (!Array.prototype.indexOf)
@ -99,11 +68,6 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
}
}
function randomString()
{
return "_" + Math.floor(Math.random() * 1000000);
}
// for IE
if ($.browser.msie)
{
@ -115,7 +79,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
{}
}
var userId = "hiddenUser" + randomString();
var socketId;
//var socket;
var channelState = "DISCONNECTED";
@ -191,10 +155,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
// splice the lines
splice: function(start, numRemoved, newLinesVA)
{
var newLines = Array.prototype.slice.call(arguments, 2).map(
function(s)
{
var newLines = map(Array.prototype.slice.call(arguments, 2), function(s) {
return s;
});
@ -316,10 +277,13 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
padContents.currentTime += timeDelta * 1000;
debugLog('Time Delta: ', timeDelta)
updateTimer();
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
var authors = map(padContents.getActiveAuthors(), function(name)
{
return authorData[name];
}));
});
BroadcastSlider.setAuthors(authors);
}
function updateTimer()
@ -419,10 +383,11 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
changesetLoader.queueUp(start, 1, update);
}
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
{
var authors = map(padContents.getActiveAuthors(), function(name){
return authorData[name];
}));
});
BroadcastSlider.setAuthors(authors);
}
changesetLoader = {
@ -561,10 +526,12 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
var authorMap = {};
authorMap[obj.author] = obj.data;
receiveAuthorData(authorMap);
BroadcastSlider.setAuthors(padContents.getActiveAuthors().map(function(name)
{
var authors = map(padContents.getActiveAuthors(),function(name) {
return authorData[name];
}));
});
BroadcastSlider.setAuthors(authors);
}
else if (obj['type'] == "NEW_SAVEDREV")
{
@ -616,53 +583,6 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
}));
}
/*function setUpSocket()
{
// required for Comet
if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0)))
{
document.domain = document.domain; // for comet
}
var success = false;
callCatchingErrors("setUpSocket", function ()
{
appLevelDisconnectReason = null;
socketId = String(Math.floor(Math.random() * 1e12));
socket = new WebSocket(socketId);
socket.onmessage = wrapRecordingErrors("socket.onmessage", handleMessageFromServer);
socket.onclosed = wrapRecordingErrors("socket.onclosed", handleSocketClosed);
socket.onopen = wrapRecordingErrors("socket.onopen", function ()
{
setChannelState("CONNECTED");
var msg = {
type: "CLIENT_READY",
roomType: 'padview',
roomName: 'padview/' + clientVars.viewId,
data: {
lastRev: clientVars.revNum,
userInfo: {
userId: userId
}
}
};
sendMessage(msg);
});
// socket.onhiccup = wrapRecordingErrors("socket.onhiccup", handleCometHiccup);
// socket.onlogmessage = function(x) {debugLog(x); };
socket.connect();
success = true;
});
if (success)
{
//initialStartConnectTime = +new Date();
}
else
{
abandonConnection("initsocketfail");
}
}*/
function setChannelState(newChannelState, moreInfo)
{
@ -691,7 +611,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
window.onload = function ()
{
window['isloaded'] = true;
window['onloadFuncts'].forEach(function (funct)
forEach(window['onloadFuncts'],function (funct)
{
funct();
});

View file

@ -42,13 +42,13 @@ var chat = (function()
chat.show();
if(!isStuck || fromInitialCall) { // Stick it to
padcookie.setPref("chatAlwaysVisible", true);
$('#chatbox').css({"right":"0px", "top":"36px", "border-radius":"0px", "height":"auto", "border-right":"none", "border-left":"1px solid #ccc", "border-top":"none", "background-color":"#f1f1f1", "width":"185px"});
$('#chatbox').addClass("stickyChat");
$('#chattext').css({"top":"0px"});
$('#editorcontainer').css({"right":"192px", "width":"auto"});
isStuck = true;
} else { // Unstick it
padcookie.setPref("chatAlwaysVisible", false);
$('#chatbox').css({"right":"20px", "top":"auto", "border-top-left-radius":"5px", "border-top-right-radius":"5px", "border-right":"1px solid #999", "height":"200px", "border-top":"1px solid #999", "background-color":"#f7f7f7"});
$('#chatbox').removeClass("stickyChat");
$('#chattext').css({"top":"25px"});
$('#editorcontainer').css({"right":"0px", "width":"100%"});
isStuck = false;

View file

@ -84,13 +84,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
{}
};
$(window).bind("unload", function()
{
if (getSocket())
{
setChannelState("DISCONNECTED", "unload");
}
});
if ($.browser.mozilla)
{
// Prevent "escape" from taking effect and canceling a comet connection;

View file

@ -120,4 +120,19 @@ colorutils.blend = function(c1, c2, t)
return [colorutils.scale(t, c1[0], c2[0]), colorutils.scale(t, c1[1], c2[1]), colorutils.scale(t, c1[2], c2[2])];
}
colorutils.invert = function(c)
{
return [1 - c[0], 1 - c[1], 1- c[2]];
}
colorutils.complementary = function(c)
{
var inv = colorutils.invert(c);
return [
(inv[0] >= c[0]) ? Math.min(inv[0] * 1.30, 1) : (c[0] * 0.30),
(inv[1] >= c[1]) ? Math.min(inv[1] * 1.59, 1) : (c[1] * 0.59),
(inv[2] >= c[2]) ? Math.min(inv[2] * 1.11, 1) : (c[2] * 0.11)
];
}
exports.colorutils = colorutils;

View file

@ -28,15 +28,12 @@
var Security = require('ep_etherpad-lite/static/js/security');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var map = require('ep_etherpad-lite/static/js/ace2_common').map;
var Ace2Common = require('ep_etherpad-lite/static/js/ace2_common');
var map = Ace2Common.map;
var noop = Ace2Common.noop;
var identity = Ace2Common.identity;
var domline = {};
domline.noop = function()
{};
domline.identity = function(x)
{
return x;
};
domline.addToLineClass = function(lineClass, cls)
{
@ -60,11 +57,11 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
{
var result = {
node: null,
appendSpan: domline.noop,
prepareForAdd: domline.noop,
notifyAdded: domline.noop,
clearSpans: domline.noop,
finishUpdate: domline.noop,
appendSpan: noop,
prepareForAdd: noop,
notifyAdded: noop,
clearSpans: noop,
finishUpdate: noop,
lineMarker: 0
};
@ -91,7 +88,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
{
return domline.processSpaces(s, doesWrap);
}
var identity = domline.identity;
var perTextNodeProcess = (doesWrap ? identity : processSpaces);
var perHtmlLineProcess = (doesWrap ? processSpaces : identity);
var lineClass = 'ace-line';

View file

@ -146,6 +146,12 @@ function savePassword()
document.location=document.location;
}
function ieTestXMLHTTP(){
// Test for IE known XML HTTP issue
if ($.browser.msie && !window.XMLHttpRequest){
$("#editorloadingbox").html("You do not have XML HTTP enabled in your browser. <a target='_blank' href='https://github.com/Pita/etherpad-lite/wiki/How-to-enable-native-XMLHTTP-support-in-IE'>Fix this issue</a>");
}
}
function handshake()
{
var loc = document.location;
@ -158,7 +164,8 @@ function handshake()
//connect
socket = pad.socket = io.connect(url, {
resource: resource,
'max reconnection attempts': 3
'max reconnection attempts': 3,
'sync disconnect on unload' : false
});
function sendClientReady(isReconnect)
@ -216,15 +223,19 @@ function handshake()
sendClientReady(true);
});
socket.on('disconnect', function () {
function disconnectEvent()
{
pad.collabClient.setChannelState("DISCONNECTED", "reconnect_timeout");
socket.on('disconnect', function (reason) {
if(reason == "booted"){
pad.collabClient.setChannelState("DISCONNECTED");
} else {
function disconnectEvent()
{
pad.collabClient.setChannelState("DISCONNECTED", "reconnect_timeout");
}
pad.collabClient.setChannelState("RECONNECTING");
disconnectTimeout = setTimeout(disconnectEvent, 10000);
}
pad.collabClient.setChannelState("RECONNECTING");
disconnectTimeout = setTimeout(disconnectEvent, 10000);
});
var receivedClientVars = false;
@ -276,7 +287,7 @@ function handshake()
pad.changeViewOption('showLineNumbers', false);
}
// If the noColors value is set to true then we need to hide the backround colors on the ace spans
// If the noColors value is set to true then we need to hide the background colors on the ace spans
if (settings.noColors == true)
{
pad.changeViewOption('noColors', true);
@ -364,7 +375,6 @@ var pad = {
{
return clientVars.userIsGuest;
},
//
getUserId: function()
{
return pad.myUserInfo.userId;
@ -384,16 +394,13 @@ var pad = {
$(document).ready(function()
{
// test for XML HTTP capabiites
ieTestXMLHTTP();
// start the custom js
if (typeof customStart == "function") customStart();
getParams();
handshake();
});
$(window).unload(function()
{
pad.dispose();
});
},
_afterHandshake: function()
{
@ -422,7 +429,7 @@ var pad = {
// order of inits is important here:
padcookie.init(clientVars.cookiePrefsToSet, this);
$("#widthprefcheck").click(pad.toggleWidthPref);
// $("#sidebarcheck").click(pad.togglewSidebar);
@ -477,6 +484,13 @@ var pad = {
{
padeditor.ace.focus();
}, 0);
if(padcookie.getPref("chatAlwaysVisible")){ // if we have a cookie for always showing chat then show it
chat.stickToScreen(true); // stick it to the screen
$('#options-stickychat').prop("checked", true); // set the checkbox to on
}
if(padcookie.getPref("showAuthorshipColors") == false){
pad.changeViewOption('showAuthorColors', false);
}
}
},
dispose: function()
@ -741,6 +755,7 @@ var pad = {
// pad.determineSidebarVisibility(isConnected && !isInitialConnect);
pad.determineChatVisibility(isConnected && !isInitialConnect);
pad.determineAuthorshipColorsVisibility();
},
/* determineSidebarVisibility: function(asNowConnectedFeedback)
@ -770,6 +785,16 @@ var pad = {
$('#options-stickychat').prop("checked", false); // set the checkbox for off
}
},
determineAuthorshipColorsVisibility: function(){
var authColCookie = padcookie.getPref('showAuthorshipColors');
if (authColCookie){
pad.changeViewOption('showAuthorColors', true);
$('#options-colorscheck').prop("checked", true);
}
else {
$('#options-colorscheck').prop("checked", false);
}
},
handleCollabAction: function(action)
{
if (action == "commitPerformed")
@ -972,3 +997,4 @@ exports.handshake = handshake;
exports.pad = pad;
exports.init = init;
exports.alertBar = alertBar;

View file

@ -239,14 +239,14 @@ var padeditbar = (function()
var readonlyLink = basePath + "/ro/" + clientVars.readOnlyId;
$('#embedinput').val("<iframe name='embed_readonly' src='" + readonlyLink + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
$('#linkinput').val(readonlyLink);
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=H|0&chl=" + readonlyLink);
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=|0&chl=" + readonlyLink);
}
else
{
var padurl = window.location.href.split("?")[0];
$('#embedinput').val("<iframe name='embed_readwrite' 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);
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=|0&chl=" + padurl);
}
}
};

View file

@ -69,6 +69,7 @@ var padeditor = (function()
});
padutils.bindCheckboxChange($("#options-colorscheck"), function()
{
padcookie.setPref('showAuthorshipColors', padutils.getCheckbox("#options-colorscheck"));
pad.changeViewOption('showAuthorColors', padutils.getCheckbox("#options-colorscheck"));
});
$("#viewfontmenu").change(function()

View file

@ -95,11 +95,6 @@ var padimpexp = (function()
}, 0);
$('#importarrow').stop(true, true).hide();
$('#importstatusball').show();
$("#import .importframe").load(function()
{
importDone();
});
}
return ret;
}
@ -107,8 +102,6 @@ var padimpexp = (function()
function importFailed(msg)
{
importErrorMessage(msg);
importDone();
addImportFrames();
}
function importDone()
@ -120,6 +113,7 @@ var padimpexp = (function()
}, 0);
$('#importstatusball').hide();
importClearTimeout();
addImportFrames();
}
function importClearTimeout()
@ -131,11 +125,19 @@ var padimpexp = (function()
}
}
function importErrorMessage(msg)
function importErrorMessage(status)
{
var msg="";
if(status === "convertFailed"){
msg = "We were not able to import this file. Please use a different document format or copy paste manually";
} else if(status === "uploadFailed"){
msg = "The upload failed, please try again";
}
function showError(fade)
{
$('#importmessagefail').html('<strong style="color: red">Import failed:</strong> ' + (msg || 'Please try a different file.'))[(fade ? "fadeIn" : "show")]();
$('#importmessagefail').html('<strong style="color: red">Import failed:</strong> ' + (msg || 'Please copy paste'))[(fade ? "fadeIn" : "show")]();
}
if ($('#importexport .importmessage').is(':visible'))
@ -175,39 +177,6 @@ var padimpexp = (function()
importDone();
}
function importApplicationSuccessful(data, textStatus)
{
if (data.substr(0, 2) == "ok")
{
if ($('#importexport .importmessage').is(':visible'))
{
$('#importexport .importmessage').hide();
}
$('#importmessagesuccess').html('<strong style="color: green">Import successful!</strong>').show();
$('#importformfilediv').hide();
window.setTimeout(function()
{
$('#importmessagesuccess').fadeOut("slow", function()
{
$('#importformfilediv').show();
});
if (hidePanelCall)
{
hidePanelCall();
}
}, 3000);
}
else if (data.substr(0, 4) == "fail")
{
importErrorMessage("Couldn't update pad contents. This can happen if your web browser has \"cookies\" disabled.");
}
else if (data.substr(0, 4) == "msg:")
{
importErrorMessage(data.substr(4));
}
importDone();
}
///// export
function cantExport()
@ -257,8 +226,7 @@ var padimpexp = (function()
$("#exportworda").remove();
$("#exportpdfa").remove();
$("#exportopena").remove();
$("#importexport").css({"height":"115px"});
$("#importexportline").css({"height":"115px"});
$(".importformdiv").remove();
$("#import").html("Import is not available. To enable import please install abiword");
}
else if(clientVars.abiwordAvailable == "withoutPDF")
@ -292,16 +260,14 @@ var padimpexp = (function()
$('#importform').submit(fileInputSubmit);
$('.disabledexport').click(cantExport);
},
handleFrameCall: function(callName, argsArray)
handleFrameCall: function(status)
{
if (callName == 'importFailed')
if (status !== "ok")
{
importFailed(argsArray[0]);
}
else if (callName == 'importSuccessful')
{
importSuccessful(argsArray[0]);
importFailed(status);
}
importDone();
},
disable: function()
{

View file

@ -21,7 +21,7 @@
*/
var noop = require('./ace2_common').noop;
function newSkipList()
@ -41,9 +41,6 @@ function newSkipList()
};
}
function noop()
{}
// if there are N elements in the skiplist, "start" is element -1 and "end" is element N
var start = {
key: null,