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

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"