fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
smartxml: wrapping TextNode content
[fnpeditor.git]
/
src
/
smartxml
/
smartxml.js
diff --git
a/src/smartxml/smartxml.js
b/src/smartxml/smartxml.js
index
f4aa9fe
..
2e507db
100644
(file)
--- a/
src/smartxml/smartxml.js
+++ b/
src/smartxml/smartxml.js
@@
-29,7
+29,7
@@
$.extend(DocumentNode.prototype, {
detach: function() { this._$.detach(); },
sameNode: function(otherNode) {
detach: function() { this._$.detach(); },
sameNode: function(otherNode) {
- return this.nativeNode === otherNode.nativeNode;
+ return
otherNode &&
this.nativeNode === otherNode.nativeNode;
},
parent: function() {
},
parent: function() {
@@
-41,10
+41,13
@@
$.extend(DocumentNode.prototype, {
},
wrapWith: function(node) {
},
wrapWith: function(node) {
+ node = node instanceof ElementNode ? node : this.document.createElementNode(node);
+
if(this.parent()) {
this.before(node);
}
node.append(this);
if(this.parent()) {
this.before(node);
}
node.append(this);
+ return node;
},
triggerChangeEvent: function(type, metaData) {
},
triggerChangeEvent: function(type, metaData) {
@@
-209,12
+212,24
@@
$.extend(TextNode.prototype, DocumentNode.prototype, {
return this.nativeNode.data;
},
return this.nativeNode.data;
},
+ setText: function(text) {
+ this.nativeNode.data = text;
+ this.triggerTextChangeEvent();
+ },
+
appendText: function(text) {
this.nativeNode.data = this.nativeNode.data + text;
appendText: function(text) {
this.nativeNode.data = this.nativeNode.data + text;
+ this.triggerTextChangeEvent();
},
prependText: function(text) {
this.nativeNode.data = text + this.nativeNode.data;
},
prependText: function(text) {
this.nativeNode.data = text + this.nativeNode.data;
+ this.triggerTextChangeEvent();
+ },
+
+ triggerTextChangeEvent: function() {
+ var event = new events.ChangeEvent('nodeTextChange', {node: this});
+ this.document.trigger('change', event);
}
});
}
});
@@
-233,7
+248,7
@@
$.extend(Document.prototype, Backbone.Events, {
createElementNode: function(from) {
if(!(from instanceof HTMLElement)) {
createElementNode: function(from) {
if(!(from instanceof HTMLElement)) {
- from = $('<' + from.tagName + '>');
+ from = $('<' + from.tagName + '>')
[0]
;
}
return new this.ElementNodeFactory(from, this);
},
}
return new this.ElementNodeFactory(from, this);
},
@@
-242,10
+257,12
@@
$.extend(Document.prototype, Backbone.Events, {
return new this.TextNodeFactory(nativeNode, this);
},
return new this.TextNodeFactory(nativeNode, this);
},
- loadXML: function(xml) {
+ loadXML: function(xml, options) {
+ options = options || {};
defineDocumentProperties(this, $(parseXML(xml)));
defineDocumentProperties(this, $(parseXML(xml)));
-
- this.trigger('contentSet');
+ if(!options.silent) {
+ this.trigger('contentSet');
+ }
},
toXML: function() {
},
toXML: function() {