X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/432da106a4167b35113341fcb7d275ed53671480..eb2569dfea00204192e8a69aa4599bd2ab46c51e:/src/editor/modules/documentCanvas/canvas/canvas.js diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 428cedc..44d3e6d 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -2,15 +2,17 @@ define([ 'libs/jquery', 'libs/underscore', 'libs/backbone', +'fnpjs/logging/logging', 'modules/documentCanvas/canvas/documentElement', 'modules/documentCanvas/canvas/keyboard', 'modules/documentCanvas/canvas/utils', 'modules/documentCanvas/canvas/wlxmlListener' -], function($, _, Backbone, documentElement, keyboard, utils, wlxmlListener) { +], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener) { 'use strict'; /* global document:false, window:false, Node:false */ +var logger = logging.getLogger('canvas'); var TextHandler = function(canvas) {this.canvas = canvas; this.buffer = null;}; $.extend(TextHandler.prototype, { @@ -89,13 +91,20 @@ $.extend(Canvas.prototype, { keyboard.handleKey(e, this); }.bind(this)); + var mouseDown; + this.wrapper.on('mousedown', '[document-node-element], [document-text-element]', function(e) { + mouseDown = e.target; + }); + this.wrapper.on('click', '[document-node-element], [document-text-element]', function(e) { e.stopPropagation(); if(e.originalEvent.detail === 3) { e.preventDefault(); canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole'); } else { - canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + if(mouseDown === e.target) { + canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + } } }); @@ -136,7 +145,6 @@ $.extend(Canvas.prototype, { canvas._moveCaretToTextElement(canvas.getDocumentElement(mutation.target), 'end'); } observer.observe(canvas.wrapper[0], config); - canvas.publisher('contentChanged'); var textElement = canvas.getDocumentElement(mutation.target), toSet = mutation.target.data !== utils.unicode.ZWS ? mutation.target.data : ''; @@ -199,10 +207,6 @@ $.extend(Canvas.prototype, { element.toggleHighlight(toggle); }, - createNodeElement: function(params) { - return documentElement.DocumentNodeElement.create(params, this); - }, - getDocumentElement: function(from) { /* globals HTMLElement, Text */ if(from instanceof HTMLElement || from instanceof Text) { @@ -222,13 +226,20 @@ $.extend(Canvas.prototype, { return this.getDocumentElement(this.wrapper.find('.current-text-element')[0]); }, - + contains: function(element) { + return element.dom().parents().index(this.wrapper) !== -1; + }, setCurrentElement: function(element, params) { if(!(element instanceof documentElement.DocumentElement)) { element = utils.findCanvasElement(element); } + if(!element || !this.contains(element)) { + logger.warning('Cannot set current element: element doesn\'t exist on canvas'); + return; + } + params = _.extend({caretTo: 'end'}, params); var findFirstDirectTextChild = function(e, nodeToLand) { var byBrowser = this.getCursor().getPosition().element; @@ -250,7 +261,6 @@ $.extend(Canvas.prototype, { } else { this.wrapper.find('.current-node-element').removeClass('current-node-element'); element._container().addClass('current-node-element'); - this.publisher('currentElementChanged', element); } }.bind(this);