X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/264005bc6b4f629d4ef7d32c0aa626e3da7afbc7..39625b37b8cbd892677f7e8bf3ab5f8b065a1fd0:/src/editor/modules/documentCanvas/canvas/documentElement.js?ds=inline diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index b5269ca..1da7b3e 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -1,68 +1,38 @@ define([ 'libs/jquery', 'libs/underscore', -'modules/documentCanvas/canvas/utils', -'modules/documentCanvas/canvas/widgets', -'modules/documentCanvas/canvas/wlxmlManagers' -], function($, _, utils, widgets, wlxmlManagers) { +'modules/documentCanvas/canvas/utils' +], 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(htmlElement, canvas) { - if(arguments.length === 0) { - return; - } +var DocumentElement = function(wlxmlNode, canvas) { + this.wlxmlNode = wlxmlNode; this.canvas = canvas; - this._setupDOMHandler(htmlElement); -}; - -var elementTypeFromWlxmlNode = function(wlxmlNode) { - return wlxmlNode.nodeType === Node.TEXT_NODE ? DocumentTextElement : DocumentNodeElement; + this.$element = this.createDOM(); + this.$element.data('canvas-element', this); }; -$.extend(DocumentElement, { - create: function(node, canvas) { - return elementTypeFromWlxmlNode(node).create(node, canvas); - }, - - fromHTMLElement: function(htmlElement, canvas) { - var $element = $(htmlElement); - if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) { - return DocumentNodeElement.fromHTMLElement(htmlElement, canvas); - } - if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) { - return DocumentTextElement.fromHTMLElement(htmlElement, canvas); - } - return undefined; - } -}); - $.extend(DocumentElement.prototype, { - _setupDOMHandler: function(htmlElement) { - this.$element = $(htmlElement); + refreshPath: function() { + this.parents().forEach(function(parent) { + parent.refresh(); + }); + this.refresh(); }, - bound: function() { - return $.contains(document.documentElement, this.dom()[0]); + refresh: function() { + // noop }, dom: function() { return this.$element; }, - data: function() { - var dom = this.dom(), - args = Array.prototype.slice.call(arguments, 0); - if(args.length === 2 && args[1] === undefined) { - return dom.removeData(args[0]); - } - return dom.data.apply(dom, arguments); - }, parent: function() { var parents = this.$element.parents('[document-node-element]'); if(parents.length) { - return DocumentElement.fromHTMLElement(parents[0], this.canvas); + return this.canvas.getDocumentElement(parents[0]); } return null; }, @@ -81,29 +51,6 @@ $.extend(DocumentElement.prototype, { return other && (typeof other === typeof this) && other.dom()[0] === this.dom()[0]; }, - markAsCurrent: function() { - this.canvas.markAsCurrent(this); - }, - - getVerticallyFirstTextElement: function() { - var toret; - this.children().some(function(child) { - if(!child.isVisible()) { - return false; // continue - } - if(child instanceof DocumentTextElement) { - toret = child; - return true; // break - } else { - toret = child.getVerticallyFirstTextElement(); - if(toret) { - return true; // break - } - } - }); - return toret; - }, - getPreviousTextElement: function(includeInvisible) { return this.getNearestTextElement('above', includeInvisible); }, @@ -118,100 +65,74 @@ $.extend(DocumentElement.prototype, { return this.canvas.getDocumentElement(utils.nearestInDocumentOrder(selector, direction, this.dom()[0])); }, - isVisible: function() { - return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata'; - }, + trigger: function() { + //this.canvas.bus.trigger() + } - isInsideList: function() { - return this.parents().some(function(parent) { - return parent.is('list'); - }); - }, - exec: function(method) { - var manager = this.data('_wlxmlManager'); - if(manager[method]) { - return manager[method].apply(manager, Array.prototype.slice.call(arguments, 1)); - } - } }); // DocumentNodeElement represents an element node from WLXML document rendered inside Canvas -var DocumentNodeElement = function(htmlElement, canvas) { - DocumentElement.call(this, htmlElement, canvas); +var DocumentNodeElement = function(wlxmlNode, canvas) { + DocumentElement.call(this, wlxmlNode, canvas); + wlxmlNode.setData('canvasElement', this); + this.init(this.$element); }; -$.extend(DocumentNodeElement, { - create: function(wlxmlNode, canvas) { - return this.fromHTMLElement(this.createDOM(wlxmlNode, canvas)[0], canvas); - }, - - fromHTMLElement: function(htmlElement, canvas) { - return new this(htmlElement, canvas); - }, - - createDOM: function(wlxmlNode, canvas) { - var dom = $('