1 // Module that implements main WYSIWIG edit area
7 'libs/text!./template.html'], function($, _, canvas3, template) {
11 return function(sandbox) {
13 var canvas = canvas3.fromXMLDocument(null);
14 var canvasWrapper = $(template);
15 var shownAlready = false;
16 var scrollbarPosition = 0,
21 canvas.on('selectionChanged', function(selection) {
22 sandbox.publish('selectionChanged', selection);
25 canvasWrapper.onShow = function() {
28 canvas.setCurrentElement(canvas.doc().getVerticallyFirstTextElement());
30 canvas.setCursorPosition(cursorPosition);
31 this.find('#rng-module-documentCanvas-contentWrapper').scrollTop(scrollbarPosition);
35 canvasWrapper.onHide = function() {
36 scrollbarPosition = this.find('#rng-module-documentCanvas-contentWrapper').scrollTop();
37 cursorPosition = canvas.getCursor().getPosition();
43 sandbox.getPlugins().forEach(function(plugin) {
46 handlers = plugin.canvas.actionHandlers;
47 if(handlers && !_.isArray(handlers)) {
48 handlers = [handlers];
50 actionHandlers[plugin.name] = handlers;
53 sandbox.publish('ready');
58 getCanvas: function() {
61 setDocument: function(wlxmlDocument) {
62 canvas.loadWlxmlDocument(wlxmlDocument);
63 canvasWrapper.find('#rng-module-documentCanvas-content').empty().append(canvas.view());
65 highlightElement: function(node) {
66 canvas.toggleElementHighlight(node, true);
68 dimElement: function(node) {
69 canvas.toggleElementHighlight(node, false);
71 jumpToElement: function(node) {
72 canvas.setCurrentElement(node);
74 onAfterActionExecuted: function(action, ret) {
75 (actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
76 handler(canvas, action, ret);