fb6a2de487e499dea13ad8c01d70c9eae3e18f65
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / wlxmlListener.js
1 define([
2 'libs/jquery',
3 'modules/documentCanvas/canvas/utils',
4 ], function($, utils) {
5     
6 'use strict';
7
8 var Listener = function(canvas) {
9     this.canvas = canvas;
10 };
11
12 $.extend(Listener.prototype, {
13     listenTo: function(wlxmlDocument) {
14         if(wlxmlDocument === this.wlxmlDocument) {
15             return;
16         }
17
18         wlxmlDocument.on('change', function(event) {
19             var handler = handlers[event.type];
20             if(handler) {
21                 handler.bind(this)(event);
22             }
23         }, this);
24     }
25 });
26
27 var handlers = {
28     nodeAttrChange: function(event) {
29         if(event.meta.attr === 'class') {
30             var canvasNode = utils.findCanvasElement(event.meta.node);
31             canvasNode.setWlxmlClass(event.meta.newVal);
32         }
33     }
34 };
35
36 return {
37     create: function(canvas) {
38         return new Listener(canvas);
39     }
40 };
41
42 });