This commit is contained in:
Kevin Jahns 2014-09-29 15:28:44 +02:00
parent 631bf47a96
commit 5cb7951d44
50 changed files with 382 additions and 163 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
!function n(e,t,r){function o(u,s){if(!t[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=t[u]={exports:{}};e[u][0].call(a.exports,function(n){var t=e[u][1][n];return o(t?t:n)},a,a.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e){var t;t=function(){var n,e,t;return t=null,2===arguments.length?(t=new Peer(arguments[0]),e=arguments[1]):(t=new Peer(arguments[0],arguments[1]),t.on("error",function(n){throw new Error("Peerjs connector: "+n)}),t.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),e=arguments[2]),n=function(){function n(n,e,r,o){var i,u;this.engine=n,this.HB=e,this.execution_listener=r,this.yatta=o,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return n.addConnection(e)}}(this)),u=function(n){return function(){var e,t,r,o;r=n.connections,o=[];for(t in r)e=r[t],o.push(e.send({sync_state_vector:n.HB.getOperationCounter()}));return o}}(this),setInterval(u,4e3),i=function(n){return function(e){var t,r,o,i;if(e.uid.creator===n.HB.getUserId()&&"string"!=typeof e.uid.op_number){o=n.connections,i=[];for(r in o)t=o[r],i.push(t.send({op:e}));return i}}}(this),this.execution_listener.push(i)}return n.prototype.connectToPeer=function(n){return null==this.connections[n]&&n!==this.yatta.getUserId()?this.addConnection(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e,t,r;return this.connections[n.peer]=n,t=!1,e=!1,n.on("data",function(r){return function(o){var i,u,s,c,a;if("empty_message"===o);else if(null!=o.HB){if(t=!0,r.engine.applyOpsCheckDouble(o.HB),!o.initialized)return n.send({conns:r.getAllConnectionIds()})}else{if(null!=o.op)return r.engine.applyOp(o.op);if(null!=o.conns){for(c=o.conns,a=[],u=0,s=c.length;s>u;u++)i=c[u],a.push(r.connectToPeer(i));return a}if(null!=o.sync_state_vector)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.sync_state_vector),initialized:!0});if(null==o.state_vector)throw new Error("Can't parse this operation "+o);if(!e)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.state_vector),initialized:!1}),e=!0}}}(this)),r=function(e){return function(){return n.send({state_vector:e.HB.getOperationCounter()}),t?void 0:setTimeout(r,100)}}(this),r()},n}(),t.on("open",function(t){return e(n,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[1]);
!function n(e,t,r){function o(u,s){if(!t[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=t[u]={exports:{}};e[u][0].call(a.exports,function(n){var t=e[u][1][n];return o(t?t:n)},a,a.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e){var t;t=function(){var n,e,t;return t=null,2===arguments.length?(t=new Peer(arguments[0]),e=arguments[1]):(t=new Peer(arguments[0],arguments[1]),t.on("error",function(n){throw new Error("Peerjs connector: "+n)}),t.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),e=arguments[2]),n=function(){function n(n,e,r,o){var i,u;this.engine=n,this.HB=e,this.execution_listener=r,this.yatta=o,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return n.addConnection(e)}}(this)),u=function(n){return function(){var e,t,r,o;r=n.connections,o=[];for(t in r)e=r[t],o.push(e.send({sync_state_vector:n.HB.getOperationCounter()}));return o}}(this),setInterval(u,4e3),i=function(n){return function(e){var t,r,o,i;if(e.uid.creator===n.HB.getUserId()&&"string"!=typeof e.uid.op_number){o=n.connections,i=[];for(r in o)t=o[r],i.push(t.send({op:e}));return i}}}(this),this.execution_listener.push(i)}return n.prototype.connectToPeer=function(n){return null==this.connections[n]&&n!==this.yatta.getUserId()?this.addConnection(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e,t,r;return this.connections[n.peer]=n,t=!1,e=!1,n.on("data",function(r){return function(o){var i,u,s,c,a;if("empty_message"===o);else if(null!=o.HB){if(t=!0,r.engine.applyOpsCheckDouble(o.HB),!o.initialized)return n.send({conns:r.getAllConnectionIds()})}else{if(null!=o.op)return r.engine.applyOp(o.op);if(null!=o.conns){for(c=o.conns,a=[],u=0,s=c.length;s>u;u++)i=c[u],a.push(r.connectToPeer(i));return a}if(null!=o.sync_state_vector)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.sync_state_vector),initialized:!0});if(null==o.state_vector)throw new Error("Can't parse this operation: "+o);if(!e)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.state_vector),initialized:!1}),e=!0}}}(this)),r=function(e){return function(){return n.send({state_vector:e.HB.getOperationCounter()}),t?void 0:setTimeout(r,100)}}(this),r()},n}(),t.on("open",function(t){return e(n,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[1]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -122,7 +122,7 @@
return initialized_him = true;
}
} else {
throw new Error("Can't parse this operation " + data);
throw new Error("Can't parse this operation: " + data);
}
};
})(this));

