X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/8e6255bf612a7d33e1f1c97dd293db6f34949ef9..7b4405539ac7c11a11b5259b4f968e1289f0b2a7:/modules/documentCanvas/canvas.js diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 20c286a..80d3915 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -15,8 +15,8 @@ var Canvas = function(xml) { } Canvas.prototype.setXML = function(xml) { - this.xml = xml; - this.content.html(transformations.fromXML.getHTMLTree(xml)); + this.xml = $.trim(xml); + this.content.html(transformations.fromXML.getHTMLTree(this.xml)); } Canvas.prototype.toXML = function() { @@ -36,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'; @@ -49,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) @@ -106,6 +117,12 @@ Canvas.prototype.splitNode = function(options) { return newNode; } +Canvas.prototype.removeNode = function(options) { + var toRemove = $(this.content.find('#' + options.node.id).get(0)); + toRemove.remove(); + +} + Canvas.prototype.createList = function(options) { var element1 = $(this.content.find('#' + options.start.id).get(0)); var element2 = $(this.content.find('#' + options.end.id).get(0)); @@ -130,23 +147,42 @@ Canvas.prototype.createList = function(options) { else { $node = $(node); } - $node.attr('wlxml-class', 'list.item'); + $node.attr('wlxml-class', 'item'); nodesToWrap.push($node); } if(node.isSameNode(element2.get(0))) - return; + return false; }); - var list = this._createNode('div', 'list'); + var list = this._createNode('div', 'list-items'); element1.before(list); nodesToWrap.forEach(function(node) { node.remove(); list.append(node); }); +} + +Canvas.prototype.removeList = function(options) { + var pointerElement = $(this.content.find('#' + options.pointer.id)); + var listElement = options.pointer.klass === 'list-items' ? pointerElement : + pointerElement.parent('[wlxml-class="list-items"][wlxml-tag]'); + listElement.find('[wlxml-class=item]').each(function() { + $(this).attr('wlxml-class', ''); + });; + listElement.children().unwrap(); - +} + +Canvas.prototype.insideList = function(options) { + if(options.pointer) { + if(options.pointer.klass === 'list-items' || options.pointer.klass === 'item') + return true; + var pointerElement = $(this.content.find('#' + options.pointer.id)); + return pointerElement.parents('list-items').length > 0; + } + return false; }