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 canvas = canvas3.fromXMLDocument(null);
18 var canvasWrapper = $(template);
19 var shownAlready = false;
20 var scrollbarPosition = 0,
25 canvas.on('selectionChanged', function(selection) {
26 sandbox.publish('selectionChanged', selection);
29 canvasWrapper.onShow = function() {
32 canvas.setCurrentElement(canvas.doc().getVerticallyFirstTextElement());
34 canvas.setCursorPosition(cursorPosition);
35 this.find('#rng-module-documentCanvas-contentWrapper').scrollTop(scrollbarPosition);
39 canvasWrapper.onHide = function() {
40 scrollbarPosition = this.find('#rng-module-documentCanvas-contentWrapper').scrollTop();
41 cursorPosition = canvas.getCursor().getPosition();
47 sandbox.getPlugins().forEach(function(plugin) {
50 handlers = plugin.canvas.actionHandlers;
51 if(handlers && !_.isArray(handlers)) {
52 handlers = [handlers];
54 actionHandlers[plugin.name] = handlers;
57 sandbox.publish('ready');
62 getCanvas: function() {
65 setDocument: function(wlxmlDocument) {
66 canvas.loadWlxmlDocument(wlxmlDocument);
67 canvasWrapper.find('#rng-module-documentCanvas-content').empty().append(canvas.view());
69 highlightElement: function(node) {
70 canvas.toggleElementHighlight(node, true);
72 dimElement: function(node) {
73 canvas.toggleElementHighlight(node, false);
75 jumpToElement: function(node) {
76 canvas.setCurrentElement(node);
78 onAfterActionExecuted: function(action, ret) {
79 if(ret && ret instanceof canvas.wlxmlDocument.CaretFragment && ret.isValid()) {
80 logger.debug('The action returned a valid fragment');
81 canvas.setCurrentElement(ret.node, {caretTo: ret.offset});
84 logger.debug('No valid fragment returned from the action');
86 (actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
87 handler(canvas, action, ret);