all files / editor-manager/plugin/ isformatted.js

100% Statements 93/93
100% Branches 87/87
100% Functions 17/17
100% Lines 93/93
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200     1568× 1568× 326×   1242×   1568× 5236×   1568×   3994×   494×   265×   257×   106×   175×   125×   513×   452×   768×   511×     324×     8507× 8507× 442×   8065×       8063×     8447× 8447× 212×   8235×       8233×     8578× 8578× 23×   8555×     105×     8450×     8693× 8693×   8685×     45×     8640×     8874× 8874× 15×     8859×     8802× 8802× 20×     8782×     513× 513×   22×     491×     511× 511×   28×     483×     768× 768×   67×     701×     452× 452×   15×     437×     8722× 8722×     8719×                                                              
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var IsFormatted = (function () {
        function IsFormatted() {
        }
        IsFormatted.prototype.getFormattedNode = function (node, format, endNode) {
            var parentNode = this.getFormatParent(node, format, endNode);
            if (parentNode !== null && parentNode !== endNode) {
                return parentNode;
            }
            return null;
        };
        IsFormatted.prototype.getFormatParent = function (node, format, endNode) {
            do {
                node = node.parentNode;
            } while (node && (node !== endNode) && !this.isFormattedNode(node, format));
            return node;
        };
        IsFormatted.prototype.isFormattedNode = function (node, format) {
            switch (format) {
                case 'bold':
                    return IsFormatted.isBold(node);
                case 'italic':
                    return IsFormatted.isItalic(node);
                case 'underline':
                    return IsFormatted.isUnderline(node);
                case 'strikethrough':
                    return IsFormatted.isStrikethrough(node);
                case 'superscript':
                    return IsFormatted.isSuperscript(node);
                case 'subscript':
                    return IsFormatted.isSubscript(node);
                case 'fontcolor':
                    return this.isFontColor(node);
                case 'fontname':
                    return this.isFontName(node);
                case 'fontsize':
                    return this.isFontSize(node);
                case 'backgroundcolor':
                    return this.isBackgroundColor(node);
                case 'inlinecode':
                    return IsFormatted.isCode(node);
                default:
                    return false;
            }
        };
        IsFormatted.isBold = function (node) {
            var validTags = ['strong', 'b'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else if (this.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                node.style && node.style.fontWeight === 'bold') {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isItalic = function (node) {
            var validTags = ['em', 'i'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else if (this.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                node.style && node.style.fontStyle === 'italic') {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isUnderline = function (node) {
            var validTags = ['u'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else if (this.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                node.style && (node.style.textDecoration === 'underline' ||
                node.style.textDecorationLine === 'underline')) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isStrikethrough = function (node) {
            var validTags = ['del', 'strike', 's'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else if (this.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                node.style && (node.style.textDecoration === 'line-through' ||
                node.style.textDecorationLine === 'line-through')) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isSuperscript = function (node) {
            var validTags = ['sup'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isSubscript = function (node) {
            var validTags = ['sub'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.prototype.isFontColor = function (node) {
            var color = node.style && node.style.color;
            if (IsFormatted.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                color !== null && color !== '' && color !== undefined) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.prototype.isBackgroundColor = function (node) {
            var backColor = node.style && node.style.backgroundColor;
            if (IsFormatted.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                backColor !== null && backColor !== '' && backColor !== undefined) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.prototype.isFontSize = function (node) {
            var size = node.style && node.style.fontSize;
            if (IsFormatted.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                size !== null && size !== '' && size !== undefined) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.prototype.isFontName = function (node) {
            var name = node.style && node.style.fontFamily;
            if (IsFormatted.inlineTags.indexOf(node.nodeName.toLowerCase()) !== -1 &&
                name !== null && name !== '' && name !== undefined) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.isCode = function (node) {
            var validTags = ['code'];
            if (validTags.indexOf(node.nodeName.toLowerCase()) !== -1) {
                return true;
            }
            else {
                return false;
            }
        };
        IsFormatted.inlineTags = [
            'a',
            'abbr',
            'acronym',
            'b',
            'bdo',
            'big',
            'cite',
            'code',
            'dfn',
            'em',
            'font',
            'i',
            'kbd',
            'label',
            'q',
            'samp',
            'small',
            'span',
            'strong',
            'sub',
            'sup',
            'tt',
            'u',
            'var',
            'del'
        ];
        return IsFormatted;
    }());
    exports.IsFormatted = IsFormatted;
});