X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/edd85d12e3446e6d30ecb3b67519d53933a3b621..b554451bd332b417a9304fd60fafe116220a9ca4:/modules/documentCanvas/canvas.js diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index dc64cac..eb0fd0b 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -9,13 +9,14 @@ define([ 'use strict'; var Canvas = function(xml) { - this.xml = xml; this.dom = $(template); - - this.content = this.dom.find('#rng-module-documentCanvas-content') - - - this.content.html(transformations.fromXML.getHTMLTree(xml)); + this.content = this.dom.find('#rng-module-documentCanvas-content'); + this.setXML(xml); +} + +Canvas.prototype.setXML = function(xml) { + this.xml = xml; + this.content.html(transformations.fromXML.getHTMLTree(xml)); } Canvas.prototype.toXML = function() { @@ -35,6 +36,14 @@ Canvas.prototype.getNode = function(desc) { return toret; } +Canvas.prototype.getPreviousNode = function(options) { + var element = $(this.content.find('#' + options.node.id).get(0)); + var prev = element.prev() + if(prev.length === 0) + prev = element.parent(); + return new wlxmlNode.Node(prev); +} + Canvas.prototype._createNode = function(wlxmlTag, wlxmlClass) { var toBlock = ['div', 'document', 'section', 'header']; var htmlTag = _.contains(toBlock, wlxmlTag) ? 'div' : 'span'; @@ -48,8 +57,11 @@ Canvas.prototype._createNode = function(wlxmlTag, wlxmlClass) { Canvas.prototype.insertNode = function(options) { var element = $(this.content.find('#' + options.context.id).get(0)); - if(options.place == 'after') - element[options.place](this._createNode(options.tag, options.klass)); + if(options.place == 'after') { + var node = this._createNode(options.tag, options.klass); + element[options.place](node); + return node; + } else if(options.place == 'wrapText') { var elementContents = element.contents(); if(elementContents.length !== 1 || elementContents.get(0).nodeType != 3) @@ -102,6 +114,13 @@ Canvas.prototype.splitNode = function(options) { newNode.append(node) }); nodeToSplit.after(newNode); + return newNode; +} + +Canvas.prototype.removeNode = function(options) { + var toRemove = $(this.content.find('#' + options.node.id).get(0)); + toRemove.remove(); + } Canvas.prototype.createList = function(options) {