X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ca1c01b10805014a2f1c24c6f055cd77fc66af01..3d5a3556cac5639b18e41ad5c96d4d4573101e00:/modules/documentCanvas/canvas/canvas.js diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index f9f3ee0..f96e62e 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -38,41 +38,51 @@ $.extend(Canvas.prototype, { tag: currentTag.prop('tagName').toLowerCase(), klass: currentTag.attr('class'), meta: meta, - others: others + others: others, + rawChildren: currentTag.contents() }); - element.dom().append(currentTag.contents()); ['orig-before', 'orig-after', 'orig-begin', 'orig-end'].forEach(function(attr) { element.data(attr, ''); }); return element.dom(); }); + var FIRST_CONTENT_INDEX = 0; + + // @@ TODO - refactor! + var getNode = function(element) { + return element.children('[document-element-content]'); + } + this.wrapper.find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE}) .each(function() { + // TODO: use DocumentElement API var el = $(this), text = {original: el.text(), trimmed: $.trim(el.text())}, elParent = el.parent(), hasSpanParent = elParent.attr('wlxml-tag') === 'span', - hasSpanBefore = el.prev().length > 0 && $(el.prev()[0]).attr('wlxml-tag') === 'span', - hasSpanAfter = el.next().length > 0 && $(el.next()[0]).attr('wlxml-tag') === 'span'; + hasSpanBefore = el.prev().length > 0 && getNode($(el.prev()[0])).attr('wlxml-tag') === 'span', + hasSpanAfter = el.next().length > 0 && getNode($(el.next()[0])).attr('wlxml-tag') === 'span'; + if(el.parent().hasClass('canvas-widget')) + return true; // continue var addInfo = function(toAdd, where) { var parentContents = elParent.contents(), idx = parentContents.index(el[0]), - prev = idx > 0 ? parentContents[idx-1] : null, + prev = idx > FIRST_CONTENT_INDEX ? parentContents[idx-1] : null, next = idx < parentContents.length - 1 ? parentContents[idx+1] : null, target, key; if(where === 'above') { - target = prev ? $(prev) : elParent; + target = prev ? $(prev) : elParent.parent(); key = prev ? 'orig-after' : 'orig-begin'; } else if(where === 'below') { - target = next ? $(next) : elParent; + target = next ? $(next) : elParent.parent(); key = next ? 'orig-before' : 'orig-end'; } else { throw new Object;} @@ -196,12 +206,11 @@ $.extend(Canvas.prototype, { } }); - this.wrapper.on('click', '[wlxml-tag], [wlxml-text]', function(e) { + this.wrapper.on('click', '[wlxml-tag], [document-text-element]', function(e) { e.stopPropagation(); canvas.setCurrentElement(canvas.getDocumentElement(e.target), {caretTo: false}); }); - var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if(documentElement.DocumentTextElement.isContentContainer(mutation.target) && mutation.target.data === '') @@ -211,6 +220,26 @@ $.extend(Canvas.prototype, { var config = { attributes: false, childList: false, characterData: true, subtree: true, characterDataOldValue: true}; observer.observe(this.d[0], config); + + this.wrapper.on('mouseover', '[wlxml-tag], [document-text-element]', function(e) { + var el = canvas.getDocumentElement(e.target); + if(!el) + return; + e.stopPropagation(); + if(el instanceof documentElement.DocumentTextElement) + el = el.parent(); + el.toggleLabel(true); + }); + this.wrapper.on('mouseout', '[wlxml-tag], [document-text-element]', function(e) { + var el = canvas.getDocumentElement(e.target); + if(!el) + return; + e.stopPropagation(); + if(el instanceof documentElement.DocumentTextElement) + el = el.parent(); + el.toggleLabel(false); + }); + } else { this.d = null; }