Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add (optional) authentication step when connecting to shares

share.open() now accepts an object instead of a origin string, The object can contains an 'authentication' property which will be attached the user agent. Use this to store an identifier for the user e.g. OAuth token
  • Loading branch information...
commit 8e49bcdd1760727def6083ef40720a14265b5f9f 1 parent 7b835a1
@daredevildave daredevildave authored
View
9 src/client/connection.coffee
@@ -20,7 +20,7 @@ else
Doc = require('./doc').Doc
class Connection
- constructor: (host) ->
+ constructor: (host, authentication) ->
# Map of docname -> doc
@docs = {}
@@ -37,7 +37,12 @@ class Connection
new SockJS(host)
else
new BCSocket(host, reconnect:true)
-
+
+ # Send authentication message
+ @socket.send({
+ "auth": if authentication then authentication else null
+ })
+
@socket.onmessage = (msg) =>
msg = JSON.parse(msg.data) if useSockJS?
if msg.auth is null
View
18 src/client/index.coffee
@@ -28,7 +28,7 @@ exports.open = do ->
# This is a private connection pool for implicitly created connections.
connections = {}
- getConnection = (origin) ->
+ getConnection = (origin, authentication) ->
if WEB?
location = window.location
# default to browserchannel
@@ -36,7 +36,7 @@ exports.open = do ->
origin ?= "#{location.protocol}//#{location.host}/#{path}"
unless connections[origin]
- c = new Connection origin
+ c = new Connection origin, authentication
del = -> delete connections[origin]
c.on 'disconnected', del
@@ -55,12 +55,16 @@ exports.open = do ->
if numDocs == 0
c.disconnect()
- (docName, type, origin, callback) ->
- if typeof origin == 'function'
- callback = origin
- origin = null
+ (docName, type, options, callback) ->
+ if typeof options == 'function'
+ callback = options
+ options = {}
- c = getConnection origin
+
+ origin = options.origin
+ authentication = options.authentication
+
+ c = getConnection origin, authentication
c.numDocs++
c.open docName, type, (error, doc) ->
if error
View
52 src/server/session.coffee
@@ -26,6 +26,9 @@ hat = require 'hat'
syncQueue = require './syncqueue'
+# Time (in ms) that the server will wait for an auth message from the client before closing the connection
+AUTH_TIMEOUT = 10000
+
# session should implement the following interface:
# headers
# address
@@ -53,6 +56,7 @@ exports.handler = (session, createAgent) ->
# Map from docName -> {queue, listener if open}
docState = {}
+
# We'll only handle one message from each client at a time.
handleMessage = (query) ->
@@ -301,26 +305,42 @@ exports.handler = (session, createAgent) ->
send msg
callback()
+ # Authentication process has failed, send error and stop session
+ failAuthentication = (error) ->
+ session.send {
+ auth: null,
+ error: error
+ }
+ session.stop()
+
+ # Wait for client to send an auth message, but don't wait forever
+ timeout = setTimeout () ->
+ failAuthentication('Timeout waiting for client auth message')
+ , AUTH_TIMEOUT
+
# We don't process any messages from the agent until they've authorized. Instead,
# they are stored in this buffer.
buffer = []
- session.on 'message', bufferMsg = (msg) -> buffer.push msg
-
- createAgent data, (error, agent_) ->
- if error
- # The client is not authorized, so they shouldn't try and reconnect.
- session.send {auth:null, error}
- session.stop()
+ session.on 'message', bufferMsg = (msg) ->
+ if typeof msg.auth != 'undefined'
+ clearTimeout timeout
+ data.authentication = msg.auth
+ createAgent data, (error, agent_) ->
+ if error
+ # The client is not authorized, so they shouldn't try and reconnect.
+ failAuthentication(error)
+ else
+ agent = agent_
+ session.send auth:agent.sessionId
+
+ # Ok. Now we can handle all the messages in the buffer. They'll go straight to
+ # handleMessage from now on.
+ session.removeListener 'message', bufferMsg
+ handleMessage msg for msg in buffer
+ buffer = null
+ session.on 'message', handleMessage
else
- agent = agent_
- session.send auth:agent.sessionId
-
- # Ok. Now we can handle all the messages in the buffer. They'll go straight to
- # handleMessage from now on.
- session.removeListener 'message', bufferMsg
- handleMessage msg for msg in buffer
- buffer = null
- session.on 'message', handleMessage
+ buffer.push msg
session.on 'close', ->
return unless agent
View
3  src/server/useragent.coffee
@@ -20,7 +20,8 @@ module.exports = (model, options) ->
@connectTime = new Date
@headers = data.headers
@remoteAddress = data.remoteAddress
-
+ @authentication = data.authentication
+
# This is a map from docName -> listener function
@listeners = {}
View
13 webclient/ace.js
@@ -1,16 +1,13 @@
-// Generated by CoffeeScript 1.3.3
(function() {
var Range, applyToShareJS;
-
Range = require("ace/range").Range;
-
applyToShareJS = function(editorDoc, delta, doc) {
var getStartOffsetPosition, pos, text;
getStartOffsetPosition = function(range) {
- var i, line, lines, offset, _i, _len;
+ var i, line, lines, offset, _len;
lines = editorDoc.getLines(0, range.start.row);
offset = 0;
- for (i = _i = 0, _len = lines.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = lines.length; i < _len; i++) {
line = lines[i];
offset += i < range.start.row ? line.length : range.start.column;
}
@@ -36,7 +33,6 @@
throw new Error("unknown action: " + delta.action);
}
};
-
window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
if (!this.provides['text']) {
@@ -80,10 +76,10 @@
return check();
};
offsetToPos = function(offset) {
- var line, lines, row, _i, _len;
+ var line, lines, row, _len;
lines = editorDoc.getAllLines();
row = 0;
- for (row = _i = 0, _len = lines.length; _i < _len; row = ++_i) {
+ for (row = 0, _len = lines.length; row < _len; row++) {
line = lines[row];
if (offset <= line.length) {
break;
@@ -115,5 +111,4 @@
return delete doc.detach_ace;
};
});
-
}).call(this);
View
4 webclient/cm.js
@@ -1,7 +1,5 @@
-// Generated by CoffeeScript 1.3.3
(function() {
var applyToShareJS;
-
applyToShareJS = function(editorDoc, delta, doc) {
var delLen, i, startPos;
startPos = 0;
@@ -28,7 +26,6 @@
return applyToShareJS(editorDoc, delta.next, doc);
}
};
-
window.sharejs.extendDoc('attach_cm', function(editor, keepEditorContents) {
var check, editorListener, sharedoc, suppress;
if (!this.provides.text) {
@@ -84,5 +81,4 @@
return delete this.detach_cm;
};
});
-
}).call(this);
View
2  webclient/json.js
@@ -1 +1 @@
-(function(){var e,t,n,r,i,s,o,u,a,f=!0,l=[].slice,c=window.sharejs;typeof f!="undefined"&&f!==null?u=c.types.text:u=require("./text"),s={},s.name="json",s.create=function(){return null},s.invertComponent=function(e){var t={p:e.p};return e.si!==void 0&&(t.sd=e.si),e.sd!==void 0&&(t.si=e.sd),e.oi!==void 0&&(t.od=e.oi),e.od!==void 0&&(t.oi=e.od),e.li!==void 0&&(t.ld=e.li),e.ld!==void 0&&(t.li=e.ld),e.na!==void 0&&(t.na=-e.na),e.lm!==void 0&&(t.lm=e.p[e.p.length-1],t.p=e.p.slice(0,e.p.length-1).concat([e.lm])),t},s.invert=function(e){var t,n,r,i=e.slice().reverse(),o=[];for(n=0,r=i.length;n<r;n++)t=i[n],o.push(s.invertComponent(t));return o},s.checkValidOp=function(){},i=function(e){return Object.prototype.toString.call(e)==="[object Array]"},s.checkList=function(e){if(!i(e))throw new Error("Referenced element not a list")},s.checkObj=function(e){if(e.constructor!==Object)throw new Error("Referenced element not an object (it was "+JSON.stringify(e)+")")},s.apply=function(e,n){var r,i,o,u,a,f,l,c,h,p,d,v,m,g;s.checkValidOp(n),n=t(n),i={data:t(e)};try{for(a=p=0,v=n.length;p<v;a=++p){r=n[a],c=null,h=null,u=i,f="data",g=r.p;for(d=0,m=g.length;d<m;d++){l=g[d],c=u,h=f,u=u[f],f=l;if(c==null)throw new Error("Path invalid")}if(r.na!==void 0){if(typeof u[f]!="number")throw new Error("Referenced element not a number");u[f]+=r.na}else if(r.si!==void 0){if(typeof u!="string")throw new Error("Referenced element not a string (it was "+JSON.stringify(u)+")");c[h]=u.slice(0,f)+r.si+u.slice(f)}else if(r.sd!==void 0){if(typeof u!="string")throw new Error("Referenced element not a string");if(u.slice(f,f+r.sd.length)!==r.sd)throw new Error("Deleted string does not match");c[h]=u.slice(0,f)+u.slice(f+r.sd.length)}else if(r.li!==void 0&&r.ld!==void 0)s.checkList(u),u[f]=r.li;else if(r.li!==void 0)s.checkList(u),u.splice(f,0,r.li);else if(r.ld!==void 0)s.checkList(u),u.splice(f,1);else if(r.lm!==void 0)s.checkList(u),r.lm!==f&&(o=u[f],u.splice(f,1),u.splice(r.lm,0,o));else if(r.oi!==void 0)s.checkObj(u),u[f]=r.oi;else{if(r.od===void 0)throw new Error("invalid / missing instruction in op");s.checkObj(u),delete u[f]}}}catch(y){throw y}return i.data},s.pathMatches=function(e,t,n){var r,i,s,o;if(e.length!==t.length)return!1;for(r=s=0,o=e.length;s<o;r=++s){i=e[r];if(i!==t[r]&&(!n||r!==e.length-1))return!1}return!0},s.append=function(e,n){var r;return n=t(n),e.length!==0&&s.pathMatches(n.p,(r=e[e.length-1]).p)?r.na!==void 0&&n.na!==void 0?e[e.length-1]={p:r.p,na:r.na+n.na}:r.li!==void 0&&n.li===void 0&&n.ld===r.li?r.ld!==void 0?delete r.li:e.pop():r.od!==void 0&&r.oi===void 0&&n.oi!==void 0&&n.od===void 0?r.oi=n.oi:n.lm!==void 0&&n.p[n.p.length-1]===n.lm?null:e.push(n):e.push(n)},s.compose=function(e,n){var r,i,o,u;s.checkValidOp(e),s.checkValidOp(n),i=t(e);for(o=0,u=n.length;o<u;o++)r=n[o],s.append(i,r);return i},s.normalize=function(e){var t,n,r,o,u=[];i(e)||(e=[e]);for(n=0,r=e.length;n<r;n++)t=e[n],(o=t.p)==null&&(t.p=[]),s.append(u,t);return u},t=function(e){return JSON.parse(JSON.stringify(e))},s.commonPath=function(e,t){var n;e=e.slice(),t=t.slice(),e.unshift("data"),t.unshift("data"),e=e.slice(0,e.length-1),t=t.slice(0,t.length-1);if(t.length===0)return-1;n=0;while(e[n]===t[n]&&n<e.length){n++;if(n===t.length)return n-1}},s.transformComponent=function(e,n,r,i){var o,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N;n=t(n),n.na!==void 0&&n.p.push(0),r.na!==void 0&&r.p.push(0),o=s.commonPath(n.p,r.p),a=s.commonPath(r.p,n.p),c=n.p.length,v=r.p.length,n.na!==void 0&&n.p.pop(),r.na!==void 0&&r.p.pop();if(r.na)return a!=null&&v>=c&&r.p[a]===n.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d]))),s.append(e,n),e;a!=null&&v>c&&n.p[a]===r.p[a]&&(n.ld!==void 0?(d=t(r),d.p=d.p.slice(c),n.ld=s.apply(t(n.ld),[d])):n.od!==void 0&&(d=t(r),d.p=d.p.slice(c),n.od=s.apply(t(n.od),[d])));if(o!=null){f=c===v;if(r.na===void 0)if(r.si!==void 0||r.sd!==void 0){if(n.si!==void 0||n.sd!==void 0){if(!f)throw new Error("must be a string?");l=function(e){var t={p:e.p[e.p.length-1]};return e.si?t.i=e.si:t.d=e.sd,t},E=l(n),S=l(r),b=[],u._tc(b,E,S,i);for(T=0,N=b.length;T<N;T++)w=b[T],p={p:n.p.slice(0,o)},p.p.push(w.p),w.i!=null&&(p.si=w.i),w.d!=null&&(p.sd=w.d),s.append(e,p);return e}}else if(r.li!==void 0&&r.ld!==void 0){if(r.p[o]===n.p[o]){if(!f)return e;if(n.ld!==void 0){if(n.li===void 0||i!=="left")return e;n.ld=t(r.li)}}}else if(r.li!==void 0)n.li!==void 0&&n.ld===void 0&&f&&n.p[o]===r.p[o]?i==="right"&&n.p[o]++:r.p[o]<=n.p[o]&&n.p[o]++,n.lm!==void 0&&f&&r.p[o]<=n.lm&&n.lm++;else if(r.ld!==void 0){if(n.lm!==void 0&&f){if(r.p[o]===n.p[o])return e;y=r.p[o],h=n.p[o],x=n.lm,(y<x||y===x&&h<x)&&n.lm--}if(r.p[o]<n.p[o])n.p[o]--;else if(r.p[o]===n.p[o]){if(v<c)return e;if(n.ld!==void 0){if(n.li===void 0)return e;delete n.ld}}}else if(r.lm!==void 0)if(n.lm!==void 0&&c===v){h=n.p[o],x=n.lm,m=r.p[o],g=r.lm;if(m!==g)if(h===m){if(i!=="left")return e;n.p[o]=g,h===x&&(n.lm=g)}else h>m&&n.p[o]--,h>g?n.p[o]++:h===g&&m>g&&(n.p[o]++,h===x&&n.lm++),x>m?n.lm--:x===m&&x>h&&n.lm--,x>g?n.lm++:x===g&&(g>m&&x>h||g<m&&x<h?i==="right"&&n.lm++:x>h?n.lm++:x===m&&n.lm--)}else n.li!==void 0&&n.ld===void 0&&f?(h=r.p[o],x=r.lm,y=n.p[o],y>h&&n.p[o]--,y>x&&n.p[o]++):(h=r.p[o],x=r.lm,y=n.p[o],y===h?n.p[o]=x:(y>h&&n.p[o]--,y>x?n.p[o]++:y===x&&h>x&&n.p[o]++));else if(r.oi!==void 0&&r.od!==void 0){if(n.p[o]===r.p[o]){if(n.oi===void 0||!f)return e;if(i==="right")return e;n.od=r.oi}}else if(r.oi!==void 0){if(n.oi!==void 0&&n.p[o]===r.p[o]){if(i!=="left")return e;s.append(e,{p:n.p,od:r.oi})}}else if(r.od!==void 0&&n.p[o]===r.p[o]){if(!f)return e;if(n.oi===void 0)return e;delete n.od}}return s.append(e,n),e},typeof f!="undefined"&&f!==null?(c.types||(c.types={}),c._bt(s,s.transformComponent,s.checkValidOp,s.append),c.types.json=s):(module.exports=s,require("./helpers").bootstrapTransform(s,s.transformComponent,s.checkValidOp,s.append)),typeof f=="undefined"&&(s=require("./json")),typeof f!="undefined"&&f!==null&&(r=c.extendDoc,c.extendDoc=function(t,n){return e.prototype[t]=n,r(t,n)}),n=function(e){return e.length===1&&e[0].constructor===Array?e[0]:e},e=function(){function e(e,t){this.doc=e,this.path=t}return e.prototype.at=function(){var e=1<=arguments.length?l.call(arguments,0):[];return this.doc.at(this.path.concat(n(e)))},e.prototype.get=function(){return this.doc.getAt(this.path)},e.prototype.set=function(e,t){return this.doc.setAt(this.path,e,t)},e.prototype.insert=function(e,t,n){return this.doc.insertAt(this.path,e,t,n)},e.prototype.del=function(e,t,n){return this.doc.deleteTextAt(this.path,t,e,n)},e.prototype.remove=function(e){return this.doc.removeAt(this.path,e)},e.prototype.push=function(e,t){return this.insert(this.get().length,e,t)},e.prototype.move=function(e,t,n){return this.doc.moveAt(this.path,e,t,n)},e.prototype.add=function(e,t){return this.doc.addAt(this.path,e,t)},e.prototype.on=function(e,t){return this.doc.addListener(this.path,e,t)},e.prototype.removeListener=function(e){return this.doc.removeListener(e)},e.prototype.getLength=function(){return this.get().length},e.prototype.getText=function(){return this.get()},e}(),a=function(e,t){var n,r,i,s={data:e},o="data",u=s;for(r=0,i=t.length;r<i;r++){n=t[r],u=u[o],o=n;if(typeof u=="undefined")throw new Error("bad path")}return{elem:u,key:o}},o=function(e,t){var n,r,i,s;if(e.length!==t.length)return!1;for(r=i=0,s=e.length;i<s;r=++i){n=e[r];if(n!==t[r])return!1}return!0},s.api={provides:{json:!0},at:function(){var t=1<=arguments.length?l.call(arguments,0):[];return new e(this,n(t))},get:function(){return this.snapshot},set:function(e,t){return this.setAt([],e,t)},getAt:function(e){var t=a(this.snapshot,e),n=t.elem,r=t.key;return n[r]},setAt:function(e,t,n){var r=a(this.snapshot,e),i=r.elem,s=r.key,o={p:e};if(i.constructor===Array)o.li=t,typeof i[s]!="undefined"&&(o.ld=i[s]);else{if(typeof i!="object")throw new Error("bad path");o.oi=t,typeof i[s]!="undefined"&&(o.od=i[s])}return this.submitOp([o],n)},removeAt:function(e,t){var n,r=a(this.snapshot,e),i=r.elem,s=r.key;if(typeof i[s]=="undefined")throw new Error("no element at that path");n={p:e};if(i.constructor===Array)n.ld=i[s];else{if(typeof i!="object")throw new Error("bad path");n.od=i[s]}return this.submitOp([n],t)},insertAt:function(e,t,n,r){var i=a(this.snapshot,e),s=i.elem,o=i.key,u={p:e.concat(t)};return s[o].constructor===Array?u.li=n:typeof s[o]=="string"&&(u.si=n),this.submitOp([u],r)},moveAt:function(e,t,n,r){var i=[{p:e.concat(t),lm:n}];return this.submitOp(i,r)},addAt:function(e,t,n){var r=[{p:e,na:t}];return this.submitOp(r,n)},deleteTextAt:function(e,t,n,r){var i=a(this.snapshot,e),s=i.elem,o=i.key,u=[{p:e.concat(n),sd:s[o].slice(n,n+t)}];return this.submitOp(u,r)},addListener:function(e,t,n){var r={path:e,event:t,cb:n};return this._listeners.push(r),r},removeListener:function(e){var t=this._listeners.indexOf(e);return t<0?!1:(this._listeners.splice(t,1),!0)},_register:function(){return this._listeners=[],this.on("change",function(e){var t,n,r,i,s,o,u,a,f,l,c,h=[];for(u=0,f=e.length;u<f;u++){t=e[u];if(t.na!==void 0||t.si!==void 0||t.sd!==void 0)continue;s=[],c=this._listeners;for(r=a=0,l=c.length;a<l;r=++a){i=c[r],n={p:i.path,na:0},o=this.type.transformComponent([],n,t,"left");if(o.length===0)s.push(r);else{if(o.length!==1)throw new Error("Bad assumption in json-api: xforming an 'si' op will always result in 0 or 1 components.");i.path=o[0].p}}s.sort(function(e,t){return t-e}),h.push(function(){var e,t,n=[];for(e=0,t=s.length;e<t;e++)r=s[e],n.push(this._listeners.splice(r,1));return n}.call(this))}return h}),this.on("remoteop",function(e){var t,n,r,i,s,u,a,f,l,c=[];for(f=0,l=e.length;f<l;f++)t=e[f],u=t.na===void 0?t.p.slice(0,t.p.length-1):t.p,c.push(function(){var e,f,l,c,h=this._listeners,p=[];for(e=0,f=h.length;e<f;e++){l=h[e],a=l.path,s=l.event,n=l.cb;if(o(a,u))switch(s){case"insert":t.li!==void 0&&t.ld===void 0?p.push(n(t.p[t.p.length-1],t.li)):t.oi!==void 0&&t.od===void 0?p.push(n(t.p[t.p.length-1],t.oi)):t.si!==void 0?p.push(n(t.p[t.p.length-1],t.si)):p.push(void 0);break;case"delete":t.li===void 0&&t.ld!==void 0?p.push(n(t.p[t.p.length-1],t.ld)):t.oi===void 0&&t.od!==void 0?p.push(n(t.p[t.p.length-1],t.od)):t.sd!==void 0?p.push(n(t.p[t.p.length-1],t.sd)):p.push(void 0);break;case"replace":t.li!==void 0&&t.ld!==void 0?p.push(n(t.p[t.p.length-1],t.ld,t.li)):t.oi!==void 0&&t.od!==void 0?p.push(n(t.p[t.p.length-1],t.od,t.oi)):p.push(void 0);break;case"move":t.lm!==void 0?p.push(n(t.p[t.p.length-1],t.lm)):p.push(void 0);break;case"add":t.na!==void 0?p.push(n(t.na)):p.push(void 0);break;default:p.push(void 0)}else if((i=this.type.commonPath(u,a))!=null)if(s==="child op"){if(u.length===(c=a.length)&&c===i)throw new Error("paths match length and have commonality, but aren't equal?");r=t.p.slice(i+1),p.push(n(r,t))}else p.push(void 0);else p.push(void 0)}return p}.call(this));return c})}}}).call(this)
+(function(){var a,b,c,d,e,f,g,h,i,j=!0,k=Array.prototype.slice,l=window.sharejs;typeof j!="undefined"&&j!==null?h=l.types.text:h=require("./text"),f={},f.name="json",f.create=function(){return null},f.invertComponent=function(a){var b={p:a.p};return a.si!==void 0&&(b.sd=a.si),a.sd!==void 0&&(b.si=a.sd),a.oi!==void 0&&(b.od=a.oi),a.od!==void 0&&(b.oi=a.od),a.li!==void 0&&(b.ld=a.li),a.ld!==void 0&&(b.li=a.ld),a.na!==void 0&&(b.na=-a.na),a.lm!==void 0&&(b.lm=a.p[a.p.length-1],b.p=a.p.slice(0,a.p.length-1).concat([a.lm])),b},f.invert=function(a){var b,c,d,e=a.slice().reverse(),g=[];for(c=0,d=e.length;c<d;c++)b=e[c],g.push(f.invertComponent(b));return g},f.checkValidOp=function(){},e=function(a){return Object.prototype.toString.call(a)==="[object Array]"},f.checkList=function(a){if(!e(a))throw new Error("Referenced element not a list")},f.checkObj=function(a){if(a.constructor!==Object)throw new Error("Referenced element not an object (it was "+JSON.stringify(a)+")")},f.apply=function(a,c){var d,e,g,h,i,j,k,l,m,n,o,p,q;f.checkValidOp(c),c=b(c),e={data:b(a)};try{for(i=0,o=c.length;i<o;i++){d=c[i],l=null,m=null,h=e,j="data",q=d.p;for(n=0,p=q.length;n<p;n++){k=q[n],l=h,m=j,h=h[j],j=k;if(l==null)throw new Error("Path invalid")}if(d.na!==void 0){if(typeof h[j]!="number")throw new Error("Referenced element not a number");h[j]+=d.na}else if(d.si!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string (it was "+JSON.stringify(h)+")");l[m]=h.slice(0,j)+d.si+h.slice(j)}else if(d.sd!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string");if(h.slice(j,j+d.sd.length)!==d.sd)throw new Error("Deleted string does not match");l[m]=h.slice(0,j)+h.slice(j+d.sd.length)}else if(d.li!==void 0&&d.ld!==void 0)f.checkList(h),h[j]=d.li;else if(d.li!==void 0)f.checkList(h),h.splice(j,0,d.li);else if(d.ld!==void 0)f.checkList(h),h.splice(j,1);else if(d.lm!==void 0)f.checkList(h),d.lm!==j&&(g=h[j],h.splice(j,1),h.splice(d.lm,0,g));else if(d.oi!==void 0)f.checkObj(h),h[j]=d.oi;else{if(d.od===void 0)throw new Error("invalid / missing instruction in op");f.checkObj(h),delete h[j]}}}catch(r){throw r}return e.data},f.pathMatches=function(a,b,c){var d,e,f;if(a.length!==b.length)return!1;for(d=0,f=a.length;d<f;d++){e=a[d];if(e!==b[d]&&(!c||d!==a.length-1))return!1}return!0},f.append=function(a,c){var d;return c=b(c),a.length!==0&&f.pathMatches(c.p,(d=a[a.length-1]).p)?d.na!==void 0&&c.na!==void 0?a[a.length-1]={p:d.p,na:d.na+c.na}:d.li!==void 0&&c.li===void 0&&c.ld===d.li?d.ld!==void 0?delete d.li:a.pop():d.od!==void 0&&d.oi===void 0&&c.oi!==void 0&&c.od===void 0?d.oi=c.oi:c.lm!==void 0&&c.p[c.p.length-1]===c.lm?null:a.push(c):a.push(c)},f.compose=function(a,c){var d,e,g,h;f.checkValidOp(a),f.checkValidOp(c),e=b(a);for(g=0,h=c.length;g<h;g++)d=c[g],f.append(e,d);return e},f.normalize=function(a){var b,c,d,g,h=[];e(a)||(a=[a]);for(c=0,d=a.length;c<d;c++)b=a[c],(g=b.p)!=null?g:b.p=[],f.append(h,b);return h},b=function(a){return JSON.parse(JSON.stringify(a))},f.commonPath=function(a,b){var c;a=a.slice(),b=b.slice(),a.unshift("data"),b.unshift("data"),a=a.slice(0,a.length-1),b=b.slice(0,b.length-1);if(b.length===0)return-1;c=0;while(a[c]===b[c]&&c<a.length){c++;if(c===b.length)return c-1}},f.transformComponent=function(a,c,d,e){var g,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;c=b(c),c.na!==void 0&&c.p.push(0),d.na!==void 0&&d.p.push(0),g=f.commonPath(c.p,d.p),i=f.commonPath(d.p,c.p),l=c.p.length,p=d.p.length,c.na!==void 0&&c.p.pop(),d.na!==void 0&&d.p.pop();if(d.na)return i!=null&&p>=l&&d.p[i]===c.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o]))),f.append(a,c),a;i!=null&&p>l&&c.p[i]===d.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o])));if(g!=null){j=l===p;if(d.na===void 0)if(d.si!==void 0||d.sd!==void 0){if(c.si!==void 0||c.sd!==void 0){if(!j)throw new Error("must be a string?");k=function(a){var b={p:a.p[a.p.length-1]};return a.si?b.i=a.si:b.d=a.sd,b},v=k(c),w=k(d),t=[],h._tc(t,v,w,e);for(y=0,z=t.length;y<z;y++)u=t[y],n={p:c.p.slice(0,g)},n.p.push(u.p),u.i!=null&&(n.si=u.i),u.d!=null&&(n.sd=u.d),f.append(a,n);return a}}else if(d.li!==void 0&&d.ld!==void 0){if(d.p[g]===c.p[g]){if(!j)return a;if(c.ld!==void 0){if(c.li===void 0||e!=="left")return a;c.ld=b(d.li)}}}else if(d.li!==void 0)c.li!==void 0&&c.ld===void 0&&j&&c.p[g]===d.p[g]?e==="right"&&c.p[g]++:d.p[g]<=c.p[g]&&c.p[g]++,c.lm!==void 0&&j&&d.p[g]<=c.lm&&c.lm++;else if(d.ld!==void 0){if(c.lm!==void 0&&j){if(d.p[g]===c.p[g])return a;s=d.p[g],m=c.p[g],x=c.lm,(s<x||s===x&&m<x)&&c.lm--}if(d.p[g]<c.p[g])c.p[g]--;else if(d.p[g]===c.p[g]){if(p<l)return a;if(c.ld!==void 0){if(c.li===void 0)return a;delete c.ld}}}else if(d.lm!==void 0)if(c.lm!==void 0&&l===p){m=c.p[g],x=c.lm,q=d.p[g],r=d.lm;if(q!==r)if(m===q){if(e!=="left")return a;c.p[g]=r,m===x&&(c.lm=r)}else m>q&&c.p[g]--,m>r?c.p[g]++:m===r&&q>r&&(c.p[g]++,m===x&&c.lm++),x>q?c.lm--:x===q&&x>m&&c.lm--,x>r?c.lm++:x===r&&(r>q&&x>m||r<q&&x<m?e==="right"&&c.lm++:x>m?c.lm++:x===q&&c.lm--)}else c.li!==void 0&&c.ld===void 0&&j?(m=d.p[g],x=d.lm,s=c.p[g],s>m&&c.p[g]--,s>x&&c.p[g]++):(m=d.p[g],x=d.lm,s=c.p[g],s===m?c.p[g]=x:(s>m&&c.p[g]--,s>x?c.p[g]++:s===x&&m>x&&c.p[g]++));else if(d.oi!==void 0&&d.od!==void 0){if(c.p[g]===d.p[g]){if(c.oi===void 0||!j)return a;if(e==="right")return a;c.od=d.oi}}else if(d.oi!==void 0){if(c.oi!==void 0&&c.p[g]===d.p[g]){if(e!=="left")return a;f.append(a,{p:c.p,od:d.oi})}}else if(d.od!==void 0&&c.p[g]===d.p[g]){if(!j)return a;if(c.oi===void 0)return a;delete c.od}}return f.append(a,c),a},typeof j!="undefined"&&j!==null?(l.types||(l.types={}),l._bt(f,f.transformComponent,f.checkValidOp,f.append),l.types.json=f):(module.exports=f,require("./helpers").bootstrapTransform(f,f.transformComponent,f.checkValidOp,f.append)),typeof j=="undefined"&&(f=require("./json")),typeof j!="undefined"&&j!==null&&(d=l.extendDoc,l.extendDoc=function(b,c){return a.prototype[b]=c,d(b,c)}),c=function(a){return a.length===1&&a[0].constructor===Array?a[0]:a},a=function(){function a(a,b){this.doc=a,this.path=b}return a.prototype.at=function(){var a=1<=arguments.length?k.call(arguments,0):[];return this.doc.at(this.path.concat(c(a)))},a.prototype.get=function(){return this.doc.getAt(this.path)},a.prototype.set=function(a,b){return this.doc.setAt(this.path,a,b)},a.prototype.insert=function(a,b,c){return this.doc.insertAt(this.path,a,b,c)},a.prototype.del=function(a,b,c){return this.doc.deleteTextAt(this.path,b,a,c)},a.prototype.remove=function(a){return this.doc.removeAt(this.path,a)},a.prototype.push=function(a,b){return this.insert(this.get().length,a,b)},a.prototype.move=function(a,b,c){return this.doc.moveAt(this.path,a,b,c)},a.prototype.add=function(a,b){return this.doc.addAt(this.path,a,b)},a.prototype.on=function(a,b){return this.doc.addListener(this.path,a,b)},a.prototype.removeListener=function(a){return this.doc.removeListener(a)},a.prototype.getLength=function(){return this.get().length},a.prototype.getText=function(){return this.get()},a}(),i=function(a,b){var c,d,e,f={data:a},g="data",h=f;for(d=0,e=b.length;d<e;d++){c=b[d],h=h[g],g=c;if(typeof h=="undefined")throw new Error("bad path")}return{elem:h,key:g}},g=function(a,b){var c,d,e;if(a.length!==b.length)return!1;for(d=0,e=a.length;d<e;d++){c=a[d];if(c!==b[d])return!1}return!0},f.api={provides:{json:!0},at:function(){var b=1<=arguments.length?k.call(arguments,0):[];return new a(this,c(b))},get:function(){return this.snapshot},set:function(a,b){return this.setAt([],a,b)},getAt:function(a){var b=i(this.snapshot,a),c=b.elem,d=b.key;return c[d]},setAt:function(a,b,c){var d=i(this.snapshot,a),e=d.elem,f=d.key,g={p:a};if(e.constructor===Array)g.li=b,typeof e[f]!="undefined"&&(g.ld=e[f]);else{if(typeof e!="object")throw new Error("bad path");g.oi=b,typeof e[f]!="undefined"&&(g.od=e[f])}return this.submitOp([g],c)},removeAt:function(a,b){var c,d=i(this.snapshot,a),e=d.elem,f=d.key;if(typeof e[f]=="undefined")throw new Error("no element at that path");c={p:a};if(e.constructor===Array)c.ld=e[f];else{if(typeof e!="object")throw new Error("bad path");c.od=e[f]}return this.submitOp([c],b)},insertAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h={p:a.concat(b)};return f[g].constructor===Array?h.li=c:typeof f[g]=="string"&&(h.si=c),this.submitOp([h],d)},moveAt:function(a,b,c,d){var e=[{p:a.concat(b),lm:c}];return this.submitOp(e,d)},addAt:function(a,b,c){var d=[{p:a,na:b}];return this.submitOp(d,c)},deleteTextAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h=[{p:a.concat(c),sd:f[g].slice(c,c+b)}];return this.submitOp(h,d)},addListener:function(a,b,c){var d={path:a,event:b,cb:c};return this._listeners.push(d),d},removeListener:function(a){var b=this._listeners.indexOf(a);return b<0?!1:(this._listeners.splice(b,1),!0)},_register:function(){return this._listeners=[],this.on("change",function(a){var b,c,d,e,f,g,h,i,j,k,l=[];for(h=0,i=a.length;h<i;h++){b=a[h];if(b.na!==void 0||b.si!==void 0||b.sd!==void 0)continue;f=[],k=this._listeners;for(d=0,j=k.length;d<j;d++){e=k[d],c={p:e.path,na:0},g=this.type.transformComponent([],c,b,"left");if(g.length===0)f.push(d);else{if(g.length!==1)throw new Error("Bad assumption in json-api: xforming an 'si' op will always result in 0 or 1 components.");e.path=g[0].p}}f.sort(function(a,b){return b-a}),l.push(function(){var a,b,c=[];for(a=0,b=f.length;a<b;a++)d=f[a],c.push(this._listeners.splice(d,1));return c}.call(this))}return l}),this.on("remoteop",function(a){var b,c,d,e,f,h,i,j,k,l=[];for(j=0,k=a.length;j<k;j++)b=a[j],h=b.na===void 0?b.p.slice(0,b.p.length-1):b.p,l.push(function(){var a,j,k,l=this._listeners,m=[];for(a=0,j=l.length;a<j;a++)k=l[a],i=k.path,f=k.event,c=k.cb,m.push(function(){var a;if(g(i,h))switch(f){case"insert":if(b.li!==void 0&&b.ld===void 0)return c(b.p[b.p.length-1],b.li);if(b.oi!==void 0&&b.od===void 0)return c(b.p[b.p.length-1],b.oi);if(b.si!==void 0)return c(b.p[b.p.length-1],b.si);break;case"delete":if(b.li===void 0&&b.ld!==void 0)return c(b.p[b.p.length-1],b.ld);if(b.oi===void 0&&b.od!==void 0)return c(b.p[b.p.length-1],b.od);if(b.sd!==void 0)return c(b.p[b.p.length-1],b.sd);break;case"replace":if(b.li!==void 0&&b.ld!==void 0)return c(b.p[b.p.length-1],b.ld,b.li);if(b.oi!==void 0&&b.od!==void 0)return c(b.p[b.p.length-1],b.od,b.oi);break;case"move":if(b.lm!==void 0)return c(b.p[b.p.length-1],b.lm);break;case"add":if(b.na!==void 0)return c(b.na)}else if((e=this.type.commonPath(h,i))!=null&&f==="child op"){if(h.length===(a=i.length)&&a===e)throw new Error("paths match length and have commonality, but aren't equal?");return d=b.p.slice(e+1),c(d,b)}}.call(this));return m}.call(this));return l})}}}).call(this)
View
209 webclient/json.uncompressed.js
@@ -1,31 +1,22 @@
-// Generated by CoffeeScript 1.3.3
(function() {
/**
@const
@type {boolean}
*/
var WEB = true;
-;
-
- var SubDoc, clone, depath, exports, extendDoc, isArray, json, pathEquals, text, traverse,
- __slice = [].slice;
-
+; var SubDoc, clone, depath, exports, extendDoc, isArray, json, pathEquals, text, traverse;
+ var __slice = Array.prototype.slice;
exports = window['sharejs'];
-
if (typeof WEB !== "undefined" && WEB !== null) {
text = exports.types.text;
} else {
text = require('./text');
}
-
json = {};
-
json.name = 'json';
-
json.create = function() {
return null;
};
-
json.invertComponent = function(c) {
var c_;
c_ = {
@@ -58,7 +49,6 @@ var WEB = true;
}
return c_;
};
-
json.invert = function(op) {
var c, _i, _len, _ref, _results;
_ref = op.slice().reverse();
@@ -69,42 +59,37 @@ var WEB = true;
}
return _results;
};
-
json.checkValidOp = function(op) {};
-
isArray = function(o) {
return Object.prototype.toString.call(o) === '[object Array]';
};
-
json.checkList = function(elem) {
if (!isArray(elem)) {
throw new Error('Referenced element not a list');
}
};
-
json.checkObj = function(elem) {
if (elem.constructor !== Object) {
throw new Error("Referenced element not an object (it was " + (JSON.stringify(elem)) + ")");
}
};
-
json.apply = function(snapshot, op) {
- var c, container, e, elem, i, key, p, parent, parentkey, _i, _j, _len, _len1, _ref;
+ var c, container, e, elem, i, key, p, parent, parentkey, _i, _len, _len2, _ref;
json.checkValidOp(op);
op = clone(op);
container = {
data: clone(snapshot)
};
try {
- for (i = _i = 0, _len = op.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = op.length; i < _len; i++) {
c = op[i];
parent = null;
parentkey = null;
elem = container;
key = 'data';
_ref = c.p;
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
- p = _ref[_j];
+ for (_i = 0, _len2 = _ref.length; _i < _len2; _i++) {
+ p = _ref[_i];
parent = elem;
parentkey = key;
elem = elem[key];
@@ -162,13 +147,12 @@ var WEB = true;
}
return container.data;
};
-
json.pathMatches = function(p1, p2, ignoreLast) {
- var i, p, _i, _len;
+ var i, p, _len;
if (p1.length !== p2.length) {
return false;
}
- for (i = _i = 0, _len = p1.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = p1.length; i < _len; i++) {
p = p1[i];
if (p !== p2[i] && (!ignoreLast || i !== p1.length - 1)) {
return false;
@@ -176,7 +160,6 @@ var WEB = true;
}
return true;
};
-
json.append = function(dest, c) {
var last;
c = clone(c);
@@ -203,7 +186,6 @@ var WEB = true;
return dest.push(c);
}
};
-
json.compose = function(op1, op2) {
var c, newOp, _i, _len;
json.checkValidOp(op1);
@@ -215,7 +197,6 @@ var WEB = true;
}
return newOp;
};
-
json.normalize = function(op) {
var c, newOp, _i, _len, _ref;
newOp = [];
@@ -224,18 +205,18 @@ var WEB = true;
}
for (_i = 0, _len = op.length; _i < _len; _i++) {
c = op[_i];
- if ((_ref = c.p) == null) {
+ if ((_ref = c.p) != null) {
+ _ref;
+ } else {
c.p = [];
- }
+ };
json.append(newOp, c);
}
return newOp;
};
-
clone = function(o) {
return JSON.parse(JSON.stringify(o));
};
-
json.commonPath = function(p1, p2) {
var i;
p1 = p1.slice();
@@ -255,7 +236,6 @@ var WEB = true;
}
}
};
-
json.transformComponent = function(dest, c, otherC, type) {
var common, common2, commonOperand, convert, cplength, from, jc, oc, otherCplength, otherFrom, otherTo, p, res, tc, tc1, tc2, to, _i, _len;
c = clone(c);
@@ -303,9 +283,7 @@ var WEB = true;
}
if (common != null) {
commonOperand = cplength === otherCplength;
- if (otherC.na !== void 0) {
-
- } else if (otherC.si !== void 0 || otherC.sd !== void 0) {
+ if (otherC.na !== void 0) {} else if (otherC.si !== void 0 || otherC.sd !== void 0) {
if (c.si !== void 0 || c.sd !== void 0) {
if (!commonOperand) {
throw new Error("must be a string?");
@@ -518,7 +496,6 @@ var WEB = true;
json.append(dest, c);
return dest;
};
-
if (typeof WEB !== "undefined" && WEB !== null) {
exports.types || (exports.types = {});
exports._bt(json, json.transformComponent, json.checkValidOp, json.append);
@@ -527,11 +504,9 @@ var WEB = true;
module.exports = json;
require('./helpers').bootstrapTransform(json, json.transformComponent, json.checkValidOp, json.append);
}
-
if (typeof WEB === 'undefined') {
json = require('./json');
}
-
if (typeof WEB !== "undefined" && WEB !== null) {
extendDoc = exports.extendDoc;
exports.extendDoc = function(name, fn) {
@@ -539,7 +514,6 @@ var WEB = true;
return extendDoc(name, fn);
};
}
-
depath = function(path) {
if (path.length === 1 && path[0].constructor === Array) {
return path[0];
@@ -547,72 +521,54 @@ var WEB = true;
return path;
}
};
-
SubDoc = (function() {
-
function SubDoc(doc, path) {
this.doc = doc;
this.path = path;
}
-
SubDoc.prototype.at = function() {
var path;
path = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.doc.at(this.path.concat(depath(path)));
};
-
SubDoc.prototype.get = function() {
return this.doc.getAt(this.path);
};
-
SubDoc.prototype.set = function(value, cb) {
return this.doc.setAt(this.path, value, cb);
};
-
SubDoc.prototype.insert = function(pos, value, cb) {
return this.doc.insertAt(this.path, pos, value, cb);
};
-
SubDoc.prototype.del = function(pos, length, cb) {
return this.doc.deleteTextAt(this.path, length, pos, cb);
};
-
SubDoc.prototype.remove = function(cb) {
return this.doc.removeAt(this.path, cb);
};
-
SubDoc.prototype.push = function(value, cb) {
return this.insert(this.get().length, value, cb);
};
-
SubDoc.prototype.move = function(from, to, cb) {
return this.doc.moveAt(this.path, from, to, cb);
};
-
SubDoc.prototype.add = function(amount, cb) {
return this.doc.addAt(this.path, amount, cb);
};
-
SubDoc.prototype.on = function(event, cb) {
return this.doc.addListener(this.path, event, cb);
};
-
SubDoc.prototype.removeListener = function(l) {
return this.doc.removeListener(l);
};
-
SubDoc.prototype.getLength = function() {
return this.get().length;
};
-
SubDoc.prototype.getText = function() {
return this.get();
};
-
return SubDoc;
-
})();
-
traverse = function(snapshot, path) {
var container, elem, key, p, _i, _len;
container = {
@@ -633,13 +589,12 @@ var WEB = true;
key: key
};
};
-
pathEquals = function(p1, p2) {
- var e, i, _i, _len;
+ var e, i, _len;
if (p1.length !== p2.length) {
return false;
}
- for (i = _i = 0, _len = p1.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = p1.length; i < _len; i++) {
e = p1[i];
if (e !== p2[i]) {
return false;
@@ -647,7 +602,6 @@ var WEB = true;
}
return true;
};
-
json.api = {
provides: {
json: true
@@ -773,7 +727,7 @@ var WEB = true;
_register: function() {
this._listeners = [];
this.on('change', function(op) {
- var c, dummy, i, l, to_remove, xformed, _i, _j, _len, _len1, _ref, _results;
+ var c, dummy, i, l, to_remove, xformed, _i, _len, _len2, _ref, _results;
_results = [];
for (_i = 0, _len = op.length; _i < _len; _i++) {
c = op[_i];
@@ -782,7 +736,7 @@ var WEB = true;
}
to_remove = [];
_ref = this._listeners;
- for (i = _j = 0, _len1 = _ref.length; _j < _len1; i = ++_j) {
+ for (i = 0, _len2 = _ref.length; i < _len2; i++) {
l = _ref[i];
dummy = {
p: l.path,
@@ -801,13 +755,13 @@ var WEB = true;
return b - a;
});
_results.push((function() {
- var _k, _len2, _results1;
- _results1 = [];
- for (_k = 0, _len2 = to_remove.length; _k < _len2; _k++) {
- i = to_remove[_k];
- _results1.push(this._listeners.splice(i, 1));
+ var _j, _len3, _results2;
+ _results2 = [];
+ for (_j = 0, _len3 = to_remove.length; _j < _len3; _j++) {
+ i = to_remove[_j];
+ _results2.push(this._listeners.splice(i, 1));
}
- return _results1;
+ return _results2;
}).call(this));
}
return _results;
@@ -819,81 +773,66 @@ var WEB = true;
c = op[_i];
match_path = c.na === void 0 ? c.p.slice(0, c.p.length - 1) : c.p;
_results.push((function() {
- var _j, _len1, _ref, _ref1, _ref2, _results1;
+ var _j, _len2, _ref, _ref2, _results2;
_ref = this._listeners;
- _results1 = [];
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
- _ref1 = _ref[_j], path = _ref1.path, event = _ref1.event, cb = _ref1.cb;
- if (pathEquals(path, match_path)) {
- switch (event) {
- case 'insert':
- if (c.li !== void 0 && c.ld === void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.li));
- } else if (c.oi !== void 0 && c.od === void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.oi));
- } else if (c.si !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.si));
- } else {
- _results1.push(void 0);
- }
- break;
- case 'delete':
- if (c.li === void 0 && c.ld !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.ld));
- } else if (c.oi === void 0 && c.od !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.od));
- } else if (c.sd !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.sd));
- } else {
- _results1.push(void 0);
- }
- break;
- case 'replace':
- if (c.li !== void 0 && c.ld !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.ld, c.li));
- } else if (c.oi !== void 0 && c.od !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.od, c.oi));
- } else {
- _results1.push(void 0);
- }
- break;
- case 'move':
- if (c.lm !== void 0) {
- _results1.push(cb(c.p[c.p.length - 1], c.lm));
- } else {
- _results1.push(void 0);
- }
- break;
- case 'add':
- if (c.na !== void 0) {
- _results1.push(cb(c.na));
- } else {
- _results1.push(void 0);
+ _results2 = [];
+ for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
+ _ref2 = _ref[_j], path = _ref2.path, event = _ref2.event, cb = _ref2.cb;
+ _results2.push((function() {
+ var _ref3;
+ if (pathEquals(path, match_path)) {
+ switch (event) {
+ case 'insert':
+ if (c.li !== void 0 && c.ld === void 0) {
+ return cb(c.p[c.p.length - 1], c.li);
+ } else if (c.oi !== void 0 && c.od === void 0) {
+ return cb(c.p[c.p.length - 1], c.oi);
+ } else if (c.si !== void 0) {
+ return cb(c.p[c.p.length - 1], c.si);
+ }
+ break;
+ case 'delete':
+ if (c.li === void 0 && c.ld !== void 0) {
+ return cb(c.p[c.p.length - 1], c.ld);
+ } else if (c.oi === void 0 && c.od !== void 0) {
+ return cb(c.p[c.p.length - 1], c.od);
+ } else if (c.sd !== void 0) {
+ return cb(c.p[c.p.length - 1], c.sd);
+ }
+ break;
+ case 'replace':
+ if (c.li !== void 0 && c.ld !== void 0) {
+ return cb(c.p[c.p.length - 1], c.ld, c.li);
+ } else if (c.oi !== void 0 && c.od !== void 0) {
+ return cb(c.p[c.p.length - 1], c.od, c.oi);
+ }
+ break;
+ case 'move':
+ if (c.lm !== void 0) {
+ return cb(c.p[c.p.length - 1], c.lm);
+ }
+ break;
+ case 'add':
+ if (c.na !== void 0) {
+ return cb(c.na);
+ }
+ }
+ } else if ((common = this.type.commonPath(match_path, path)) != null) {
+ if (event === 'child op') {
+ if ((match_path.length === (_ref3 = path.length) && _ref3 === common)) {
+ throw new Error("paths match length and have commonality, but aren't equal?");
}
- break;
- default:
- _results1.push(void 0);
- }
- } else if ((common = this.type.commonPath(match_path, path)) != null) {
- if (event === 'child op') {
- if ((match_path.length === (_ref2 = path.length) && _ref2 === common)) {
- throw new Error("paths match length and have commonality, but aren't equal?");
+ child_path = c.p.slice(common + 1);
+ return cb(child_path, c);
}
- child_path = c.p.slice(common + 1);
- _results1.push(cb(child_path, c));
- } else {
- _results1.push(void 0);
}
- } else {
- _results1.push(void 0);
- }
+ }).call(this));
}
- return _results1;
+ return _results2;
}).call(this));
}
return _results;
});
}
};
-
}).call(this);
View
13 webclient/share-ace.js
@@ -1,16 +1,13 @@
-// Generated by CoffeeScript 1.3.3
(function() {
var Range, applyToShareJS;
-
Range = require("ace/range").Range;
-
applyToShareJS = function(editorDoc, delta, doc) {
var getStartOffsetPosition, pos, text;
getStartOffsetPosition = function(range) {
- var i, line, lines, offset, _i, _len;
+ var i, line, lines, offset, _len;
lines = editorDoc.getLines(0, range.start.row);
offset = 0;
- for (i = _i = 0, _len = lines.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = lines.length; i < _len; i++) {
line = lines[i];
offset += i < range.start.row ? line.length : range.start.column;
}
@@ -36,7 +33,6 @@
throw new Error("unknown action: " + delta.action);
}
};
-
window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
if (!this.provides['text']) {
@@ -80,10 +76,10 @@
return check();
};
offsetToPos = function(offset) {
- var line, lines, row, _i, _len;
+ var line, lines, row, _len;
lines = editorDoc.getAllLines();
row = 0;
- for (row = _i = 0, _len = lines.length; _i < _len; row = ++_i) {
+ for (row = 0, _len = lines.length; row < _len; row++) {
line = lines[row];
if (offset <= line.length) {
break;
@@ -115,5 +111,4 @@
return delete doc.detach_ace;
};
});
-
}).call(this);
View
2  webclient/share.js
@@ -1 +1 @@
-(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w=[].slice,E=function(e,t){return function(){return e.apply(t,arguments)}},S=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};window.sharejs=f={version:"0.5.0"},p=function(e){return setTimeout(e,0)},r=function(){function e(){}return e.prototype.on=function(e,t){var n;return this._events||(this._events={}),(n=this._events)[e]||(n[e]=[]),this._events[e].push(t),this},e.prototype.removeListener=function(e,t){var n,r,i,s=this;this._events||(this._events={}),r=(i=this._events)[e]||(i[e]=[]),n=0;while(n<r.length)r[n]===t&&(r[n]=void 0),n++;return p(function(){var t;return s._events[e]=function(){var n,r,i=this._events[e],s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t&&s.push(t);return s}.call(s)}),this},e.prototype.emit=function(){var e,t,n,r,i,s=arguments[0],o=2<=arguments.length?w.call(arguments,1):[];if((r=this._events)!=null?!r[s]:!void 0)return this;i=this._events[s];for(t=0,n=i.length;t<n;t++)e=i[t],e&&e.apply(this,o);return this},e}(),r.mixin=function(e){var t=e.prototype||e;return t.on=r.prototype.on,t.removeListener=r.prototype.removeListener,t.emit=r.prototype.emit,e},f._bt=o=function(e,t,n,r){var i,s=function(e,n,r,i){return t(r,e,n,"left"),t(i,n,e,"right")};return e.transformX=e.transformX=i=function(e,t){var o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T;n(e),n(t),l=[];for(v=0,b=t.length;v<b;v++){d=t[v],f=[],o=0;while(o<e.length){c=[],s(e[o],d,f,c),o++;if(c.length!==1){if(c.length===0){x=e.slice(o);for(m=0,w=x.length;m<w;m++)u=x[m],r(f,u);d=null;break}T=i(e.slice(o),c),a=T[0],p=T[1];for(g=0,E=a.length;g<E;g++)u=a[g],r(f,u);for(y=0,S=p.length;y<S;y++)h=p[y],r(l,h);d=null;break}d=c[0]}d!=null&&r(l,d),e=f}return[e,l]},e.transform=e.transform=function(e,n,r){var s,o,u,a,f;if(r!=="left"&&r!=="right")throw new Error("type must be 'left' or 'right'");return n.length===0?e:e.length===1&&n.length===1?t([],e[0],n[0],r):r==="left"?(a=i(e,n),s=a[0],u=a[1],s):(f=i(n,e),u=f[0],o=f[1],o)}},v={},v.name="text",v.create=function(){return""},d=function(e,t,n){return e.slice(0,t)+n+e.slice(t)},u=function(e){var t,n;if(typeof e.p!="number")throw new Error("component missing position field");n=typeof e.i,t=typeof e.d;if(!(n==="string"^t==="string"))throw new Error("component needs an i or d field");if(!(e.p>=0))throw new Error("position cannot be negative")},a=function(e){var t,n,r;for(n=0,r=e.length;n<r;n++)t=e[n],u(t);return!0},v.apply=function(e,t){var n,r,i,s;a(t);for(i=0,s=t.length;i<s;i++){n=t[i];if(n.i!=null)e=d(e,n.p,n.i);else{r=e.slice(n.p,n.p+n.d.length);if(n.d!==r)throw new Error("Delete component '"+n.d+"' does not match deleted text '"+r+"'");e=e.slice(0,n.p)+e.slice(n.p+n.d.length)}}return e},v._append=s=function(e,t){var n,r,i;if(t.i===""||t.d==="")return;return e.length===0?e.push(t):(n=e[e.length-1],n.i!=null&&t.i!=null&&n.p<=(r=t.p)&&r<=n.p+n.i.length?e[e.length-1]={i:d(n.i,t.p-n.p,t.i),p:n.p}:n.d!=null&&t.d!=null&&t.p<=(i=n.p)&&i<=t.p+t.d.length?e[e.length-1]={d:d(t.d,n.p-t.p,n.d),p:t.p}:e.push(t))},v.compose=function(e,t){var n,r,i,o;a(e),a(t),r=e.slice();for(i=0,o=t.length;i<o;i++)n=t[i],s(r,n);return r},v.compress=function(e){return v.compose([],e)},v.normalize=function(e){var t,n,r,i,o=[];if(e.i!=null||e.p!=null)e=[e];for(n=0,r=e.length;n<r;n++)t=e[n],(i=t.p)==null&&(t.p=0),s(o,t);return o},g=function(e,t,n){return t.i!=null?t.p<e||t.p===e&&n?e+t.i.length:e:e<=t.p?e:e<=t.p+t.d.length?t.p:e-t.d.length},v.transformCursor=function(e,t,n){var r,i,s,o=n==="right";for(i=0,s=t.length;i<s;i++)r=t[i],e=g(e,r,o);return e},v._tc=m=function(e,t,n,r){var i,o,u,f,l,c;a([t]),a([n]);if(t.i!=null)s(e,{i:t.i,p:g(t.p,n,r==="right")});else if(n.i!=null)c=t.d,t.p<n.p&&(s(e,{d:c.slice(0,n.p-t.p),p:t.p}),c=c.slice(n.p-t.p)),c!==""&&s(e,{d:c,p:t.p+n.i.length});else if(t.p>=n.p+n.d.length)s(e,{d:t.d,p:t.p-n.d.length});else if(t.p+t.d.length<=n.p)s(e,t);else{f={d:"",p:t.p},t.p<n.p&&(f.d=t.d.slice(0,n.p-t.p)),t.p+t.d.length>n.p+n.d.length&&(f.d+=t.d.slice(n.p+n.d.length-t.p)),u=Math.max(t.p,n.p),o=Math.min(t.p+t.d.length,n.p+n.d.length),i=t.d.slice(u-t.p,o-t.p),l=n.d.slice(u-n.p,o-n.p);if(i!==l)throw new Error("Delete ops delete different text in the same region of the document");f.d!==""&&(f.p=g(f.p,n),s(e,f))}return e},h=function(e){return e.i!=null?{d:e.i,p:e.p}:{i:e.d,p:e.p}},v.invert=function(e){var t,n,r,i=e.slice().reverse(),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(h(t));return s},f.types||(f.types={}),o(v,m,a,s),f.types.text=v,v.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(e,t,n){var r=[{p:e,i:t}];return this.submitOp(r,n),r},del:function(e,t,n){var r=[{p:e,d:this.snapshot.slice(e,e+t)}];return this.submitOp(r,n),r},_register:function(){return this.on("remoteop",function(e){var t,n,r,i=[];for(n=0,r=e.length;n<r;n++)t=e[n],t.i!==void 0?i.push(this.emit("insert",t.p,t.i)):i.push(this.emit("delete",t.p,t.d));return i})}},f.extendDoc=function(e,t){return n.prototype[e]=t},n=function(){function e(e,t,n){this.connection=e,this.name=t,this.shout=E(this.shout,this),this.flush=E(this.flush,this),n||(n={}),this.version=n.v,this.snapshot=n.snaphot,n.type&&this._setType(n.type),this.state="closed",this.autoOpen=!1,this._create=n.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return e.prototype._xf=function(e,t){var n,r;return this.type.transformX?this.type.transformX(e,t):(n=this.type.transform(e,t,"left"),r=this.type.transform(t,e,"right"),[n,r])},e.prototype._otApply=function(e,t){var n=this.snapshot;this.snapshot=this.type.apply(this.snapshot,e),this.emit("change",e,n);if(t)return this.emit("remoteop",e,n)},e.prototype._connectionStateChanged=function(e,t){switch(e){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(t)}return this.emit(e,t)},e.prototype._setType=function(e){var t,n,r;typeof e=="string"&&(e=y[e]);if(!e||!e.compose)throw new Error("Support for types without compose() is not implemented");this.type=e;if(e.api){r=e.api;for(t in r)n=r[t],this[t]=n;return typeof this._register=="function"?this._register():void 0}return this.provides={}},e.prototype._onMessage=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w;if(e.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!e.create),e.type&&this._setType(e.type),e.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),e.snapshot!==void 0&&(this.snapshot=e.snapshot)),e.v!=null&&(this.version=e.v),this.inflightOp?(u={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(u.dupIfSource=this.inflightSubmittedIds),this.connection.send(u)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(e.open===!1)return e.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+e.error),this.emit("error",e.error),typeof this._openCallback=="function"&&this._openCallback(e.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(e.op!==null||r!=="Op already submitted"){if(e.op===void 0&&e.v!==void 0||e.op&&(d=e.meta.source,S.call(this.inflightSubmittedIds,d)>=0)){i=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,r=e.error;if(r){this.type.invert?(a=this.type.invert(i),this.pendingOp&&(v=this._xf(this.pendingOp,a),this.pendingOp=v[0],a=v[1]),this._otApply(a,!0)):this.emit("error","Op apply failed ("+r+") and the op could not be reverted"),m=this.inflightCallbacks;for(l=0,h=m.length;l<h;l++)t=m[l],t(r)}else{if(e.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=i,this.version++,this.emit("acknowledge",i),g=this.inflightCallbacks;for(c=0,p=g.length;c<p;c++)t=g[c],t(null,i)}return this.flush()}if(e.op){if(e.v<this.version)return;return e.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+e.doc):e.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+e.v):(s=e.op,this.serverOps[this.version]=s,n=s,this.inflightOp!==null&&(y=this._xf(this.inflightOp,n),this.inflightOp=y[0],n=y[1]),this.pendingOp!==null&&(b=this._xf(this.pendingOp,n),this.pendingOp=b[0],n=b[1]),this.version++,this._otApply(n,!0))}if(!e.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",e):void 0;w=e.meta,o=w.path,f=w.value;switch(o!=null?o[0]:void 0){case"shout":return this.emit("shout",f);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",e):void 0}}},e.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},e.prototype.submitOp=function(e,t){return this.type.normalize!=null&&(e=this.type.normalize(e)),this.snapshot=this.type.apply(this.snapshot,e),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,e):this.pendingOp=e,t&&this.pendingCallbacks.push(t),this.emit("change",e),setTimeout(this.flush,0)},e.prototype.shout=function(e){return this.connection.send({doc:this.name,meta:{path:["shout"],value:e}})},e.prototype.open=function(e){var t,n=this;this.autoOpen=!0;if(this.state!=="closed")return;return t={doc:this.name,open:!0},this.snapshot===void 0&&(t.snapshot=null),this.type&&(t.type=this.type.name),this.version!=null&&(t.v=this.version),this._create&&(t.create=!0),this.connection.send(t),this.state="opening",this._openCallback=function(t){return n._openCallback=null,typeof e=="function"?e(t):void 0}},e.prototype.close=function(e){return this.autoOpen=!1,this.state==="closed"?typeof e=="function"?e():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=e)},e}(),r.mixin(n),f.Doc=n,y=f.types,e=window.BCSocket,i=window.SockJS,t=function(){function t(t){var n=this;this.docs={},this.state="connecting",this.socket=typeof b!="undefined"&&b!==null?new i(t):new e(t,{reconnect:!0}),this.socket.onmessage=function(e){var t;typeof b!="undefined"&&b!==null&&(e=JSON.parse(e.data));if(e.auth===null)return n.lastError=e.error,n.disconnect(),n.emit("connect failed",e.error);if(e.auth){n.id=e.auth,n.setState("ok");return}return t=e.doc,t!==void 0?n.lastReceivedDoc=t:e.doc=t=n.lastReceivedDoc,n.docs[t]?n.docs[t]._onMessage(e):typeof console!="undefined"&&console!==null?console.error("Unhandled message",e):void 0},this.connected=!1,this.socket.onclose=function(e){n.setState("disconnected",e);if(e==="Closed"||e==="Stopped by server")return n.setState("stopped",n.lastError||e)},this.socket.onerror=function(e){return n.emit("error",e)},this.socket.onopen=function(){return n.lastError=n.lastReceivedDoc=n.lastSentDoc=null,n.setState("handshaking")},this.socket.onconnecting=function(){return n.setState("connecting")}}return t.prototype.setState=function(e,t){var n,r,i,s;if(this.state===e)return;this.state=e,e==="disconnected"&&delete this.id,this.emit(e,t),i=this.docs,s=[];for(r in i)n=i[r],s.push(n._connectionStateChanged(e,t));return s},t.prototype.send=function(e){var t=e.doc;return t===this.lastSentDoc?delete e.doc:this.lastSentDoc=t,typeof b!="undefined"&&b!==null&&(e=JSON.stringify(e)),this.socket.send(e)},t.prototype.disconnect=function(){return this.socket.close()},t.prototype.makeDoc=function(e,t,r){var i,s=this;if(this.docs[e])throw new Error("Doc "+e+" already open");return i=new n(this,e,t),this.docs[e]=i,i.open(function(t){return t&&delete s.docs[e],r(t,t?void 0:i)})},t.prototype.openExisting=function(e,t){var n;return this.state==="stopped"?t("connection closed"):this.docs[e]?t(null,this.docs[e]):n=this.makeDoc(e,{},t)},t.prototype.open=function(e,t,n){var r;if(this.state==="stopped")return n("connection closed");if(this.state==="connecting"){this.on("handshaking",function(){return this.open(e,t,n)});return}typeof t=="function"&&(n=t,t="text"),n||(n=function(){}),typeof t=="string"&&(t=y[t]);if(!t)throw new Error("OT code for document type missing");if(e==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[e]){r=this.docs[e],r.type===t?n(null,r):n("Type mismatch",r);return}return this.makeDoc(e,{create:!0,type:t.name},n)},t}(),r.mixin(t),f.Connection=t,l=window.BCSocket!==void 0,c=window.SockJS!==void 0;if(!l&&!c)throw new Error("Must load socks or browserchannel before this library");c&&!l&&(b=!0),f.open=function(){var e={},n=function(n){var r,i,s,o;return s=window.location,o=b?"sockjs":"channel",n==null&&(n=""+s.protocol+"//"+s.host+"/"+o),e[n]||(r=new t(n),i=function(){return delete e[n]},r.on("disconnected",i),r.on("connect failed",i),e[n]=r),e[n]},r=function(e){var t,n,r=0,i=e.docs;for(n in i)t=i[n],(t.state!=="closed"||t.autoOpen)&&r++;if(r===0)return e.disconnect()};return function(e,t,i,s){var o;return typeof i=="function"&&(s=i,i=null),o=n(i),o.numDocs++,o.open(e,t,function(e,t){return e?(s(e),r(o)):(t.on("closed",function(){return r(o)}),s(null,t))}),o.on("connect failed"),o}}()}).call(this)
+(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u=function(a,b){return function(){return a.apply(b,arguments)}},v=Array.prototype.slice,w=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(this[b]===a)return b;return-1};window.sharejs=j={version:"0.5.0"},n=function(a){return setTimeout(a,0)},d=function(){function a(){}return a.prototype.on=function(a,b){var c;return this._events||(this._events={}),(c=this._events)[a]||(c[a]=[]),this._events[a].push(b),this},a.prototype.removeListener=function(a,b){var c,d,e;this._events||(this._events={}),d=(e=this._events)[a]||(e[a]=[]),c=0;while(c<d.length)d[c]===b&&(d[c]=void 0),c++;return n(u(function(){var b;return this._events[a]=function(){var c,d,e=this._events[a],f=[];for(c=0,d=e.length;c<d;c++)b=e[c],b&&f.push(b);return f}.call(this)},this)),this},a.prototype.emit=function(){var a,b,c,d,e,f=arguments[0],g=2<=arguments.length?v.call(arguments,1):[];if((d=this._events)!=null?!d[f]:!void 0)return this;e=this._events[f];for(b=0,c=e.length;b<c;b++)a=e[b],a&&a.apply(this,g);return this},a}(),d.mixin=function(a){var b=a.prototype||a;return b.on=d.prototype.on,b.removeListener=d.prototype.removeListener,b.emit=d.prototype.emit,a},j._bt=g=function(a,b,c,d){var e,f=function(a,c,d,e){return b(d,a,c,"left"),b(e,c,a,"right")};return a.transformX=a.transformX=e=function(a,b){var g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;c(a),c(b),k=[];for(p=0,t=b.length;p<t;p++){o=b[p],j=[],g=0;while(g<a.length){l=[],f(a[g],o,j,l),g++;if(l.length!==1){if(l.length===0){x=a.slice(g);for(q=0,u=x.length;q<u;q++)h=x[q],d(j,h);o=null;break}y=e(a.slice(g),l),i=y[0],n=y[1];for(r=0,v=i.length;r<v;r++)h=i[r],d(j,h);for(s=0,w=n.length;s<w;s++)m=n[s],d(k,m);o=null;break}o=l[0]}o!=null&&d(k,o),a=j}return[a,k]},a.transform=a.transform=function(a,c,d){var f,g,h,i,j;if(d!=="left"&&d!=="right")throw new Error("type must be 'left' or 'right'");return c.length===0?a:a.length===1&&c.length===1?b([],a[0],c[0],d):d==="left"?(i=e(a,c),f=i[0],h=i[1],f):(j=e(c,a),h=j[0],g=j[1],g)}},p={},p.name="text",p.create=function(){return""},o=function(a,b,c){return a.slice(0,b)+c+a.slice(b)},h=function(a){var b,c;if(typeof a.p!="number")throw new Error("component missing position field");c=typeof a.i,b=typeof a.d;if(!(c==="string"^b==="string"))throw new Error("component needs an i or d field");if(!(a.p>=0))throw new Error("position cannot be negative")},i=function(a){var b,c,d;for(c=0,d=a.length;c<d;c++)b=a[c],h(b);return!0},p.apply=function(a,b){var c,d,e,f;i(b);for(e=0,f=b.length;e<f;e++){c=b[e];if(c.i!=null)a=o(a,c.p,c.i);else{d=a.slice(c.p,c.p+c.d.length);if(c.d!==d)throw new Error("Delete component '"+c.d+"' does not match deleted text '"+d+"'");a=a.slice(0,c.p)+a.slice(c.p+c.d.length)}}return a},p._append=f=function(a,b){var c,d,e;if(b.i===""||b.d==="")return;return a.length===0?a.push(b):(c=a[a.length-1],c.i!=null&&b.i!=null&&c.p<=(d=b.p)&&d<=c.p+c.i.length?a[a.length-1]={i:o(c.i,b.p-c.p,b.i),p:c.p}:c.d!=null&&b.d!=null&&b.p<=(e=c.p)&&e<=b.p+b.d.length?a[a.length-1]={d:o(b.d,c.p-b.p,c.d),p:b.p}:a.push(b))},p.compose=function(a,b){var c,d,e,g;i(a),i(b),d=a.slice();for(e=0,g=b.length;e<g;e++)c=b[e],f(d,c);return d},p.compress=function(a){return p.compose([],a)},p.normalize=function(a){var b,c,d,e,g=[];if(a.i!=null||a.p!=null)a=[a];for(c=0,d=a.length;c<d;c++)b=a[c],(e=b.p)!=null?e:b.p=0,f(g,b);return g},r=function(a,b,c){return b.i!=null?b.p<a||b.p===a&&c?a+b.i.length:a:a<=b.p?a:a<=b.p+b.d.length?b.p:a-b.d.length},p.transformCursor=function(a,b,c){var d,e,f,g=c==="right";for(e=0,f=b.length;e<f;e++)d=b[e],a=r(a,d,g);return a},p._tc=q=function(a,b,c,d){var e,g,h,j,k,l;i([b]),i([c]);if(b.i!=null)f(a,{i:b.i,p:r(b.p,c,d==="right")});else if(c.i!=null)l=b.d,b.p<c.p&&(f(a,{d:l.slice(0,c.p-b.p),p:b.p}),l=l.slice(c.p-b.p)),l!==""&&f(a,{d:l,p:b.p+c.i.length});else if(b.p>=c.p+c.d.length)f(a,{d:b.d,p:b.p-c.d.length});else if(b.p+b.d.length<=c.p)f(a,b);else{j={d:"",p:b.p},b.p<c.p&&(j.d=b.d.slice(0,c.p-b.p)),b.p+b.d.length>c.p+c.d.length&&(j.d+=b.d.slice(c.p+c.d.length-b.p)),h=Math.max(b.p,c.p),g=Math.min(b.p+b.d.length,c.p+c.d.length),e=b.d.slice(h-b.p,g-b.p),k=c.d.slice(h-c.p,g-c.p);if(e!==k)throw new Error("Delete ops delete different text in the same region of the document");j.d!==""&&(j.p=r(j.p,c),f(a,j))}return a},m=function(a){return a.i!=null?{d:a.i,p:a.p}:{i:a.d,p:a.p}},p.invert=function(a){var b,c,d,e=a.slice().reverse(),f=[];for(c=0,d=e.length;c<d;c++)b=e[c],f.push(m(b));return f},j.types||(j.types={}),g(p,q,i,f),j.types.text=p,p.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(a,b,c){var d=[{p:a,i:b}];return this.submitOp(d,c),d},del:function(a,b,c){var d=[{p:a,d:this.snapshot.slice(a,a+b)}];return this.submitOp(d,c),d},_register:function(){return this.on("remoteop",function(a){var b,c,d,e=[];for(c=0,d=a.length;c<d;c++)b=a[c],e.push(b.i!==void 0?this.emit("insert",b.p,b.i):this.emit("delete",b.p,b.d));return e})}},j.extendDoc=function(a,b){return c.prototype[a]=b},c=function(){function a(a,b,c){this.connection=a,this.name=b,this.shout=u(this.shout,this),this.flush=u(this.flush,this),c||(c={}),this.version=c.v,this.snapshot=c.snaphot,c.type&&this._setType(c.type),this.state="closed",this.autoOpen=!1,this._create=c.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return a.prototype._xf=function(a,b){var c,d;return this.type.transformX?this.type.transformX(a,b):(c=this.type.transform(a,b,"left"),d=this.type.transform(b,a,"right"),[c,d])},a.prototype._otApply=function(a,b){var c=this.snapshot;this.snapshot=this.type.apply(this.snapshot,a),this.emit("change",a,c);if(b)return this.emit("remoteop",a,c)},a.prototype._connectionStateChanged=function(a,b){switch(a){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(b)}return this.emit(a,b)},a.prototype._setType=function(a){var b,c,d;typeof a=="string"&&(a=s[a]);if(!a||!a.compose)throw new Error("Support for types without compose() is not implemented");this.type=a;if(a.api){d=a.api;for(b in d)c=d[b],this[b]=c;return typeof this._register=="function"?this._register():void 0}return this.provides={}},a.prototype._onMessage=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;if(a.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!a.create),a.type&&this._setType(a.type),a.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),a.snapshot!==void 0&&(this.snapshot=a.snapshot)),a.v!=null&&(this.version=a.v),this.inflightOp?(h={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(h.dupIfSource=this.inflightSubmittedIds),this.connection.send(h)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(a.open===!1)return a.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+a.error),this.emit("error",a.error),typeof this._openCallback=="function"&&this._openCallback(a.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(a.op!==null||d!=="Op already submitted"){if(a.op===void 0&&a.v!==void 0||a.op&&(o=a.meta.source,w.call(this.inflightSubmittedIds,o)>=0)){e=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,d=a.error;if(d){this.type.invert?(i=this.type.invert(e),this.pendingOp&&(p=this._xf(this.pendingOp,i),this.pendingOp=p[0],i=p[1]),this._otApply(i,!0)):this.emit("error","Op apply failed ("+d+") and the op could not be reverted"),q=this.inflightCallbacks;for(k=0,m=q.length;k<m;k++)b=q[k],b(d)}else{if(a.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=e,this.version++,this.emit("acknowledge",e),r=this.inflightCallbacks;for(l=0,n=r.length;l<n;l++)b=r[l],b(null,e)}return this.flush()}if(a.op){if(a.v<this.version)return;return a.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+a.doc):a.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+a.v):(f=a.op,this.serverOps[this.version]=f,c=f,this.inflightOp!==null&&(s=this._xf(this.inflightOp,c),this.inflightOp=s[0],c=s[1]),this.pendingOp!==null&&(t=this._xf(this.pendingOp,c),this.pendingOp=t[0],c=t[1]),this.version++,this._otApply(c,!0))}if(!a.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",a):void 0;u=a.meta,g=u.path,j=u.value;switch(g!=null?g[0]:void 0){case"shout":return this.emit("shout",j);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",a):void 0}}},a.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},a.prototype.submitOp=function(a,b){return this.type.normalize!=null&&(a=this.type.normalize(a)),this.snapshot=this.type.apply(this.snapshot,a),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,a):this.pendingOp=a,b&&this.pendingCallbacks.push(b),this.emit("change",a),setTimeout(this.flush,0)},a.prototype.shout=function(a){return this.connection.send({doc:this.name,meta:{path:["shout"],value:a}})},a.prototype.open=function(a){var b;this.autoOpen=!0;if(this.state!=="closed")return;return b={doc:this.name,open:!0},this.snapshot===void 0&&(b.snapshot=null),this.type&&(b.type=this.type.name),this.version!=null&&(b.v=this.version),this._create&&(b.create=!0),this.connection.send(b),this.state="opening",this._openCallback=u(function(b){return this._openCallback=null,typeof a=="function"?a(b):void 0},this)},a.prototype.close=function(a){return this.autoOpen=!1,this.state==="closed"?typeof a=="function"?a():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=a)},a}(),d.mixin(c),j.Doc=c,s=j.types,a=window.BCSocket,e=window.SockJS,b=function(){function b(b,c){this.docs={},this.state="connecting",this.socket=typeof t!="undefined"&&t!==null?new e(b):new a(b,{reconnect:!0}),this.socket.send({auth:c?c:null}),this.socket.onmessage=u(function(a){var b;typeof t!="undefined"&&t!==null&&(a=JSON.parse(a.data));if(a.auth===null)return this.lastError=a.error,this.disconnect(),this.emit("connect failed",a.error);if(a.auth){this.id=a.auth,this.setState("ok");return}return b=a.doc,b!==void 0?this.lastReceivedDoc=b:a.doc=b=this.lastReceivedDoc,this.docs[b]?this.docs[b]._onMessage(a):typeof console!="undefined"&&console!==null?console.error("Unhandled message",a):void 0},this),this.connected=!1,this.socket.onclose=u(function(a){this.setState("disconnected",a);if(a==="Closed"||a==="Stopped by server")return this.setState("stopped",this.lastError||a)},this),this.socket.onerror=u(function(a){return this.emit("error",a)},this),this.socket.onopen=u(function(){return this.lastError=this.lastReceivedDoc=this.lastSentDoc=null,this.setState("handshaking")},this),this.socket.onconnecting=u(function(){return this.setState("connecting")},this)}return b.prototype.setState=function(a,b){var c,d,e,f;if(this.state===a)return;this.state=a,a==="disconnected"&&delete this.id,this.emit(a,b),e=this.docs,f=[];for(d in e)c=e[d],f.push(c._connectionStateChanged(a,b));return f},b.prototype.send=function(a){var b=a.doc;return b===this.lastSentDoc?delete a.doc:this.lastSentDoc=b,typeof t!="undefined"&&t!==null&&(a=JSON.stringify(a)),this.socket.send(a)},b.prototype.disconnect=function(){return this.socket.close()},b.prototype.makeDoc=function(a,b,d){var e;if(this.docs[a])throw new Error("Doc "+a+" already open");return e=new c(this,a,b),this.docs[a]=e,e.open(u(function(b){return b&&delete this.docs[a],d(b,b?void 0:e)},this))},b.prototype.openExisting=function(a,b){var c;return this.state==="stopped"?b("connection closed"):this.docs[a]?b(null,this.docs[a]):c=this.makeDoc(a,{},b)},b.prototype.open=function(a,b,c){var d;if(this.state==="stopped")return c("connection closed");if(this.state==="connecting"){this.on("handshaking",function(){return this.open(a,b,c)});return}typeof b=="function"&&(c=b,b="text"),c||(c=function(){}),typeof b=="string"&&(b=s[b]);if(!b)throw new Error("OT code for document type missing");if(a==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[a]){d=this.docs[a],d.type===b?c(null,d):c("Type mismatch",d);return}return this.makeDoc(a,{create:!0,type:b.name},c)},b}(),d.mixin(b),j.Connection=b,k=window.BCSocket!==void 0,l=window.SockJS!==void 0;if(!k&&!l)throw new Error("Must load socks or browserchannel before this library");l&&!k&&(t=!0),j.open=function(){var a={},c=function(c,d){var e,f,g,h;return g=window.location,h=t?"sockjs":"channel",c!=null?c:c=""+g.protocol+"//"+g.host+"/"+h,a[c]||(e=new b(c,d),f=function(){return delete a[c]},e.on("disconnected",f),e.on("connect failed",f),a[c]=e),a[c]},d=function(a){var b,c,d=0,e=a.docs;for(c in e)b=e[c],(b.state!=="closed"||b.autoOpen)&&d++;if(d===0)return a.disconnect()};return function(a,b,e,f){var g,h,i;return typeof e=="function"&&(f=e,e={}),i=e.origin,g=e.authentication,h=c(i,g),h.numDocs++,h.open(a,b,function(a,b){return a?(f(a),d(h)):(b.on("closed",function(){return d(h)}),f(null,b))}),h.on("connect failed"),h}}()}).call(this)
View
263 webclient/share.uncompressed.js
@@ -1,26 +1,22 @@
-// Generated by CoffeeScript 1.3.3
(function() {
- var BCSocket, Connection, Doc, MicroEvent, SockJS, append, bootstrapTransform, checkValidComponent, checkValidOp, exports, hasBCSocket, hasSockJS, invertComponent, nextTick, strInject, text, transformComponent, transformPosition, types, useSockJS,
- __slice = [].slice,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
-
+ var BCSocket, Connection, Doc, MicroEvent, SockJS, append, bootstrapTransform, checkValidComponent, checkValidOp, exports, hasBCSocket, hasSockJS, invertComponent, nextTick, strInject, text, transformComponent, transformPosition, types, useSockJS;
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice, __indexOf = Array.prototype.indexOf || function(item) {
+ for (var i = 0, l = this.length; i < l; i++) {
+ if (this[i] === item) return i;
+ }
+ return -1;
+ };
window.sharejs = exports = {
'version': '0.5.0'
};
-
if (typeof WEB === 'undefined') {
window.WEB = true;
}
-
nextTick = typeof WEB !== "undefined" && WEB !== null ? function(fn) {
return setTimeout(fn, 0);
} : process['nextTick'];
-
MicroEvent = (function() {
-
function MicroEvent() {}
-
MicroEvent.prototype.on = function(event, fct) {
var _base;
this._events || (this._events = {});
@@ -28,10 +24,8 @@
this._events[event].push(fct);
return this;
};
-
MicroEvent.prototype.removeListener = function(event, fct) {
- var i, listeners, _base,
- _this = this;
+ var i, listeners, _base;
this._events || (this._events = {});
listeners = ((_base = this._events)[event] || (_base[event] = []));
i = 0;
@@ -41,9 +35,9 @@
}
i++;
}
- nextTick(function() {
+ nextTick(__bind(function() {
var x;
- return _this._events[event] = (function() {
+ return this._events[event] = (function() {
var _i, _len, _ref, _results;
_ref = this._events[event];
_results = [];
@@ -54,31 +48,27 @@
}
}
return _results;
- }).call(_this);
- });
+ }).call(this);
+ }, this));
return this;
};
-
MicroEvent.prototype.emit = function() {
- var args, event, fn, _i, _len, _ref, _ref1;
+ var args, event, fn, _i, _len, _ref, _ref2;
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (!((_ref = this._events) != null ? _ref[event] : void 0)) {
return this;
}
- _ref1 = this._events[event];
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- fn = _ref1[_i];
+ _ref2 = this._events[event];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ fn = _ref2[_i];
if (fn) {
fn.apply(this, args);
}
}
return this;
};
-
return MicroEvent;
-
})();
-
MicroEvent.mixin = function(obj) {
var proto;
proto = obj.prototype || obj;
@@ -87,11 +77,9 @@
proto.emit = MicroEvent.prototype.emit;
return obj;
};
-
if (typeof WEB === "undefined" || WEB === null) {
module.exports = MicroEvent;
}
-
exports['_bt'] = bootstrapTransform = function(type, transformComponent, checkValidOp, append) {
var transformComponentX, transformX;
transformComponentX = function(left, right, destLeft, destRight) {
@@ -99,7 +87,7 @@
return transformComponent(destRight, right, left, 'right');
};
type.transformX = type['transformX'] = transformX = function(leftOp, rightOp) {
- var k, l, l_, newLeftOp, newRightOp, nextC, r, r_, rightComponent, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1;
+ var k, l, l_, newLeftOp, newRightOp, nextC, r, r_, rightComponent, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2;
checkValidOp(leftOp);
checkValidOp(rightOp);
newRightOp = [];
@@ -115,19 +103,19 @@
rightComponent = nextC[0];
} else if (nextC.length === 0) {
_ref = leftOp.slice(k);
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
+ for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
l = _ref[_j];
append(newLeftOp, l);
}
rightComponent = null;
break;
} else {
- _ref1 = transformX(leftOp.slice(k), nextC), l_ = _ref1[0], r_ = _ref1[1];
- for (_k = 0, _len2 = l_.length; _k < _len2; _k++) {
+ _ref2 = transformX(leftOp.slice(k), nextC), l_ = _ref2[0], r_ = _ref2[1];
+ for (_k = 0, _len3 = l_.length; _k < _len3; _k++) {
l = l_[_k];
append(newLeftOp, l);
}
- for (_l = 0, _len3 = r_.length; _l < _len3; _l++) {
+ for (_l = 0, _len4 = r_.length; _l < _len4; _l++) {
r = r_[_l];
append(newRightOp, r);
}
@@ -143,7 +131,7 @@
return [leftOp, newRightOp];
};
return type.transform = type['transform'] = function(op, otherOp, type) {
- var left, right, _, _ref, _ref1;
+ var left, right, _, _ref, _ref2;
if (!(type === 'left' || type === 'right')) {
throw new Error("type must be 'left' or 'right'");
}
@@ -157,28 +145,22 @@
_ref = transformX(op, otherOp), left = _ref[0], _ = _ref[1];
return left;
} else {
- _ref1 = transformX(otherOp, op), _ = _ref1[0], right = _ref1[1];
+ _ref2 = transformX(otherOp, op), _ = _ref2[0], right = _ref2[1];
return right;
}
};
};
-
if (typeof WEB === 'undefined') {
exports.bootstrapTransform = bootstrapTransform;
}
-
text = {};
-
text.name = 'text';
-
text.create = function() {
return '';
};
-
strInject = function(s1, pos, s2) {
return s1.slice(0, pos) + s2 + s1.slice(pos);
};
-
checkValidComponent = function(c) {
var d_type, i_type;
if (typeof c.p !== 'number') {
@@ -193,7 +175,6 @@
throw new Error('position cannot be negative');
}
};
-
checkValidOp = function(op) {
var c, _i, _len;
for (_i = 0, _len = op.length; _i < _len; _i++) {
@@ -202,7 +183,6 @@
}
return true;
};
-
text.apply = function(snapshot, op) {
var component, deleted, _i, _len;
checkValidOp(op);
@@ -220,9 +200,8 @@
}
return snapshot;
};
-
text._append = append = function(newOp, c) {
- var last, _ref, _ref1;
+ var last, _ref, _ref2;
if (c.i === '' || c.d === '') {
return;
}
@@ -235,7 +214,7 @@
i: strInject(last.i, c.p - last.p, c.i),
p: last.p
};
- } else if ((last.d != null) && (c.d != null) && (c.p <= (_ref1 = last.p) && _ref1 <= (c.p + c.d.length))) {
+ } else if ((last.d != null) && (c.d != null) && (c.p <= (_ref2 = last.p) && _ref2 <= (c.p + c.d.length))) {
return newOp[newOp.length - 1] = {
d: strInject(c.d, last.p - c.p, last.d),
p: c.p
@@ -245,7 +224,6 @@
}
}
};
-
text.compose = function(op1, op2) {
var c, newOp, _i, _len;
checkValidOp(op1);
@@ -257,11 +235,9 @@
}
return newOp;
};
-
text.compress = function(op) {
return text.compose([], op);
};
-
text.normalize = function(op) {
var c, newOp, _i, _len, _ref;
newOp = [];
@@ -270,14 +246,15 @@
}
for (_i = 0, _len = op.length; _i < _len; _i++) {
c = op[_i];
- if ((_ref = c.p) == null) {
+ if ((_ref = c.p) != null) {
+ _ref;
+ } else {
c.p = 0;
- }
+ };
append(newOp, c);
}
return newOp;
};
-
transformPosition = function(pos, c, insertAfter) {
if (c.i != null) {
if (c.p < pos || (c.p === pos && insertAfter)) {
@@ -295,7 +272,6 @@
}
}
};
-
text.transformCursor = function(position, op, side) {
var c, insertAfter, _i, _len;
insertAfter = side === 'right';
@@ -305,7 +281,6 @@
}
return position;
};
-
text._tc = transformComponent = function(dest, c, otherC, side) {
var cIntersect, intersectEnd, intersectStart, newC, otherIntersect, s;
checkValidOp([c]);
@@ -366,7 +341,6 @@
}
return dest;
};
-
invertComponent = function(c) {
if (c.i != null) {
return {
@@ -380,7 +354,6 @@
};
}
};
-
text.invert = function(op) {
var c, _i, _len, _ref, _results;
_ref = op.slice().reverse();
@@ -391,7 +364,6 @@
}
return _results;
};
-
if (typeof WEB !== "undefined" && WEB !== null) {
exports.types || (exports.types = {});
bootstrapTransform(text, transformComponent, checkValidOp, append);
@@ -400,11 +372,9 @@
module.exports = text;
require('./helpers').bootstrapTransform(text, transformComponent, checkValidOp, append);
}
-
if (typeof WEB === 'undefined') {
text = require('./text');
}
-
text.api = {
provides: {
text: true
@@ -443,36 +413,26 @@
_results = [];
for (_i = 0, _len = op.length; _i < _len; _i++) {
component = op[_i];
- if (component.i !== void 0) {
- _results.push(this.emit('insert', component.p, component.i));
- } else {
- _results.push(this.emit('delete', component.p, component.d));
- }
+ _results.push(component.i !== void 0 ? this.emit('insert', component.p, component.i) : this.emit('delete', component.p, component.d));
}
return _results;
});
}
};
-
if (typeof WEB === "undefined" || WEB === null) {
types = require('../types');
}
-
if (typeof WEB !== "undefined" && WEB !== null) {
exports.extendDoc = function(name, fn) {
return Doc.prototype[name] = fn;
};
}
-
Doc = (function() {
-
function Doc(connection, name, openData) {
this.connection = connection;
this.name = name;
- this.shout = __bind(this.shout, this);
-
- this.flush = __bind(this.flush, this);
-
+ this.shout = __bind(this.shout, this);;
+ this.flush = __bind(this.flush, this);;
openData || (openData = {});
this.version = openData.v;
this.snapshot = openData.snaphot;
@@ -489,7 +449,6 @@
this.pendingCallbacks = [];
this.serverOps = {};
}
-
Doc.prototype._xf = function(client, server) {
var client_, server_;
if (this.type.transformX) {
@@ -500,7 +459,6 @@
return [client_, server_];
}
};
-
Doc.prototype._otApply = function(docOp, isRemote) {
var oldSnapshot;
oldSnapshot = this.snapshot;
@@ -510,7 +468,6 @@
return this.emit('remoteop', docOp, oldSnapshot);
}
};
-
Doc.prototype._connectionStateChanged = function(state, data) {
switch (state) {
case 'disconnected':
@@ -532,7 +489,6 @@
}
return this.emit(state, data);
};
-
Doc.prototype._setType = function(type) {
var k, v, _ref;
if (typeof type === 'string') {
@@ -553,9 +509,8 @@
return this.provides = {};
}
};
-
Doc.prototype._onMessage = function(msg) {
- var callback, docOp, error, oldInflightOp, op, path, response, undo, value, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
+ var callback, docOp, error, oldInflightOp, op, path, response, undo, value, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
if (msg.open === true) {
this.state = 'open';
this._create = false;
@@ -611,7 +566,7 @@
}
return this._closeCallback = null;
} else if (msg.op === null && error === 'Op already submitted') {
-
+ ;
} else if ((msg.op === void 0 && msg.v !== void 0) || (msg.op && (_ref = msg.meta.source, __indexOf.call(this.inflightSubmittedIds, _ref) >= 0))) {
oldInflightOp = this.inflightOp;
this.inflightOp = null;
@@ -621,15 +576,15 @@
if (this.type.invert) {
undo = this.type.invert(oldInflightOp);
if (this.pendingOp) {
- _ref1 = this._xf(this.pendingOp, undo), this.pendingOp = _ref1[0], undo = _ref1[1];
+ _ref2 = this._xf(this.pendingOp, undo), this.pendingOp = _ref2[0], undo = _ref2[1];
}
this._otApply(undo, true);
} else {
this.emit('error', "Op apply failed (" + error + ") and the op could not be reverted");
}
- _ref2 = this.inflightCallbacks;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- callback = _ref2[_i];
+ _ref3 = this.inflightCallbacks;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ callback = _ref3[_i];
callback(error);
}
} else {
@@ -639,9 +594,9 @@
this.serverOps[this.version] = oldInflightOp;
this.version++;
this.emit('acknowledge', oldInflightOp);
- _ref3 = this.inflightCallbacks;
- for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
- callback = _ref3[_j];
+ _ref4 = this.inflightCallbacks;
+ for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
+ callback = _ref4[_j];
callback(null, oldInflightOp);
}
}
@@ -660,15 +615,15 @@
this.serverOps[this.version] = op;
docOp = op;
if (this.inflightOp !== null) {
- _ref4 = this._xf(this.inflightOp, docOp), this.inflightOp = _ref4[0], docOp = _ref4[1];
+ _ref5 = this._xf(this.inflightOp, docOp), this.inflightOp = _ref5[0], docOp = _ref5[1];
}
if (this.pendingOp !== null) {
- _ref5 = this._xf(this.pendingOp, docOp), this.pendingOp = _ref5[0], docOp = _ref5[1];
+ _ref6 = this._xf(this.pendingOp, docOp), this.pendingOp = _ref6[0], docOp = _ref6[1];
}
this.version++;
return this._otApply(docOp, true);
} else if (msg.meta) {
- _ref6 = msg.meta, path = _ref6.path, value = _ref6.value;
+ _ref7 = msg.meta, path = _ref7.path, value = _ref7.value;
switch (path != null ? path[0] : void 0) {
case 'shout':
return this.emit('shout', value);
@@ -679,7 +634,6 @@
return typeof console !== "undefined" && console !== null ? console.warn('Unhandled document message:', msg) : void 0;
}
};
-
Doc.prototype.flush = function() {
if (!(this.connection.state === 'ok' && this.inflightOp === null && this.pendingOp !== null)) {
return;
@@ -694,7 +648,6 @@
v: this.version
});
};
-
Doc.prototype.submitOp = function(op, callback) {
if (this.type.normalize != null) {
op = this.type.normalize(op);
@@ -711,7 +664,6 @@
this.emit('change', op);
return setTimeout(this.flush, 0);
};
-
Doc.prototype.shout = function(msg) {
return this.connection.send({
doc: this.name,
@@ -721,10 +673,8 @@
}
});
};
-
Doc.prototype.open = function(callback) {
- var message,
- _this = this;
+ var message;
this.autoOpen = true;
if (this.state !== 'closed') {
return;
@@ -747,12 +697,11 @@
}
this.connection.send(message);
this.state = 'opening';
- return this._openCallback = function(error) {
- _this._openCallback = null;
+ return this._openCallback = __bind(function(error) {
+ this._openCallback = null;
return typeof callback === "function" ? callback(error) : void 0;
- };
+ }, this);
};
-
Doc.prototype.close = function(callback) {
this.autoOpen = false;
if (this.state === 'closed') {
@@ -766,19 +715,13 @@
this.emit('closing');
return this._closeCallback = callback;
};
-
return Doc;
-
})();
-
if (typeof WEB === "undefined" || WEB === null) {
MicroEvent = require('./microevent');
}
-
MicroEvent.mixin(Doc);
-
exports.Doc = Doc;
-
if (typeof WEB !== "undefined" && WEB !== null) {
types = exports.types;
BCSocket = window.BCSocket, SockJS = window.SockJS;
@@ -787,61 +730,60 @@
BCSocket = require('browserchannel').BCSocket;
Doc = require('./doc').Doc;
}
-
Connection = (function() {
-
- function Connection(host) {
- var _this = this;
+ function Connection(host, authentication) {
this.docs = {};
this.state = 'connecting';
this.socket = typeof useSockJS !== "undefined" && useSockJS !== null ? new SockJS(host) : new BCSocket(host, {
reconnect: true
});
- this.socket.onmessage = function(msg) {
+ this.socket.send({
+ "auth": authentication ? authentication : null
+ });
+ this.socket.onmessage = __bind(function(msg) {
var docName;
if (typeof useSockJS !== "undefined" && useSockJS !== null) {
msg = JSON.parse(msg.data);
}
if (msg.auth === null) {
- _this.lastError = msg.error;
- _this.disconnect();
- return _this.emit('connect failed', msg.error);
+ this.lastError = msg.error;
+ this.disconnect();
+ return this.emit('connect failed', msg.error);
} else if (msg.auth) {
- _this.id = msg.auth;
- _this.setState('ok');
+ this.id = msg.auth;
+ this.setState('ok');
return;
}
docName = msg.doc;
if (docName !== void 0) {
- _this.lastReceivedDoc = docName;
+ this.lastReceivedDoc = docName;
} else {
- msg.doc = docName = _this.lastReceivedDoc;
+ msg.doc = docName = this.lastReceivedDoc;
}
- if (_this.docs[docName]) {
- return _this.docs[docName]._onMessage(msg);
+ if (this.docs[docName]) {
+ return this.docs[docName]._onMessage(msg);
} else {
return typeof console !== "undefined" && console !== null ? console.error('Unhandled message', msg) : void 0;
}
- };
+ }, this);
this.connected = false;
- this.socket.onclose = function(reason) {
- _this.setState('disconnected', reason);
+ this.socket.onclose = __bind(function(reason) {
+ this.setState('disconnected', reason);
if (reason === 'Closed' || reason === 'Stopped by server') {
- return _this.setState('stopped', _this.lastError || reason);
- }
- };
- this.socket.onerror = function(e) {
- return _this.emit('error', e);
- };
- this.socket.onopen = function() {
- _this.lastError = _this.lastReceivedDoc = _this.lastSentDoc = null;
- return _this.setState('handshaking');
- };
- this.socket.onconnecting = function() {
- return _this.setState('connecting');
- };
+ return this.setState('stopped', this.lastError || reason);
+ }
+ }, this);
+ this.socket.onerror = __bind(function(e) {
+ return this.emit('error', e);
+ }, this);
+ this.socket.onopen = __bind(function() {
+ this.lastError = this.lastReceivedDoc = this.lastSentDoc = null;
+ return this.setState('handshaking');
+ }, this);
+ this.socket.onconnecting = __bind(function() {
+ return this.setState('connecting');
+ }, this);
}
-
Connection.prototype.setState = function(state, data) {
var doc, docName, _ref, _results;
if (this.state === state) {
@@ -860,7 +802,6 @@
}
return _results;
};
-
Connection.prototype.send = function(data) {
var docName;
docName = data.doc;
@@ -874,27 +815,23 @@
}
return this.socket.send(data);
};
-
Connection.prototype.disconnect = function() {
return this.socket.close();
};
-
Connection.prototype.makeDoc = function(name, data, callback) {
- var doc,
- _this = this;
+ var doc;
if (this.docs[name]) {
throw new Error("Doc " + name + " already open");
}
doc = new Doc(this, name, data);
this.docs[name] = doc;
- return doc.open(function(error) {
+ return doc.open(__bind(function(error) {
if (error) {
- delete _this.docs[name];
+ delete this.docs[name];
}
return callback(error, (!error ? doc : void 0));
- });
+ }, this));
};
-
Connection.prototype.openExisting = function(docName, callback) {
var doc;
if (this.state === 'stopped') {
@@ -905,7 +842,6 @@
}
return doc = this.makeDoc(docName, {}, callback);
};
-
Connection.prototype.open = function(docName, type, callback) {
var doc;
if (this.state === 'stopped') {
@@ -945,19 +881,13 @@
type: type.name
}, callback);
};
-
return Connection;
-
})();
-
if (typeof WEB === "undefined" || WEB === null) {
MicroEvent = require('./microevent');
}
-
MicroEvent.mixin(Connection);
-
exports.Connection = Connection;
-
if (typeof WEB !== "undefined" && WEB !== null) {
hasBCSocket = window.BCSocket !== void 0;
hasSockJS = window.SockJS !== void 0;
@@ -970,21 +900,22 @@
} else {
Connection = require('./connection').Connection;
}
-
exports.open = (function() {
var connections, getConnection, maybeClose;
connections = {};
- getConnection = function(origin) {
+ getConnection = function(origin, authentication) {
var c, del, location, path;
if (typeof WEB !== "undefined" && WEB !== null) {
location = window.location;
path = useSockJS ? 'sockjs' : 'channel';
- if (origin == null) {
+ if (origin != null) {
+ origin;
+ } else {
origin = "" + location.protocol + "//" + location.host + "/" + path;
- }
+ };
}
if (!connections[origin]) {
- c = new Connection(origin);
+ c = new Connection(origin, authentication);
del = function() {
return delete connections[origin];
};
@@ -1008,13 +939,15 @@
return c.disconnect();
}
};
- return function(docName, type, origin, callback) {
- var c;
- if (typeof origin === 'function') {
- callback = origin;
- origin = null;
- }
- c = getConnection(origin);
+ return function(docName, type, options, callback) {
+ var authentication, c, origin;
+ if (typeof options === 'function') {
+ callback = options;
+ options = {};
+ }
+ origin = options.origin;
+ authentication = options.authentication;
+ c = getConnection(origin, authentication);
c.numDocs++;
c.open(docName, type, function(error, doc) {
if (error) {
@@ -1031,10 +964,8 @@
return c;
};
})();
-
if (typeof WEB === "undefined" || WEB === null) {
exports.Doc = require('./doc').Doc;
exports.Connection = require('./connection').Connection;
}
-
}).call(this);
View
2  webclient/text-tp2.js
@@ -1 +1 @@
-(function(){var e,t,n,r,i,s,o,u=!0,a=window.sharejs,f={name:"text-tp2",tp2:!0,create:function(){return{charLength:0,totalLength:0,positionCache:[],data:[]}},serialize:function(e){if(!e.data)throw new Error("invalid doc snapshot");return e.data},deserialize:function(e){var t,n,r,i=f.create();i.data=e;for(n=0,r=e.length;n<r;n++)t=e[n],typeof t=="string"?(i.charLength+=t.length,i.totalLength+=t.length):i.totalLength+=t;return i}},l=function(e){var t,n,r,i,s;if(!Array.isArray(e))throw new Error("Op must be an array of components");n=null,s=[];for(r=0,i=e.length;r<i;r++){t=e[r];if(typeof t=="object")if(t.i!==void 0){if(!(typeof t.i=="string"&&t.i.length>0||typeof t.i=="number"&&t.i>0))throw new Error("Inserts must insert a string or a +ive number")}else{if(t.d===void 0)throw new Error("Operation component must define .i or .d");if(!(typeof t.d=="number"&&t.d>0))throw new Error("Deletes must be a +ive number")}else{if(typeof t!="number")throw new Error("Op components must be objects or numbers");if(!(t>0))throw new Error("Skip components must be a positive number");if(typeof n=="number")throw new Error("Adjacent skip components should be combined")}s.push(n=t)}return s};f._takeDoc=s=function(e,t,n,r){var i,s,o;if(t.index>=e.data.length)throw new Error("Operation goes past the end of the document");return i=e.data[t.index],s=typeof i=="string"?n!==void 0?i.slice(t.offset,t.offset+n):i.slice(t.offset):n===void 0||r?i-t.offset:Math.min(n,i-t.offset),o=s.length||s,(i.length||i)-t.offset>o?t.offset+=o:(t.index++,t.offset=0),s},f._appendDoc=t=function(e,t){var n;if(t===0||t==="")return;typeof t=="string"?(e.charLength+=t.length,e.totalLength+=t.length):e.totalLength+=t,n=e.data,n.length===0?n.push(t):typeof n[n.length-1]==typeof t?n[n.length-1]+=t:n.push(t)},f.apply=function(e,n){var r,i,o,u,a,c,h;if(e.totalLength===void 0||e.charLength===void 0||e.data.length===void 0)throw new Error("Snapshot is invalid");l(n),i=f.create(),u={index:0,offset:0};for(c=0,h=n.length;c<h;c++){r=n[c];if(typeof r=="number"){a=r;while(a>0)o=s(e,u,a),t(i,o),a-=o.length||o}else if(r.i!==void 0)t(i,r.i);else if(r.d!==void 0){a=r.d;while(a>0)o=s(e,u,a),a-=o.length||o;t(i,r.d)}}return i},f._append=e=function(e,t){var n;if(t!==0&&t.i!==""&&t.i!==0&&t.d!==0)return e.length===0?e.push(t):(n=e[e.length-1],typeof t=="number"&&typeof n=="number"?e[e.length-1]+=t:t.i!==void 0&&n.i!=null&&typeof n.i==typeof t.i?n.i+=t.i:t.d!==void 0&&n.d!=null?n.d+=t.d:e.push(t))},i=function(e){var t=0,n=0,r=function(r,i){var s,o,u,a;return t===e.length?null:(u=e[t],typeof (o=u)=="number"||typeof (o=u.i)=="number"||(o=u.d)!==void 0?(r==null||o-n<=r||i&&u.i!==void 0?(s=o-n,++t,n=0):(n+=r,s=r),u.i!==void 0?{i:s}:u.d!==void 0?{d:s}:s):(r==null||u.i.length-n<=r||i?(a={i:u.i.slice(n)},++t,n=0):(a={i:u.i.slice(n,n+r)},n+=r),a))},i=function(){return e[t]};return[r,i]},r=function(e){return typeof e=="number"?e:typeof e.i=="string"?e.i.length:e.d||e.i},f.normalize=function(t){var n,r,i,s=[];for(r=0,i=t.length;r<i;r++)n=t[r],e(s,n);return s},o=function(t,n,s,o){var u,a,f,c,h,p,d,v,m,g;l(t),l(n),c=[],m=i(t),p=m[0],h=m[1];for(d=0,v=n.length;d<v;d++){a=n[d],f=r(a);if(a.i!==void 0)if(s){if(o==="left")while(((g=h())!=null?g.i:void 0)!==void 0)e(c,p());e(c,f)}else while(f>0){u=p(f,!0);if(u===null)throw new Error("The transformed op is invalid");if(u.d!==void 0)throw new Error("The transformed op deletes locally inserted characters - it cannot be purged of the insert.");typeof u=="number"?f-=u:e(c,u)}else while(f>0){u=p(f,!0);if(u===null)throw new Error("The op traverses more elements than the document has");e(c,u),u.i||(f-=r(u))}}while(a=p()){if(a.i===void 0)throw new Error("Remaining fragments in the op: "+a);e(c,a)}return c},f.transform=function(e,t,n){if(n!=="left"&&n!=="right")throw new Error("side ("+n+") should be 'left' or 'right'");return o(e,t,!0,n)},f.prune=function(e,t){return o(e,t,!1)},f.compose=function(t,n){var s,o,u,a,f,c,h,p,d,v;if(t===null||t===void 0)return n;l(t),l(n),f=[],v=i(t),c=v[0],h=v[1];for(p=0,d=n.length;p<d;p++){u=n[p];if(typeof u=="number"){a=u;while(a>0){s=c(a);if(s===null)throw new Error("The op traverses more elements than the document has");e(f,s),a-=r(s)}}else if(u.i!==void 0)e(f,{i:u.i});else{a=u.d;while(a>0){s=c(a);if(s===null)throw new Error("The op traverses more elements than the document has");o=r(s),s.i!==void 0?e(f,{i:o}):e(f,{d:o}),a-=o}}}while(u=c()){if(u.i===void 0)throw new Error("Remaining fragments in op1: "+u);e(f,u)}return f},typeof u!="undefined"&&u!==null?a.types["text-tp2"]=f:module.exports=f,typeof u!="undefined"&&u!==null?f=a.types["text-tp2"]:f=require("./text-tp2"),s=f._takeDoc,e=f._append,n=function(t,n,r,i){var o,u=[];while((i===void 0||i>0)&&r.index<n.data.length)o=s(n,r,i,!0),i!==void 0&&typeof o=="string"&&(i-=o.length),u.push(e(t,o.length||o));return u},f.api={provides:{text:!0},getLength:function(){return this.snapshot.charLength},getText:function(){var e,t=function(){var t,n,r=this.snapshot.data,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],typeof e=="string"&&i.push(e);return i}.call(this);return t.join("")},insert:function(t,r,i){var s,o;return t===void 0&&(t=0),o=[],s={index:0,offset:0},n(o,this.snapshot,s,t),e(o,{i:r}),n(o,this.snapshot,s),this.submitOp(o,i),o},del:function(t,r,i){var o,u=[],a={index:0,offset:0};n(u,this.snapshot,a,t);while(r>0)o=s(this.snapshot,a,r,!0),typeof o=="string"?(e(u,{d:o.length}),r-=o.length):e(u,o);return n(u,this.snapshot,a),this.submitOp(u,i),u},_register:function(){return this.on("remoteop",function(e,t){var n,r,i,o,u,a=0,f={index:0,offset:0};for(o=0,u=e.length;o<u;o++){n=e[o];if(typeof n=="number"){i=n;while(i>0)r=s(t,f,i),typeof r=="string"&&(a+=r.length),i-=r.length||r}else if(n.i!==void 0)typeof n.i=="string"&&(this.emit("insert",a,n.i),a+=n.i.length);else{i=n.d;while(i>0)r=s(t,f,i),typeof r=="string"&&this.emit("delete",a,r),i-=r.length||r}}})}}}).call(this)
+(function(){var a,b,c,d,e,f,g,h=!0,i=window.sharejs,j={name:"text-tp2",tp2:!0,create:function(){return{charLength:0,totalLength:0,positionCache:[],data:[]}},serialize:function(a){if(!a.data)throw new Error("invalid doc snapshot");return a.data},deserialize:function(a){var b,c,d,e=j.create();e.data=a;for(c=0,d=a.length;c<d;c++)b=a[c],typeof b=="string"?(e.charLength+=b.length,e.totalLength+=b.length):e.totalLength+=b;return e}},k=function(a){var b,c,d,e,f;if(!Array.isArray(a))throw new Error("Op must be an array of components");c=null,f=[];for(d=0,e=a.length;d<e;d++){b=a[d];if(typeof b=="object")if(b.i!==void 0){if(!(typeof b.i=="string"&&b.i.length>0||typeof b.i=="number"&&b.i>0))throw new Error("Inserts must insert a string or a +ive number")}else{if(b.d===void 0)throw new Error("Operation component must define .i or .d");if(!(typeof b.d=="number"&&b.d>0))throw new Error("Deletes must be a +ive number")}else{if(typeof b!="number")throw new Error("Op components must be objects or numbers");if(!(b>0))throw new Error("Skip components must be a positive number");if(typeof c=="number")throw new Error("Adjacent skip components should be combined")}f.push(c=b)}return f};j._takeDoc=f=function(a,b,c,d){var e,f,g;if(b.index>=a.data.length)throw new Error("Operation goes past the end of the document");return e=a.data[b.index],f=typeof e=="string"?c!==void 0?e.slice(b.offset,b.offset+c):e.slice(b.offset):c===void 0||d?e-b.offset:Math.min(c,e-b.offset),g=f.length||f,(e.length||e)-b.offset>g?b.offset+=g:(b.index++,b.offset=0),f},j._appendDoc=b=function(a,b){var c;if(b===0||b==="")return;typeof b=="string"?(a.charLength+=b.length,a.totalLength+=b.length):a.totalLength+=b,c=a.data,c.length===0?c.push(b):typeof c[c.length-1]==typeof b?c[c.length-1]+=b:c.push(b)},j.apply=function(a,c){var d,e,g,h,i,l,m;if(a.totalLength===void 0||a.charLength===void 0||a.data.length===void 0)throw new Error("Snapshot is invalid");k(c),e=j.create(),h={index:0,offset:0};for(l=0,m=c.length;l<m;l++){d=c[l];if(typeof d=="number"){i=d;while(i>0)g=f(a,h,i),b(e,g),i-=g.length||g}else if(d.i!==void 0)b(e,d.i);else if(d.d!==void 0){i=d.d;while(i>0)g=f(a,h,i),i-=g.length||g;b(e,d.d)}}return e},j._append=a=function(a,b){var c;if(b!==0&&b.i!==""&&b.i!==0&&b.d!==0)return a.length===0?a.push(b):(c=a[a.length-1],typeof b=="number"&&typeof c=="number"?a[a.length-1]+=b:b.i!==void 0&&c.i!=null&&typeof c.i==typeof b.i?c.i+=b.i:b.d!==void 0&&c.d!=null?c.d+=b.d:a.push(b))},e=function(a){var b=0,c=0,d=function(d,e){var f,g,h,i;return b===a.length?null:(h=a[b],typeof (g=h)=="number"||typeof (g=h.i)=="number"||(g=h.d)!==void 0?(d==null||g-c<=d||e&&h.i!==void 0?(f=g-c,++b,c=0):(c+=d,f=d),h.i!==void 0?{i:f}:h.d!==void 0?{d:f}:f):(d==null||h.i.length-c<=d||e?(i={i:h.i.slice(c)},++b,c=0):(i={i:h.i.slice(c,c+d)},c+=d),i))},e=function(){return a[b]};return[d,e]},d=function(a){return typeof a=="number"?a:typeof a.i=="string"?a.i.length:a.d||a.i},j.normalize=function(b){var c,d,e,f=[];for(d=0,e=b.length;d<e;d++)c=b[d],a(f,c);return f},g=function(b,c,f,g){var h,i,j,l,m,n,o,p,q,r;k(b),k(c),l=[],q=e(b),n=q[0],m=q[1];for(o=0,p=c.length;o<p;o++){i=c[o],j=d(i);if(i.i!==void 0)if(f){if(g==="left")while(((r=m())!=null?r.i:void 0)!==void 0)a(l,n());a(l,j)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The transformed op is invalid");if(h.d!==void 0)throw new Error("The transformed op deletes locally inserted characters - it cannot be purged of the insert.");typeof h=="number"?j-=h:a(l,h)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The op traverses more elements than the document has");a(l,h),h.i||(j-=d(h))}}while(i=n()){if(i.i===void 0)throw new Error("Remaining fragments in the op: "+i);a(l,i)}return l},j.transform=function(a,b,c){if(c!=="left"&&c!=="right")throw new Error("side ("+c+") should be 'left' or 'right'");return g(a,b,!0,c)},j.prune=function(a,b){return g(a,b,!1)},j.compose=function(b,c){var f,g,h,i,j,l,m,n,o,p;if(b===null||b===void 0)return c;k(b),k(c),j=[],p=e(b),l=p[0],m=p[1];for(n=0,o=c.length;n<o;n++){h=c[n];if(typeof h=="number"){i=h;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");a(j,f),i-=d(f)}}else if(h.i!==void 0)a(j,{i:h.i});else{i=h.d;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");g=d(f),f.i!==void 0?a(j,{i:g}):a(j,{d:g}),i-=g}}}while(h=l()){if(h.i===void 0)throw new Error("Remaining fragments in op1: "+h);a(j,h)}return j},typeof h!="undefined"&&h!==null?i.types["text-tp2"]=j:module.exports=j,typeof h!="undefined"&&h!==null?j=i.types["text-tp2"]:j=require("./text-tp2"),f=j._takeDoc,a=j._append,c=function(b,c,d,e){var g,h=[];while((e===void 0||e>0)&&d.index<c.data.length)g=f(c,d,e,!0),e!==void 0&&typeof g=="string"&&(e-=g.length),h.push(a(b,g.length||g));return h},j.api={provides:{text:!0},getLength:function(){return this.snapshot.charLength},getText:function(){var a,b=function(){var b,c,d=this.snapshot.data,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],typeof a=="string"&&e.push(a);return e}.call(this);return b.join("")},insert:function(b,d,e){var f,g;return b===void 0&&(b=0),g=[],f={index:0,offset:0},c(g,this.snapshot,f,b),a(g,{i:d}),c(g,this.snapshot,f),this.submitOp(g,e),g},del:function(b,d,e){var g,h=[],i={index:0,offset:0};c(h,this.snapshot,i,b);while(d>0)g=f(this.snapshot,i,d,!0),typeof g=="string"?(a(h,{d:g.length}),d-=g.length):a(h,g);return c(h,this.snapshot,i),this.submitOp(h,e),h},_register:function(){return this.on("remoteop",function(a,b){var c,d,e,g,h,i=0,j={index:0,offset:0};for(g=0,h=a.length;g<h;g++){c=a[g];if(typeof c=="number"){e=c;while(e>0)d=f(b,j,e),typeof d=="string"&&(i+=d.length),e-=d.length||d}else if(c.i!==void 0)typeof c.i=="string"&&(this.emit("insert",i,c.i),i+=c.i.length);else{e=c.d;while(e>0)d=f(b,j,e),typeof d=="string"&&this.emit("delete",i,d),e-=d.length||d}}})}}}).call(this)
View
31 webclient/text-tp2.uncompressed.js
@@ -1,16 +1,11 @@
-// Generated by CoffeeScript 1.3.3
(function() {
/**
@const
@type {boolean}
*/
var WEB = true;
-;
-
- var append, appendDoc, appendSkipChars, checkOp, componentLength, exports, makeTake, takeDoc, transformer, type;
-
+; var append, appendDoc, appendSkipChars, checkOp, componentLength, exports, makeTake, takeDoc, transformer, type;
exports = window['sharejs'];
-
type = {
name: 'text-tp2',
tp2: true,
@@ -44,7 +39,6 @@ var WEB = true;
return doc;
}
};
-
checkOp = function(op) {
var c, last, _i, _len, _results;
if (!Array.isArray(op)) {
@@ -81,7 +75,6 @@ var WEB = true;
}
return _results;
};
-
type._takeDoc = takeDoc = function(doc, position, maxlength, tombsIndivisible) {
var part, result, resultLen;
if (position.index >= doc.data.length) {
@@ -98,7 +91,6 @@ var WEB = true;
}
return result;
};
-
type._appendDoc = appendDoc = function(doc, p) {
var data;
if (p === 0 || p === '') {
@@ -119,7 +111,6 @@ var WEB = true;
data.push(p);
}
};
-
type.apply = function(doc, op) {
var component, newDoc, part, position, remainder, _i, _len;
if (!(doc.totalLength !== void 0 && doc.charLength !== void 0 && doc.data.length !== void 0)) {
@@ -153,11 +144,10 @@ var WEB = true;
}
return newDoc;
};
-
type._append = append = function(op, component) {
var last;
if (component === 0 || component.i === '' || component.i === 0 || component.d === 0) {
-
+ ;
} else if (op.length === 0) {
return op.push(component);
} else {
@@ -173,7 +163,6 @@ var WEB = true;
}
}
};
-
makeTake = function(op) {
var index, offset, peekType, take;
index = 0;
@@ -225,7 +214,6 @@ var WEB = true;
};
return [take, peekType];
};
-
componentLength = function(component) {
if (typeof component === 'number') {
return component;
@@ -235,7 +223,6 @@ var WEB = true;
return component.d || component.i;
}
};
-
type.normalize = function(op) {
var component, newOp, _i, _len;
newOp = [];
@@ -245,9 +232,8 @@ var WEB = true;
}
return newOp;
};
-
transformer = function(op, otherOp, goForwards, side) {
- var chunk, component, length, newOp, peek, take, _i, _len, _ref, _ref1;
+ var chunk, component, length, newOp, peek, take, _i, _len, _ref, _ref2;
checkOp(op);
checkOp(otherOp);
newOp = [];
@@ -258,7 +244,7 @@ var WEB = true;
if (component.i !== void 0) {
if (goForwards) {
if (side === 'left') {
- while (((_ref1 = peek()) != null ? _ref1.i : void 0) !== void 0) {
+ while (((_ref2 = peek()) != null ? _ref2.i : void 0) !== void 0) {
append(newOp, take());
}
}
@@ -300,18 +286,15 @@ var WEB = true;
}
return newOp;
};
-
type.transform = function(op, otherOp, side) {
if (!(side === 'left' || side === 'right')) {
throw new Error("side (" + side + ") should be 'left' or 'right'");
}
return transformer(op, otherOp, true, side);
};
-
type.prune = function(op, otherOp) {
return transformer(op, otherOp, false);
};
-
type.compose = function(op1, op2) {
var chunk, chunkLength, component, length, result, take, _, _i, _len, _ref;
if (op1 === null || op1 === void 0) {
@@ -366,21 +349,17 @@ var WEB = true;
}
return result;
};
-
if (typeof WEB !== "undefined" && WEB !== null) {
exports.types['text-tp2'] = type;
} else {
module.exports = type;
}
-
if (typeof WEB !== "undefined" && WEB !== null) {
type = exports.types['text-tp2'];
} else {
type = require('./text-tp2');
}
-
takeDoc = type._takeDoc, append = type._append;
-
appendSkipChars = function(op, doc, pos, maxlength) {
var part, _results;
_results = [];
@@ -393,7 +372,6 @@ var WEB = true;
}
return _results;
};
-
type['api'] = {
'provides': {
'text': true
@@ -496,5 +474,4 @@ var WEB = true;
});
}
};
-
}).call(this);
View
10 webclient/textarea.js
@@ -1,7 +1,5 @@
-// Generated by CoffeeScript 1.3.3
(function() {
var applyChange;
-
applyChange = function(doc, oldval, newval) {
var commonEnd, commonStart;
if (oldval === newval) {
@@ -22,7 +20,6 @@
return doc.insert(commonStart, newval.slice(commonStart, newval.length - commonEnd));
}
};
-
window.sharejs.extendDoc('attach_textarea', function(elem) {
var doc, event, genOp, prevvalue, replaceText, _i, _len, _ref, _results;
doc = this;
@@ -78,13 +75,8 @@
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
- if (elem.addEventListener) {
- _results.push(elem.addEventListener(event, genOp, false));
- } else {
- _results.push(elem.attachEvent('on' + event, genOp));
- }
+ _results.push(elem.addEventListener ? elem.addEventListener(event, genOp, false) : elem.attachEvent('on' + event, genOp));
}
return _results;
});
-
}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.