fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make sure to run all tests
[fnpeditor.git]
/
src
/
smartxml
/
smartxml.js
diff --git
a/src/smartxml/smartxml.js
b/src/smartxml/smartxml.js
index
865f928
..
43e3041
100644
(file)
--- a/
src/smartxml/smartxml.js
+++ b/
src/smartxml/smartxml.js
@@
-9,28
+9,42
@@
var TEXT_NODE = Node.TEXT_NODE, ELEMENT_NODE = Node.ELEMENT_NODE;
var parseXML = function(xml) {
return $(xml)[0];
var parseXML = function(xml) {
return $(xml)[0];
-}
+}
;
var Document = function(nativeNode) {
var $document = $(nativeNode);
var Document = function(nativeNode) {
var $document = $(nativeNode);
- Object.defineProperty(this, 'root', {get: function() { return new ElementNode($document[0])
}});
-}
+ Object.defineProperty(this, 'root', {get: function() { return new ElementNode($document[0])
;}});
+}
;
var DocumentNode = function(nativeNode) {
this.nativeNode = nativeNode;
this._$ = $(nativeNode);
var DocumentNode = function(nativeNode) {
this.nativeNode = nativeNode;
this._$ = $(nativeNode);
-}
+}
;
$.extend(DocumentNode.prototype, {
detach: function() { this._$.detach(); },
sameNode: function(otherNode) {
return this.nativeNode === otherNode.nativeNode;
$.extend(DocumentNode.prototype, {
detach: function() { this._$.detach(); },
sameNode: function(otherNode) {
return this.nativeNode === otherNode.nativeNode;
- }
-})
+ },
+
+ parent: function() {
+ return this.nativeNode.parentNode ? new ElementNode(this.nativeNode.parentNode) : null;
+ },
+
+ before: function(node) {
+ this._$.before(node.nativeNode);
+ },
+
+ wrapWith: function(node) {
+ if(this.parent())
+ this.before(node);
+ node.append(this);
+ },
+});
var ElementNode = function(nativeNode) {
DocumentNode.apply(this, arguments);
var ElementNode = function(nativeNode) {
DocumentNode.apply(this, arguments);
@@
-43,14
+57,6
@@
$.extend(ElementNode.prototype, DocumentNode.prototype, {
return this.nativeNode.tagName.toLowerCase();
},
return this.nativeNode.tagName.toLowerCase();
},
- append: function(documentNode) {
- this._$.append(documentNode.nativeNode);
- },
-
- before: function(node) {
- this._$.before(node.nativeNode);
- },
-
contents: function() {
var toret = [];
this._$.contents().each(function() {
contents: function() {
var toret = [];
this._$.contents().each(function() {
@@
-66,8
+72,16
@@
$.extend(ElementNode.prototype, DocumentNode.prototype, {
return this._$.contents().index(node._$);
},
return this._$.contents().index(node._$);
},
- parent: function() {
- return new ElementNode(this._$.parent());
+ getAttr: function(name) {
+ return this._$.attr(name);
+ },
+
+ setAttr: function(name, value) {
+ this._$.attr(name, value);
+ },
+
+ append: function(documentNode) {
+ this._$.append(documentNode.nativeNode);
},
unwrapContent: function() {
},
unwrapContent: function() {
@@
-118,7
+132,7
@@
$.extend(ElementNode.prototype, DocumentNode.prototype, {
var TextNode = function(nativeNode) {
DocumentNode.apply(this, arguments);
var TextNode = function(nativeNode) {
DocumentNode.apply(this, arguments);
-}
+}
;
$.extend(TextNode.prototype, DocumentNode.prototype, {
nodeType: Node.TEXT_NODE,
$.extend(TextNode.prototype, DocumentNode.prototype, {
nodeType: Node.TEXT_NODE,
@@
-134,7
+148,7
@@
$.extend(TextNode.prototype, DocumentNode.prototype, {
prependText: function(text) {
this.nativeNode.data = text + this.nativeNode.data;
}
prependText: function(text) {
this.nativeNode.data = text + this.nativeNode.data;
}
-})
+})
;
return {
return {