File diff suppressed because one or more lines are too long

View File

@ -51,8 +51,9 @@
return this.getSharedObject().toJson();
};
JsonFramework.prototype.val = function(name, content, mutable) {
return this.getSharedObject().val(name, content, mutable);
JsonFramework.prototype.val = function() {
var _ref;
return (_ref = this.getSharedObject()).val.apply(_ref, arguments);
};
JsonFramework.prototype.on = function() {

File diff suppressed because one or more lines are too long

View File

@ -142,7 +142,7 @@
HB.addOperation(json).execute();
this.replace_manager.replace(json);
return this;
} else if ((name != null) && ((content != null) || content === null)) {
} else if ((name != null) && arguments.length > 1) {
if (mutable != null) {
if (mutable === true || mutable === 'mutable') {
mutable = true;
@ -154,7 +154,7 @@
}
if (typeof content === 'function') {
return this;
} else if (content === null || (((!mutable) || typeof content === 'number') && content.constructor !== Object)) {
} else if ((content == null) || (((!mutable) || typeof content === 'number') && content.constructor !== Object)) {
obj = HB.addOperation(new types.ImmutableObject(void 0, content)).execute();
return JsonType.__super__.val.call(this, name, obj);
} else {

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,11 @@
__extends(TextInsert, _super);
function TextInsert(content, uid, prev, next, origin) {
this.content = content;
if ((content != null ? content.creator : void 0) != null) {
this.saveOperation('content', content);
} else {
this.content = content;
}
if (!((prev != null) && (next != null))) {
throw new Error("You must define prev, and next for TextInsert-types!");
}
@ -56,14 +60,18 @@
};
TextInsert.prototype._encode = function() {
var json;
var json, _ref;
json = {
'type': "TextInsert",
'content': this.content,
'uid': this.getUid(),
'prev': this.prev_cl.getUid(),
'next': this.next_cl.getUid()
};
if (((_ref = this.content) != null ? _ref.getUid : void 0) != null) {
json['content'] = this.content.getUid();
} else {
json['content'] = this.content;
}
if (this.origin !== this.prev_cl) {
json["origin"] = this.origin.getUid();
}

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,27 @@
(function() {
var json_types_uninitialized,
var json_types_uninitialized, proxy_token,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
json_types_uninitialized = require("./JsonTypes");
proxy_token = false;
if (typeof Element !== "undefined" && Element !== null) {
Element.prototype._proxy = function(f_name, f) {
var old_f;
old_f = this[f_name];
if (old_f != null) {
return this[f_name] = function() {
f.apply(this, arguments);
return old_f.apply(this, arguments);
if (!proxy_token) {
proxy_token = true;
old_f.apply(this, arguments);
f.apply(this, arguments);
return proxy_token = false;
} else {
return old_f.apply(this, arguments);
}
};
} else {
return this[f_name] = f;
}
};
}
@ -95,8 +101,10 @@
};
XmlType.prototype.setXmlProxy = function() {
var insertBefore, that;
this.xml._yatta = this;
return this.xml._proxy('insertBefore', function(insertedNode, adjacentNode) {
that = this;
insertBefore = function(insertedNode, adjacentNode) {
var element, next, prev;
next = adjacentNode != null ? adjacentNode._yatta : void 0;
prev = null;
@ -105,10 +113,16 @@
} else {
prev = this._yatta.elements.end.prev_cl;
}
element = new XmlType(void 0, void 0, void 0, void 0);
element = new XmlType(void 0, void 0, void 0, void 0, insertedNode);
HB.addOperation(element).execute();
return this.elements.insertAfter(prev, element);
return that.elements.insertAfter(prev, element);
};
this.xml._proxy('insertBefore', insertBefore);
this.xml._proxy('appendChild', insertBefore);
this.xml._proxy('removeAttribute', function(name) {
return that.attributes.val(name, void 0);
});
return this.xml._proxy('removeChild', function(node) {});
};
XmlType.prototype.val = function(enforce) {
@ -122,9 +136,11 @@
attr = this.attributes.val();
for (attr_name in attr) {
value = attr[attr_name];
a = document.createAttribute(attr_name);
a.value = value;
this.xml.setAttributeNode(a);
if (value != null) {
a = document.createAttribute(attr_name);
a.value = value;
this.xml.setAttributeNode(a);
}
}
e = this.elements.beginning.next_cl;
while (e.type !== "Delimiter") {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@
</head>
<body>
<div id="mocha"></div>
<div id="test_dom"><p>This is a test object for <b>XmlFramework</b></p></div>
<div id="test_dom" test_attribute="the test"><p id="removeme">remove me</p><p>This is a test object for <b>XmlFramework</b></p></div>
<script src="../../node_modules/mocha/mocha.js" class="awesome"></script>
<script>
mocha.setup('bdd');

View File

@ -271,7 +271,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -302,7 +302,7 @@ data from the received intent.</p>
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -120,7 +120,7 @@ Known values that are supported:</p><ul>
<a href='#val-dynamic'>
#
(void)
<b>val</b><span>(name, content, mutable)</span>
<b>val</b><span>()</span>
</a>
</span>
<span class='desc'>
@ -288,7 +288,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
<p class='signature' id='val-dynamic'>
#
(void)
<b>val</b><span>(name, content, mutable)</span>
<b>val</b><span>()</span>
<br>
</p>
<div class='tags'>
@ -335,7 +335,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -466,7 +466,7 @@ if (x.type === &quot;JsonType&quot;) {
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -139,7 +139,7 @@ console.log(w.newProperty == &quot;Awesome&quot;) # true!</code></pre>
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -222,7 +222,7 @@ on how to do that with urls.</p>
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -356,7 +356,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -455,7 +455,7 @@ yatta.bind(textbox);</code></pre>
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -41,7 +41,13 @@
</table>
<h2>Overview</h2>
<div class='docstring'>
<p>Manages XML types</p>
<p>Manages XML types
Not supported:</p><ul>
<li>Attribute nodes</li>
<li>Real replace of child elements (to much overhead). Currently, the new element is inserted after the &#39;replaced&#39; element, and then it is deleted.
*</li>
</ul>
</div>
<div class='tags'>
</div>
@ -252,7 +258,7 @@ This result can be send to other clients.</p>
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -38,7 +38,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -70,7 +70,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
<ul>
<li>XML support</li>
</ul>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#x6d;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#x6b;&#x65;&#118;&#x69;&#x6e;&#46;&#106;&#97;&#x68;&#110;&#115;&#x40;&#114;&#119;&#x74;&#104;&#45;&#97;&#97;&#x63;&#x68;&#101;&#110;&#46;&#x64;&#x65;">&#x6b;&#x65;&#118;&#x69;&#x6e;&#46;&#106;&#97;&#x68;&#110;&#115;&#x40;&#114;&#119;&#x74;&#104;&#45;&#97;&#97;&#x63;&#x68;&#101;&#110;&#46;&#x64;&#x65;</a>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#x6d;&#x61;&#x69;&#108;&#116;&#111;&#58;&#x6b;&#x65;&#118;&#x69;&#x6e;&#x2e;&#106;&#x61;&#x68;&#110;&#x73;&#x40;&#114;&#119;&#116;&#104;&#x2d;&#x61;&#x61;&#99;&#104;&#x65;&#110;&#x2e;&#x64;&#101;">&#x6b;&#x65;&#118;&#x69;&#x6e;&#x2e;&#106;&#x61;&#x68;&#110;&#x73;&#x40;&#114;&#119;&#116;&#104;&#x2d;&#x61;&#x61;&#99;&#104;&#x65;&#110;&#x2e;&#x64;&#101;</a>
@ -79,7 +79,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -100,7 +100,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -158,7 +158,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -37,6 +37,23 @@
<td>lib&#47;Types</td>
</tr>
</table>
<h2>Variables Summary</h2>
<dl class='constants'>
<dt id='proxy_token-variable'>
proxy_token
=
</dt>
<dd>
<pre><code class='coffeescript'>false</code></pre>
<div class='docstring'>
<p>some dom implementations may call another dom.method that simulates the behavior of another.
For example xml.insertChild(dom) , wich inserts an element at the end, and xml.insertAfter(dom,null) wich does the same
But yatta&#39;s proxy may be called only once!</p>
</div>
<div class='tags'>
</div>
</dd>
</dl>
<h2>Method Summary</h2>
<ul class='summary'>
<li>
@ -65,7 +82,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -37,7 +37,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 12:25:30 by
September 29, 14 15:28:15 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -76,8 +76,8 @@ class JsonFramework
#
# @see JsonType.val
#
val : (name, content, mutable)->
@getSharedObject().val(name, content, mutable)
val : ()->
@getSharedObject().val arguments...
#
# @see Operation.on

View File

@ -207,7 +207,7 @@ module.exports = (HB)->
HB.addOperation(json).execute()
@replace_manager.replace json
@
else if name? and (content? or content is null)
else if name? and arguments.length > 1
if mutable?
if mutable is true or mutable is 'mutable'
mutable = true
@ -217,7 +217,7 @@ module.exports = (HB)->
mutable = @mutable_default
if typeof content is 'function'
@ # Just do nothing
else if content is null or (((not mutable) or typeof content is 'number') and content.constructor isnt Object)
else if (not content?) or (((not mutable) or typeof content is 'number') and content.constructor isnt Object)
obj = HB.addOperation(new types.ImmutableObject undefined, content).execute()
super name, obj
else

View File

@ -22,7 +22,11 @@ module.exports = (HB)->
# @param {String} content The content of this Insert-type Operation. Usually you restrict the length of content to size 1
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
#
constructor: (@content, uid, prev, next, origin)->
constructor: (content, uid, prev, next, origin)->
if content?.creator?
@saveOperation 'content', content
else
@content = content
if not (prev? and next?)
throw new Error "You must define prev, and next for TextInsert-types!"
super uid, prev, next, origin
@ -61,11 +65,14 @@ module.exports = (HB)->
json =
{
'type': "TextInsert"
'content': @content
'uid' : @getUid()
'prev': @prev_cl.getUid()
'next': @next_cl.getUid()
}
if @content?.getUid?
json['content'] = @content.getUid()
else
json['content'] = @content
if @origin isnt @prev_cl
json["origin"] = @origin.getUid()
json

View File

@ -1,14 +1,23 @@
json_types_uninitialized = require "./JsonTypes"
# some dom implementations may call another dom.method that simulates the behavior of another.
# For example xml.insertChild(dom) , wich inserts an element at the end, and xml.insertAfter(dom,null) wich does the same
# But yatta's proxy may be called only once!
proxy_token = false
Element?.prototype._proxy = (f_name, f)->
old_f = @[f_name]
if old_f?
@[f_name] = ()->
f.apply this, arguments
old_f.apply this, arguments
else
@[f_name] = f
if not proxy_token
proxy_token = true
old_f.apply this, arguments
f.apply this, arguments
proxy_token = false
else
old_f.apply this, arguments
#else
# @[f_name] = f
module.exports = (HB)->
@ -18,7 +27,10 @@ module.exports = (HB)->
#
# Manages XML types
#
# Not supported:
# * Attribute nodes
# * Real replace of child elements (to much overhead). Currently, the new element is inserted after the 'replaced' element, and then it is deleted.
# *
class XmlType extends types.Insert
constructor: (uid, @tagname, attributes, elements, @xml)->
@ -82,16 +94,24 @@ module.exports = (HB)->
setXmlProxy: ()->
@xml._yatta = @
@xml._proxy 'insertBefore', (insertedNode, adjacentNode)->
that = @
insertBefore = (insertedNode, adjacentNode)->
next = adjacentNode?._yatta
prev = null
if next?
prev = next.prev_cl
else
prev = @_yatta.elements.end.prev_cl
element = new XmlType undefined, undefined, undefined, undefined
element = new XmlType undefined, undefined, undefined, undefined, insertedNode
HB.addOperation(element).execute()
@elements.insertAfter prev, element
that.elements.insertAfter prev, element
@xml._proxy 'insertBefore', insertBefore
@xml._proxy 'appendChild', insertBefore
@xml._proxy 'removeAttribute', (name)->
that.attributes.val(name, undefined)
@xml._proxy 'removeChild', (node)->
val: (enforce = false)->
if document?
@ -100,9 +120,10 @@ module.exports = (HB)->
attr = @attributes.val()
for attr_name, value of attr
a = document.createAttribute attr_name
a.value = value
@xml.setAttributeNode a
if value?
a = document.createAttribute attr_name
a.value = value
@xml.setAttributeNode a
e = @elements.beginning.next_cl
while e.type isnt "Delimiter"

View File

@ -37,19 +37,43 @@ describe "XmlFramework", ->
@users = @yTest.users
###
@test_user = @yTest.makeNewUser 0, (Connector_uninitialized [])
@dom = $("#test_dom")[0]
@test_user.val(@dom)
@check = ()=>
dom_ = @test_user.val(true)
expect(dom_.outerHTML).to.equal(@dom.outerHTML)
done()
it "can transform to a real Dom element", ->
dom = $("#test_dom")[0]
@test_user.val(dom)
it "can transform to a new real Dom element", ->
dom_ = @test_user.val(true)
expect(dom_ isnt dom).to.be.true
expect(dom_.outerHTML).to.equal(dom.outerHTML)
expect(dom_ isnt @dom).to.be.true
@check()
it "can transform to a real Dom element", ->
dom = $("#test_dom")[0]
@test_user.val(dom)
it "supports dom.insertBefore", ->
newdom = $("<p>dtrn</p>")[0]
dom.insertBefore(newdom)
dom_ = @test_user.val(true)
@dom.insertBefore(newdom, null)
@check()
it "supports dom.appendChild", ->
newdom = $("<p>dtrn</p>")[0]
@dom.appendChild(newdom)
@check()
it "supports dom.removeAttribute", ->
@dom.removeAttribute("test_attribute")
@check()
it "supports dom.removeAttribute", ->
@dom.removeChild($("#removeme")[0])
expect($("#removeme").length).to.equal(0)
@check()