many jquery methods work

This commit is contained in:
Kevin Jahns 2014-09-29 18:52:05 +02:00
parent 1e73381863
commit eb3afe9106
43 changed files with 548 additions and 125 deletions

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

@ -168,6 +168,10 @@
throw new Error("You must not overwrite operations!");
}
this.buffer[o.creator][o.op_number] = o;
if (this.number_of_operations_added_to_HB == null) {
this.number_of_operations_added_to_HB = 0;
}
this.number_of_operations_added_to_HB++;
return o;
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -47,6 +47,9 @@
};
TextInsert.prototype.applyDelete = function() {
if (this.content instanceof types.Operation) {
this.content.applyDelete();
}
this.content = null;
return TextInsert.__super__.applyDelete.apply(this, arguments);
};

File diff suppressed because one or more lines are too long

View File

@ -101,7 +101,7 @@
};
XmlType.prototype.setXmlProxy = function() {
var insertBefore, that;
var insertBefore, removeChild, that;
this.xml._yatta = this;
that = this;
insertBefore = function(insertedNode, adjacentNode) {
@ -122,7 +122,23 @@
this.xml._proxy('removeAttribute', function(name) {
return that.attributes.val(name, void 0);
});
return this.xml._proxy('removeChild', function(node) {});
removeChild = function(node) {
var d, elem;
elem = that.elements.beginning.next_cl;
while (elem.type !== 'Delimiter' && elem.content !== node._yatta) {
elem = elem.next_cl;
}
if (elem.type === 'Delimiter') {
throw new Error("You are only allowed to delete existing (direct) child elements!");
}
d = new types.Delete(void 0, elem);
return HB.addOperation(d).execute();
};
this.xml._proxy('removeChild', removeChild);
return this.xml._proxy('replaceChild', function(insertedNode, replacedNode) {
insertBefore.call(this, replacedNode, insertedNode);
return removeChild.call(this, replacedNode);
});
};
XmlType.prototype.val = function(enforce) {
@ -145,7 +161,7 @@
e = this.elements.beginning.next_cl;
while (e.type !== "Delimiter") {
n = e.content;
if (!n.isDeleted()) {
if (!e.isDeleted()) {
if (n.type === "XmlType") {
this.xml.appendChild(n.val(enforce));
} else if (n.type === "WordType") {

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" test_attribute="the test"><p id="removeme">remove me</p><p>This is a test object for <b>XmlFramework</b></p></div>
<div id="test_dom" test_attribute="the test" class="stuffy" style="color: blue"><p id="replaceme">replace me</p><p id="removeme">remove me</p><p>This is a test object for <b>XmlFramework</b></p><span class="span_element"><p>span</p></span></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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -335,7 +335,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
September 29, 14 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -258,7 +258,7 @@ This result can be send to other clients.</p>
</div>
</div>
<div id='footer'>
September 29, 14 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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;&#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>
<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;&#97;&#x69;&#x6c;&#x74;&#111;&#58;&#x6b;&#101;&#x76;&#x69;&#110;&#46;&#x6a;&#x61;&#104;&#x6e;&#x73;&#64;&#x72;&#119;&#x74;&#104;&#45;&#97;&#97;&#x63;&#104;&#x65;&#x6e;&#x2e;&#100;&#x65;">&#x6b;&#101;&#x76;&#x69;&#110;&#46;&#x6a;&#x61;&#104;&#x6e;&#x73;&#64;&#x72;&#119;&#x74;&#104;&#45;&#97;&#97;&#x63;&#104;&#x65;&#x6e;&#x2e;&#100;&#x65;</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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -82,7 +82,7 @@ But yatta&#39;s proxy may be called only once!</p>
</div>
</div>
<div id='footer'>
September 29, 14 15:28:15 by
September 29, 14 16:10:05 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 15:28:15 by
September 29, 14 16:10:05 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -43,6 +43,8 @@ module.exports = (HB)->
@content.length
applyDelete: ()->
if @content instanceof types.Operation
@content.applyDelete()
@content = null
super

View File

@ -5,7 +5,7 @@ json_types_uninitialized = require "./JsonTypes"
# 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)->
_proxy = (f_name, f)->
old_f = @[f_name]
if old_f?
@[f_name] = ()->
@ -18,6 +18,7 @@ Element?.prototype._proxy = (f_name, f)->
old_f.apply this, arguments
#else
# @[f_name] = f
Element?.prototype._proxy = _proxy
module.exports = (HB)->
@ -30,7 +31,8 @@ module.exports = (HB)->
# 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.
# *
# * Namespaces (*NS)
# * Browser specific methods (webkit-* operations)
class XmlType extends types.Insert
constructor: (uid, @tagname, attributes, elements, @xml)->
@ -95,10 +97,26 @@ module.exports = (HB)->
setXmlProxy: ()->
@xml._yatta = @
that = @
# you want to find a specific child element. Since they are carried by an Insert-Type, you want to find that Insert-Operation.
# @param child {DomElement} Dom element.
# @return {InsertType} This carries the XmlType that represents the DomElement (child). false if i couldn't find it.
#
findNode = (child)->
child = child._yatta
elem = that.elements.beginning.next_cl
while elem.type isnt 'Delimiter' and elem.content isnt child
elem = elem.next_cl
if elem.type is 'Delimiter'
false
else
elem
insertBefore = (insertedNode, adjacentNode)->
next = adjacentNode?._yatta
next = null
if adjacentNode?
next = findNode adjacentNode
prev = null
if next?
if next
prev = next.prev_cl
else
prev = @_yatta.elements.end.prev_cl
@ -109,8 +127,39 @@ module.exports = (HB)->
@xml._proxy 'appendChild', insertBefore
@xml._proxy 'removeAttribute', (name)->
that.attributes.val(name, undefined)
@xml._proxy 'removeChild', (node)->
@xml._proxy 'setAttribute', (name, value)->
that.attributes.val name, value
renewClassList = ()->
that.attributes.val('class', Array.prototype.join.call this, " ")
_proxy.call @xml.classList, 'add', renewClassList
_proxy.call @xml.classList, 'remove', renewClassList
@xml.__defineSetter__ 'className', (val)->
@setAttribute('class', val)
@xml.__defineGetter__ 'className', ()->
that.attributes.val('class')
@xml.__defineSetter__ 'textContent', (val)->
# remove all nodes
elems = that.xml.childNodes
for elem in elems
that.xml.removeChild elem
# insert word content
if val isnt ""
text_node = document.createTextNode val
that.xml.appendChild text_node
removeChild = (node)->
elem = findNode node
if not elem
throw new Error "You are only allowed to delete existing (direct) child elements!"
d = new types.Delete undefined, elem
HB.addOperation(d).execute()
@xml._proxy 'removeChild', removeChild
@xml._proxy 'replaceChild', (insertedNode, replacedNode)->
insertBefore.call this, insertedNode, replacedNode
removeChild.call this, replacedNode
val: (enforce = false)->
@ -128,7 +177,7 @@ module.exports = (HB)->
e = @elements.beginning.next_cl
while e.type isnt "Delimiter"
n = e.content
if not n.isDeleted()
if not e.isDeleted()
if n.type is "XmlType"
@xml.appendChild n.val(enforce)
else if n.type is "WordType"

View File

@ -37,7 +37,8 @@ describe "XmlFramework", ->
@users = @yTest.users
###
@test_user = @yTest.makeNewUser 0, (Connector_uninitialized [])
@dom = $("#test_dom")[0]
@$dom = $("#test_dom")
@dom = @$dom[0]
@test_user.val(@dom)
@check = ()=>
@ -52,7 +53,10 @@ describe "XmlFramework", ->
it "supports dom.insertBefore", ->
newdom = $("<p>dtrn</p>")[0]
newdom2 = $("<p>dtrn2</p>")[0]
n = $("#removeme")[0]
@dom.insertBefore(newdom, null)
@dom.insertBefore(newdom2, n)
@check()
it "supports dom.appendChild", ->
@ -60,20 +64,83 @@ describe "XmlFramework", ->
@dom.appendChild(newdom)
@check()
it "supports dom.setAttribute", ->
@dom.setAttribute("test_attribute", "newVal")
@check()
it "supports dom.removeAttribute", ->
@dom.removeAttribute("test_attribute")
@check()
it "supports dom.removeAttribute", ->
it "supports dom.removeChild", ->
@dom.removeChild($("#removeme")[0])
expect($("#removeme").length).to.equal(0)
@check()
it "supports dom.replaceChild", ->
newdom = $("<p>replaced</p>")[0]
replace = $("#replaceme")[0]
@dom.replaceChild(newdom,replace)
expect($("#replaceme").length).to.equal(0)
@check()
it "supports dom.classList.add", ->
@dom.classList.add "classy"
@check()
it "supports dom.textcontent", -> #TODO!!!!
@dom.classList.add "classy"
@check()
it "supports jquery.addClass", ->
@$dom.addClass("testy")
@check()
it "supports jquery.after", ->
d = $("#test_dom p")
d.after("<div class=\"inserted_after\">after</div>")
@check()
it "supports jquery.append", ->
d = $("#test_dom p")
d.after("<b>appended</b>")
@check()
it "supports jquery.appendTo", ->
$("<b>appendedTo</b>").appendTo("#test_dom p")
@check()
it "supports jquery.before", ->
d = $("#test_dom p")
d.before("<div>before</div>")
@check()
it "supports jquery.detach", ->
d = $(".inserted_after")
d.detach()
@check()
it "supports jquery.empty", ->
d = $("p")
d.empty()
@check()
it "supports jquery.insertAfter", ->
$("<p>after span</p>").insertAfter(".span_element")
@check()
it "supports jquery.insertBefore", ->
$("<p>before span</p>").insertBefore(".span_element")
@check()
it "supports jquery.insertBefore", ->
d = $("p")
d.empty()
@check()