all files / editor-manager/plugin/ insert-methods.js

100% Statements 25/25
100% Branches 8/8
100% Functions 7/7
100% Lines 25/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38     100× 100× 100× 98×   100×   452× 452× 452×   395× 395× 395× 485×   395× 395×   952×            
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var InsertMethods = (function () {
        function InsertMethods() {
        }
        InsertMethods.WrapBefore = function (textNode, parentNode, isAfter) {
            parentNode.innerText = textNode.textContent;
            (!isAfter) ? this.AppendBefore(parentNode, textNode) : this.AppendBefore(parentNode, textNode, true);
            if (textNode.parentNode) {
                textNode.parentNode.removeChild(textNode);
            }
            return parentNode.childNodes[0];
        };
        InsertMethods.Wrap = function (childNode, parentNode) {
            this.AppendBefore(parentNode, childNode);
            parentNode.appendChild(childNode);
            return childNode;
        };
        InsertMethods.unwrap = function (node) {
            var parent = node.parentNode;
            var child = [];
            for (; node.firstChild; null) {
                child.push(parent.insertBefore(node.firstChild, node));
            }
            parent.removeChild(node);
            return child;
        };
        InsertMethods.AppendBefore = function (textNode, parentNode, isAfter) {
            return (parentNode.parentNode) ? ((!isAfter) ? parentNode.parentNode.insertBefore(textNode, parentNode)
                : parentNode.parentNode.insertBefore(textNode, parentNode.nextSibling)) :
                parentNode;
        };
        return InsertMethods;
    }());
    exports.InsertMethods = InsertMethods;
});