bd56c4372f9ca7d804176b28ebe9837581ea663a
[fnpeditor.git] / modules / sourceEditor / sourceEditor.js
1 define(function() {\r
2 \r
3 return function(sandbox) {\r
4 \r
5     var view = $(sandbox.getTemplate('main')());\r
6     \r
7     var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]);\r
8     editor.setTheme("ace/theme/chrome");\r
9     editor.getSession().setMode("ace/mode/xml");\r
10     $('textarea', view).on('keyup', function() {\r
11         sandbox.publish('xmlChanged');\r
12     });\r
13     \r
14     editor.getSession().on('change', function() {\r
15         sandbox.publish('xmlChanged');\r
16     })\r
17     return {\r
18         start: function() {\r
19             sandbox.publish('ready');\r
20         },\r
21         getView: function() {\r
22             return view;\r
23         },\r
24         setDocument: function(document) {\r
25             editor.setValue(document);\r
26             editor.gotoLine(0)\r
27             sandbox.publish('documentSet');\r
28         },\r
29         getDocument: function() {\r
30             return editor.getValue();\r
31         }\r
32     }\r
33 };\r
34 \r
35 });