3 'modules/documentCanvas/canvas/utils',
4 ], function($, utils) {
8 var Listener = function(canvas) {
12 $.extend(Listener.prototype, {
13 listenTo: function(wlxmlDocument) {
14 if(wlxmlDocument === this.wlxmlDocument) {
17 this.wlxmlDocument = wlxmlDocument;
19 wlxmlDocument.on('change', function(event) {
20 var handler = handlers[event.type];
22 handler.bind(this)(event);
26 wlxmlDocument.on('contentSet', function() {
27 this.canvas.loadWlxmlDocument(wlxmlDocument);
33 nodeAttrChange: function(event) {
34 if(event.meta.attr === 'class') {
35 var canvasNode = utils.findCanvasElement(event.meta.node);
36 canvasNode.setWlxmlClass(event.meta.newVal);
39 nodeTagChange: function(event) {
40 var canvasNode = utils.findCanvasElement(event.meta.node);
41 canvasNode.setWlxmlTag(event.meta.newTagName);
43 nodeAdded: function(event, checkForExistence) {
44 if(event.meta.node.isRoot()) {
45 this.canvas.reloadRoot();
48 var parentElement = utils.findCanvasElement(event.meta.node.parent()),
49 nodeIndex = event.meta.node.getIndex(),
50 referenceElement, referenceAction, actionArg;
53 referenceElement = parentElement;
54 referenceAction = 'prepend';
56 referenceElement = parentElement.children()[nodeIndex-1];
57 referenceAction = 'after';
60 actionArg = (checkForExistence && utils.findCanvasElement(event.meta.node)) || event.meta.node;
61 referenceElement[referenceAction](actionArg);
63 nodeMoved: function(event) {
64 return handlers.nodeAdded(event, true);
66 nodeDetached: function(event) {
67 var canvasNode = utils.findCanvasElementInParent(event.meta.node, event.meta.parent);
70 nodeTextChange: function(event) {
71 //console.log('wlxmlListener: ' + event.meta.node.getText());
72 var canvasElement = utils.findCanvasElement(event.meta.node),
73 toSet = event.meta.node.getText();
75 toSet = utils.unicode.ZWS;
77 if(toSet !== canvasElement.getText()) {
78 canvasElement.setText(toSet);
84 create: function(canvas) {
85 return new Listener(canvas);