comparison browser_side/nativedom.py @ 245:43881c3dda9d

browser side: added Node.setAttribute and Node.toxml to nativedom
author Goffi <goffi@goffi.org>
date Sat, 09 Nov 2013 10:23:33 +0100
parents 9763dec220ed
children ea1be522ba88
comparison
equal deleted inserted replaced
244:43a27ffc74df 245:43881c3dda9d
26 26
27 from __pyjamas__ import JS 27 from __pyjamas__ import JS
28 28
29 29
30 class Node(): 30 class Node():
31 31
32 def __init__(self, js_node): 32 def __init__(self, js_node):
33 self._node = js_node 33 self._node = js_node
34 34
35 def _jsNodesList2List(self, js_nodes_list): 35 def _jsNodesList2List(self, js_nodes_list):
36 ret=[] 36 ret=[]
48 return self._jsNodesList2List(self._node.childNodes) 48 return self._jsNodesList2List(self._node.childNodes)
49 49
50 def getAttribute(self, attr): 50 def getAttribute(self, attr):
51 return self._node.getAttribute(attr) 51 return self._node.getAttribute(attr)
52 52
53 def setAttribute(self, attr, value):
54 return self._node.setAttribute(attr, value)
55
53 def hasAttribute(self, attr): 56 def hasAttribute(self, attr):
54 return self._node.hasAttribute(attr) 57 return self._node.hasAttribute(attr)
58
59 def toxml(self):
60 return JS("""this._node.outerHTML || new XMLSerializer().serializeToString(this._node);""")
55 61
56 62
57 class Element(Node): 63 class Element(Node):
58 64
59 def __init__(self, js_node): 65 def __init__(self, js_node):
60 Node.__init__(self, js_node) 66 Node.__init__(self, js_node)
61 67
62 def getElementsByTagName(self, tagName): 68 def getElementsByTagName(self, tagName):
63 return self._jsNodesList2List(self._node.getElementsByTagName(tagName)) 69 return self._jsNodesList2List(self._node.getElementsByTagName(tagName))
64 70
71
65 class Document(Node): 72 class Document(Node):
66 73
67 def __init__(self, js_document): 74 def __init__(self, js_document):
68 Node.__init__(self, js_document) 75 Node.__init__(self, js_document)
69 76
70 @property 77 @property
71 def documentElement(self): 78 def documentElement(self):
72 return Element(self._node.documentElement) 79 return Element(self._node.documentElement)
73 80
81
74 class NativeDOM: 82 class NativeDOM:
75 83
76 def __init__(self): 84 def __init__(self):
77 JS(""" 85 JS("""
78 86
79 if (typeof window.DOMParser != "undefined") { 87 if (typeof window.DOMParser != "undefined") {
80 this.parseXml = function(xmlStr) { 88 this.parseXml = function(xmlStr) {