fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
smartxml/wlxml: Merge in document node instances caching
[fnpeditor.git]
/
src
/
smartxml
/
smartxml.js
diff --git
a/src/smartxml/smartxml.js
b/src/smartxml/smartxml.js
index
a5a1abc
..
c0b3c42
100644
(file)
--- a/
src/smartxml/smartxml.js
+++ b/
src/smartxml/smartxml.js
@@
-12,6
+12,8
@@
define([
/* globals Node */
/* globals Node */
+var privateKey = '_smartxml';
+
var DocumentNode = function(nativeNode, document) {
if(!document) {
throw new Error('undefined document for a node');
var DocumentNode = function(nativeNode, document) {
if(!document) {
throw new Error('undefined document for a node');
@@
-48,7
+50,7
@@
$.extend(DocumentNode.prototype, {
clone.find('*').addBack().each(function() {
var el = this,
clonedData = $(this).data();
clone.find('*').addBack().each(function() {
var el = this,
clonedData = $(this).data();
-
+ $(el).removeData(privateKey);
_.pairs(clonedData).forEach(function(pair) {
var key = pair[0],
value = pair[1];
_.pairs(clonedData).forEach(function(pair) {
var key = pair[0],
value = pair[1];
@@
-180,6
+182,7
@@
$.extend(DocumentNode.prototype, {
var ElementNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
var ElementNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
+ $(nativeNode).data(privateKey, {node: this});
};
ElementNode.prototype = Object.create(DocumentNode.prototype);
};
ElementNode.prototype = Object.create(DocumentNode.prototype);
@@
-203,7
+206,9
@@
$.extend(ElementNode.prototype, {
if(key) {
return this._$.data(key);
}
if(key) {
return this._$.data(key);
}
- return this._$.data();
+ var toret = _.clone(this._$.data());
+ delete toret[privateKey];
+ return toret;
},
getTagName: function() {
},
getTagName: function() {
@@
-275,6
+280,7
@@
$.extend(ElementNode.prototype, {
var TextNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
var TextNode = function(nativeNode, document) {
DocumentNode.call(this, nativeNode, document);
+ nativeNode.__smartxmlTextNodeInstance = this;
};
TextNode.prototype = Object.create(DocumentNode.prototype);
};
TextNode.prototype = Object.create(DocumentNode.prototype);
@@
-352,7
+358,15
@@
$.extend(Document.prototype, Backbone.Events, fragments, {
TextNodeFactory: TextNode,
createDocumentNode: function(from) {
TextNodeFactory: TextNode,
createDocumentNode: function(from) {
- if(!(from instanceof Node)) {
+ var cached;
+
+ if(from instanceof Node) {
+ /* globals Text */
+ cached = from instanceof Text ? from.__smartxmlTextNodeInstance : ($(from).data(privateKey) || {}).node;
+ if(cached instanceof DocumentNode) {
+ return cached;
+ }
+ } else {
if(typeof from === 'string') {
from = parseXML(from);
this.normalizeXML(from);
if(typeof from === 'string') {
from = parseXML(from);
this.normalizeXML(from);