fnp
/
fnpeditor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e1d74f7
)
canvas: wlxmlListener - handle setting root node
author
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 26 Nov 2013 15:52:49 +0000
(16:52 +0100)
committer
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 2 Dec 2013 13:50:54 +0000
(14:50 +0100)
src/editor/modules/documentCanvas/canvas/canvas.js
patch
|
blob
|
history
src/editor/modules/documentCanvas/canvas/canvas.test.js
patch
|
blob
|
history
src/editor/modules/documentCanvas/canvas/wlxmlListener.js
patch
|
blob
|
history
diff --git
a/src/editor/modules/documentCanvas/canvas/canvas.js
b/src/editor/modules/documentCanvas/canvas/canvas.js
index
9a01457
..
cf63c47
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/canvas.js
+++ b/
src/editor/modules/documentCanvas/canvas/canvas.js
@@
-25,15
+25,17
@@
$.extend(Canvas.prototype, {
return false;
}
return false;
}
- var canvasDOM = this.generateCanvasDOM(wlxmlDocument.root);
+ this.wlxmlListener.listenTo(wlxmlDocument);
+ this.wlxmlDocument = wlxmlDocument;
+ this.reloadRoot();
+ this.setupEventHandling();
+ },
+ reloadRoot: function() {
+ var canvasDOM = this.generateCanvasDOM(this.wlxmlDocument.root);
this.wrapper.empty();
this.wrapper.append(canvasDOM);
this.d = this.wrapper.children(0);
this.wrapper.empty();
this.wrapper.append(canvasDOM);
this.d = this.wrapper.children(0);
- this.setupEventHandling();
-
- this.wlxmlListener.listenTo(wlxmlDocument);
- this.wlxmlDocument = wlxmlDocument;
},
generateCanvasDOM: function(wlxmlNode) {
},
generateCanvasDOM: function(wlxmlNode) {
diff --git
a/src/editor/modules/documentCanvas/canvas/canvas.test.js
b/src/editor/modules/documentCanvas/canvas/canvas.test.js
index
35ad728
..
98b7ffe
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/canvas.test.js
+++ b/
src/editor/modules/documentCanvas/canvas/canvas.test.js
@@
-14,9
+14,13
@@
define([
var expect = chai.expect;
var getCanvasFromXML = function(xml) {
var expect = chai.expect;
var getCanvasFromXML = function(xml) {
- return canvas.fromXMLDocument(
wlxml.WLXML
DocumentFromXML(xml));
+ return canvas.fromXMLDocument(
get
DocumentFromXML(xml));
};
};
+var getDocumentFromXML = function(xml) {
+ return wlxml.WLXMLDocumentFromXML(xml);
+}
+
var wait = function(callback, timeout) {
return window.setTimeout(callback, timeout || 0.5);
};
var wait = function(callback, timeout) {
return window.setTimeout(callback, timeout || 0.5);
};
@@
-46,6
+50,16
@@
describe('Handling empty text nodes', function() {
});
});
});
});
+describe('Handling changes to the document', function() {
+ it('replaces the whole canvas content when document root node replaced', function() {
+ var doc = getDocumentFromXML('<section></section>'),
+ c = canvas.fromXMLDocument(doc);
+
+ var header = doc.root.replaceWith({tagName: 'header'});
+ expect(c.doc().data('wlxmlNode').sameNode(header)).to.be.true;
+ });
+});
+
describe('Cursor', function() {
var getSelection;
describe('Cursor', function() {
var getSelection;
diff --git
a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js
b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js
index
9269ce1
..
2dd61ff
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/wlxmlListener.js
+++ b/
src/editor/modules/documentCanvas/canvas/wlxmlListener.js
@@
-41,6
+41,10
@@
var handlers = {
canvasNode.setWlxmlTag(event.meta.newTagName);
},
nodeAdded: function(event) {
canvasNode.setWlxmlTag(event.meta.newTagName);
},
nodeAdded: function(event) {
+ if(event.meta.node.isRoot()) {
+ this.canvas.reloadRoot();
+ return;
+ }
var parentElement = utils.findCanvasElement(event.meta.node.parent()),
nodeIndex = event.meta.node.getIndex(),
referenceElement, referenceAction;
var parentElement = utils.findCanvasElement(event.meta.node.parent()),
nodeIndex = event.meta.node.getIndex(),
referenceElement, referenceAction;