return toret;\r
}\r
\r
+Canvas.prototype.getPreviousNode = function(options) {\r
+ var element = $(this.content.find('#' + options.node.id).get(0));\r
+ var prev = element.prev()\r
+ if(prev.length === 0)\r
+ prev = element.parent();\r
+ return new wlxmlNode.Node(prev);\r
+}\r
+\r
Canvas.prototype._createNode = function(wlxmlTag, wlxmlClass) {\r
var toBlock = ['div', 'document', 'section', 'header'];\r
var htmlTag = _.contains(toBlock, wlxmlTag) ? 'div' : 'span';\r
\r
Canvas.prototype.insertNode = function(options) {\r
var element = $(this.content.find('#' + options.context.id).get(0));\r
- if(options.place == 'after')\r
- element[options.place](this._createNode(options.tag, options.klass));\r
+ if(options.place == 'after') {\r
+ var node = this._createNode(options.tag, options.klass);\r
+ element[options.place](node);\r
+ return node;\r
+ }\r
else if(options.place == 'wrapText') {\r
var elementContents = element.contents();\r
if(elementContents.length !== 1 || elementContents.get(0).nodeType != 3)\r
assert.equal(header.tag, 'header');\r
assert.equal(header.klass, 'some-class');\r
});\r
+ \r
+ test('getting previous node', function() {\r
+ var c = new canvas.Canvas('<section><div class="some.class">Div 1</div><div class="some.other.class">Div 2</div></section>');\r
+ var secondDiv = c.getNode({tag: 'div'})[1];\r
+ var firstDiv = c.getPreviousNode({node: secondDiv});\r
+ assert.equal(firstDiv.klass, 'some-class');\r
+ })\r
+ \r
+ test('pervious node of node without "previous siblings" is its parent', function() {\r
+ var c = new canvas.Canvas('<section><div class="some.class">Div 1</div></section>');\r
+ var div = c.getNode({tag: 'div'})[0];\r
+ var section = c.getPreviousNode({node: div});\r
+ assert.equal(section.tag, 'section');\r
+ })\r
\r
test('inserting after', function() {\r
var c = new canvas.Canvas('<section><header>Header 1</header></section>');\r
<div class="list.item">a cat</div>\\r
</div>\\r
</section>');\r
- \r
+\r
});\r
});\r
\r