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('operationEnd', function() {
27 this.canvas.triggerSelectionChanged();
30 wlxmlDocument.on('contentSet', function() {
31 this.canvas.loadWlxmlDocument(wlxmlDocument);
37 var _metadataEventHandler = function(event) {
38 var element = utils.getElementForNode(event.meta.node);
39 element.handle(event);
44 nodeAttrChange: function(event) {
45 var element = utils.getElementForNode(event.meta.node),
47 if(event.meta.attr === 'class') {
48 if(element.wlxmlNode.getClass() !== event.meta.attr) {
49 if(event.meta.node.isRoot()) {
50 this.canvas.reloadRoot();
52 newElement = this.canvas.createElement(event.meta.node);
53 element.dom.replaceWith(newElement.dom);
58 element.handle(event);
61 nodeAdded: function(event) {
62 if(event.meta.node.isRoot()) {
63 this.canvas.reloadRoot();
67 var containingNode = event.meta.node.parent(),
68 containingElement = utils.getElementForNode(containingNode);
70 containingElement.handle(event);
72 nodeDetached: function(event) {
73 var element = utils.getElementForDetachedNode(event.meta.node, event.meta.parent);
74 element.handle(event);
76 nodeTextChange: function(event) {
77 var element = utils.getElementForNode(event.meta.node);
78 element.handle(event);
81 metadataChanged: _metadataEventHandler,
82 metadataAdded: _metadataEventHandler,
83 metadataRemoved: _metadataEventHandler
87 create: function(canvas) {
88 return new Listener(canvas);