-Manager.prototype.insertNewNode = function(wlxmlTag, wlxmlClass) {
- var selection = window.getSelection(),
- $anchorNode = $(selection.anchorNode),
- $focusNode = $(selection.focusNode);
-
-
- if(!selection.isCollapsed && $anchorNode.parent()[0] === $focusNode.parent()[0]) {
- var textNodeIdx,
- parent = $anchorNode.parent(),
- parentContents = parent.contents(),
- offsetStart = selection.anchorOffset,
- offsetEnd = selection.focusOffset;
-
- if(selection.anchorNode === selection.focusNode) {
- if(offsetStart > offsetEnd) {
- var tmp = offsetStart;
- offsetStart = offsetEnd;
- offsetEnd = tmp;
- }
- textNodeIdx = parentContents.index($anchorNode);
- } else {
- if(parentContents.index($anchorNode) > parentContents.index($focusNode)) {
- offsetStart = selection.focusOffset;
- offsetEnd = selection.anchorOffset;
- }
- textNodeIdx = [parentContents.index($anchorNode), parentContents.index($focusNode)];
- }
-
- var wrapper = canvasNode.create({tag: wlxmlTag, klass: wlxmlClass});
- this.canvas.nodeWrap({inside: canvasNode.create(parent),
- _with: wrapper,
- offsetStart: offsetStart,
- offsetEnd: offsetEnd,
- textNodeIdx: textNodeIdx
- });
- this.selectNode(wrapper, {movecaret: 'end'});
- }
-
-
-};
-