X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0bea7025f60aa5cc2ed89eed72da0d616f3574ef..4a1c68596333765b36f36a9cf88942f90c20efab:/src/editor/modules/documentCanvas/canvas/documentElement.js diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 283f873..7b7f7f9 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -5,14 +5,14 @@ define([ ], function($, _, utils) { 'use strict'; -/* global Node:false, document:false */ +/* global Node:false */ // DocumentElement represents a text or an element node from WLXML document rendered inside Canvas var DocumentElement = function(wlxmlNode, canvas) { this.wlxmlNode = wlxmlNode; this.canvas = canvas; - this.createDOM(); + this.$element = this.createDOM(); this.$element.data('canvas-element', this); }; @@ -26,9 +26,6 @@ $.extend(DocumentElement.prototype, { refresh: function() { // noop }, - bound: function() { - return $.contains(document.documentElement, this.dom()[0]); - }, dom: function() { return this.$element; }, @@ -54,20 +51,6 @@ $.extend(DocumentElement.prototype, { return other && (typeof other === typeof this) && other.dom()[0] === this.dom()[0]; }, - getPreviousTextElement: function(includeInvisible) { - return this.getNearestTextElement('above', includeInvisible); - }, - - getNextTextElement: function(includeInvisible) { - return this.getNearestTextElement('below', includeInvisible); - }, - - getNearestTextElement: function(direction, includeInvisible) { - includeInvisible = includeInvisible !== undefined ? includeInvisible : false; - var selector = '[document-text-element]' + (includeInvisible ? '' : ':visible'); - return this.canvas.getDocumentElement(utils.nearestInDocumentOrder(selector, direction, this.dom()[0])); - }, - trigger: function() { //this.canvas.bus.trigger() } @@ -80,10 +63,7 @@ $.extend(DocumentElement.prototype, { var DocumentNodeElement = function(wlxmlNode, canvas) { DocumentElement.call(this, wlxmlNode, canvas); wlxmlNode.setData('canvasElement', this); - if(this.init) { - this.init(); - } - + this.init(this.$element); }; @@ -126,8 +106,7 @@ $.extend(DocumentNodeElement.prototype, { wrapper.append(widgetsContainer, contentContainer); widgetsContainer.find('*').add(widgetsContainer).attr('tabindex', -1); - this.$element = wrapper; - this.displayAs(this.defaultDisplayStyle); + return wrapper; }, _container: function() { return this.dom().children('[document-element-content]'); @@ -182,7 +161,7 @@ $.extend(DocumentNodeElement.prototype, { // } // }) this.dom().css('display', what); - this._container().css('display', what); + this._container().css('display', what); } }); @@ -202,9 +181,10 @@ DocumentTextElement.prototype = Object.create(DocumentElement.prototype); $.extend(DocumentTextElement.prototype, { createDOM: function() { - this.$element = $('
') + var dom = $('
') .attr('document-text-element', '') .text(this.wlxmlNode.getText() || utils.unicode.ZWS); + return dom; }, detach: function() { this.dom().detach(); @@ -268,35 +248,11 @@ $.extend(DocumentTextElement.prototype, { }); -var SpanElement = function() { - DocumentNodeElement.apply(this, Array.prototype.slice.call(arguments, 0)); -}; -SpanElement.prototype = $.extend(Object.create(DocumentNodeElement.prototype), { - defaultDisplayStyle: 'inline', - init: function() { - if(this.containsBlock()) { - this.displayAsBlock(); - } else { - this.displayInline(); - } - }, - refresh: function() { - this.init(); - } -}); - -var elements = { - span: SpanElement -}; - return { DocumentElement: DocumentElement, DocumentNodeElement: DocumentNodeElement, - DocumentTextElement: DocumentTextElement, //, - factoryForTag: function(tagName) { - return elements[tagName] || DocumentNodeElement; - } + DocumentTextElement: DocumentTextElement }; }); \ No newline at end of file