1 // Module that implements main WYSIWIG edit area
6 'fnpjs/logging/logging',
8 'libs/text!./template.html'], function($, _, logging, canvas3, template) {
13 var logger = logging.getLogger('documentCanvas');
15 return function(sandbox) {
17 var canvasElements = [];
19 sandbox.getPlugins().forEach(function(plugin) {
20 canvasElements = canvasElements.concat(plugin.canvasElements || []);
23 var canvas = canvas3.fromXMLDocument(null, canvasElements);
24 var canvasWrapper = $(template);
25 var shownAlready = false;
26 var scrollbarPosition = 0,
31 canvas.on('selectionChanged', function(selection) {
32 sandbox.publish('selectionChanged', selection);
35 canvasWrapper.onShow = function() {
38 canvas.setCurrentElement(canvas.doc().getVerticallyFirstTextElement());
40 canvas.setCursorPosition(cursorPosition);
41 this.find('#rng-module-documentCanvas-contentWrapper').scrollTop(scrollbarPosition);
45 canvasWrapper.onHide = function() {
46 scrollbarPosition = this.find('#rng-module-documentCanvas-contentWrapper').scrollTop();
47 cursorPosition = canvas.getCursor().getPosition();
53 sandbox.getPlugins().forEach(function(plugin) {
56 handlers = plugin.canvas.actionHandlers;
57 if(handlers && !_.isArray(handlers)) {
58 handlers = [handlers];
60 actionHandlers[plugin.name] = handlers;
63 sandbox.publish('ready');
68 getCanvas: function() {
71 setDocument: function(wlxmlDocument) {
72 canvas.loadWlxmlDocument(wlxmlDocument);
73 canvasWrapper.find('#rng-module-documentCanvas-content').empty().append(canvas.view());
75 highlightElement: function(node) {
76 canvas.toggleElementHighlight(node, true);
78 dimElement: function(node) {
79 canvas.toggleElementHighlight(node, false);
81 jumpToElement: function(node) {
82 canvas.setCurrentElement(node);
84 onAfterActionExecuted: function(action, ret) {
85 if(ret && ret.isValid()) {
86 logger.debug('The action returned a valid fragment');
87 return canvas.select(ret);
90 logger.debug('No valid fragment returned from the action');
92 (actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
93 handler(canvas, action, ret);