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         user: sandbox.getConfig().user
 
  26     var canvasWrapper = $(template);
 
  27     var shownAlready = false;
 
  28     var scrollbarPosition = 0,
 
  33     canvas.on('selectionChanged', function(selection) {
 
  34         sandbox.publish('selectionChanged', selection);
 
  37     canvasWrapper.onShow = function() {
 
  40             canvas.setCurrentElement(canvas.doc().getVerticallyFirstTextElement());
 
  42             canvas.setCursorPosition(cursorPosition);
 
  43             this.find('#rng-module-documentCanvas-contentWrapper').scrollTop(scrollbarPosition);
 
  47     canvasWrapper.onHide = function() {
 
  48        scrollbarPosition = this.find('#rng-module-documentCanvas-contentWrapper').scrollTop();
 
  49        cursorPosition = canvas.getCursor().getPosition();
 
  55             sandbox.getPlugins().forEach(function(plugin) {
 
  58                     handlers = plugin.canvas.actionHandlers;
 
  59                     if(handlers && !_.isArray(handlers)) {
 
  60                         handlers = [handlers];
 
  62                     actionHandlers[plugin.name] = handlers;
 
  65             sandbox.publish('ready');
 
  70         getCanvas: function() {
 
  73         setDocument: function(wlxmlDocument) {
 
  74             canvas.loadWlxmlDocument(wlxmlDocument);
 
  75             canvasWrapper.find('#rng-module-documentCanvas-contentWrapper').empty().append(canvas.view());
 
  77         highlightElement: function(node) {
 
  78             canvas.toggleElementHighlight(node, true);
 
  80         dimElement: function(node) {
 
  81             canvas.toggleElementHighlight(node, false);
 
  83         jumpToElement: function(node) {
 
  84             canvas.setCurrentElement(node);
 
  86         onAfterActionExecuted: function(action, ret) {
 
  87             if(ret && ret.isValid()) {
 
  88                 logger.debug('The action returned a valid fragment');
 
  89                 return canvas.select(ret);
 
  92             logger.debug('No valid fragment returned from the action');
 
  94             (actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
 
  95                 handler(canvas, action, ret);