all files / document-editor-container/helper/ bullet-list-helper.js

84.87% Statements 101/119
56.86% Branches 29/51
72.22% Functions 13/18
84.87% Lines 101/119
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 201 202 203 204     602×     602× 602×     602× 602× 86×   602×     602× 86× 86×   602× 602× 602× 602× 602×   430×     430× 430× 430×     430× 430× 1290× 1290× 1290×     1290× 430×   1290× 1290×   430× 430×   86×     86× 86× 86×     86× 86× 86×     86× 86× 86× 86× 86×                                                 30× 30× 30× 30×                                                     39× 39× 39×       34× 34× 34×   34× 34×     39×                                          
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BulletListHelper = (function () {
        function BulletListHelper() {
        }
        BulletListHelper.createBulletListTag = function (ulTag, iconCss, isNone, localObj) {
            var liTag = ej2_base_1.createElement('li', {
                className: 'e-de-floating-menuitem e-de-floating-bullet-menuitem-md e-de-list-items e-de-list-item-size'
            });
            ej2_base_1.updateCSSText(liTag, 'display:block;');
            var liInnerDiv = ej2_base_1.createElement('div', {
                className: 'e-de-bullet-list-header-presetmenu'
            });
            var spanDiv = ej2_base_1.createElement('div');
            if (isNone) {
                ej2_base_1.updateCSSText(spanDiv, 'font-size:8px;text-align:center;top:8px;line-height:normal;');
            }
            var span = ej2_base_1.createElement('span', {
                className: !isNone ? iconCss : ''
            });
            if (isNone) {
                ej2_base_1.updateCSSText(liInnerDiv, 'display:inline-table;');
                span.textContent = localObj.getConstant('None');
            }
            spanDiv.appendChild(span);
            liInnerDiv.appendChild(spanDiv);
            liTag.appendChild(liInnerDiv);
            ulTag.appendChild(liTag);
            return liTag;
        };
        BulletListHelper.createNumberListTag = function (ulTag, text1, text2, text3) {
            var liTag = ej2_base_1.createElement('li', {
                className: 'e-de-floating-menuitem e-de-floating-menuitem-md e-de-list-items e-de-list-item-size'
            });
            ej2_base_1.updateCSSText(liTag, 'display:block;');
            ulTag.appendChild(liTag);
            var liInnerDiv = ej2_base_1.createElement('div', {
                className: 'e-de-list-header-presetmenu'
            });
            var values = [text1, text2, text3];
            for (var i = 0; i < values.length; i++) {
                var div = ej2_base_1.createElement('div');
                div.textContent = values[parseInt(i.toString(), 10)];
                var span = ej2_base_1.createElement('span', {
                    className: 'e-de-list-line'
                });
                if (i === 2) {
                    span.textContent = ' ';
                }
                div.appendChild(span);
                liInnerDiv.appendChild(div);
            }
            liTag.appendChild(liInnerDiv);
            return liTag;
        };
        BulletListHelper.createNumberNoneListTag = function (ulTag, localObj) {
            var liTag = ej2_base_1.createElement('li', {
                className: 'e-de-floating-menuitem e-de-floating-menuitem-md e-de-list-items e-de-list-item-size'
            });
            ej2_base_1.updateCSSText(liTag, 'display:block;');
            ulTag.appendChild(liTag);
            var liInnerDiv = ej2_base_1.createElement('div', {
                className: 'e-de-list-header-presetmenu'
            });
            ej2_base_1.updateCSSText(liInnerDiv, 'position:relative;left:11px;top:13px;');
            var innerDiv = ej2_base_1.createElement('div');
            var span = ej2_base_1.createElement('span', {
                className: 'e-de-bullets'
            });
            span.textContent = localObj.getConstant('None');
            innerDiv.appendChild(span);
            liInnerDiv.appendChild(innerDiv);
            liTag.appendChild(liInnerDiv);
            return liTag;
        };
        BulletListHelper.updateSelectedBulletListType = function (listText, bulletElements) {
            var _a;
            var bulletMap = (_a = {},
                _a[String.fromCharCode(61623)] = 'dot',
                _a[String.fromCharCode(61551) + String.fromCharCode(32)] = 'circle',
                _a[String.fromCharCode(61607)] = 'square',
                _a[String.fromCharCode(61558)] = 'flower',
                _a[String.fromCharCode(61656)] = 'arrow',
                _a[String.fromCharCode(61692)] = 'tick',
                _a);
            var elementKey = bulletMap[listText];
            if (bulletElements[elementKey]) {
                bulletElements[elementKey].classList.add('de-list-item-selected');
            }
        };
        BulletListHelper.updateSelectedNumberedListType = function (listText, numberElements) {
            var patternMap = {
                'Arabic': 'number',
                'UpRoman': 'uproman',
                'UpLetter': 'upletter',
                'LowLetter': 'lowletter',
                'LowRoman': 'lowroman'
            };
            var elementKey = patternMap[listText];
            Iif (numberElements[elementKey]) {
                numberElements[elementKey].classList.add('de-list-item-selected');
            }
        };
        BulletListHelper.removeSelectedList = function (elements) {
            var className = 'de-list-item-selected';
            for (var key in elements) {
                Eif (Object.prototype.hasOwnProperty.call(elements, key)) {
                    var element = elements[key];
                    Eif (element) {
                        element.classList.remove(className);
                    }
                }
            }
        };
        BulletListHelper.getLevelFormatNumber = function (documentEditor) {
            var numberFormat = '%';
            var levelNumber = documentEditor.selectionModule.paragraphFormat.listLevelNumber;
            numberFormat = numberFormat + (((levelNumber <= 0) ? 0 : levelNumber) + 1) + '.';
            return numberFormat;
        };
        BulletListHelper.applyBulletStyle = function (documentEditor, style, appliedBulletStyle) {
            Iif (style === 'none') {
                BulletListHelper.clearList(documentEditor);
                return;
            }
            var bulletStyle = null;
            for (var key in BulletListHelper.BULLET_STYLES) {
                Eif (Object.prototype.hasOwnProperty.call(BulletListHelper.BULLET_STYLES, key)) {
                    var s = BulletListHelper.BULLET_STYLES[key];
                    Eif (s.style === style) {
                        bulletStyle = s;
                        break;
                    }
                }
            }
            Eif (bulletStyle && !documentEditor.isReadOnly && documentEditor.editorModule) {
                appliedBulletStyle.value = style;
                documentEditor.editorModule.applyBullet(bulletStyle.char, bulletStyle.font);
                setTimeout(function () {
                    documentEditor.focusIn();
                }, 30);
            }
        };
        BulletListHelper.clearList = function (documentEditor) {
            Eif (!documentEditor.isReadOnly && documentEditor.editorModule) {
                documentEditor.editorModule.clearList();
                setTimeout(function () {
                    documentEditor.focusIn();
                }, 30);
            }
        };
        BulletListHelper.applyNumbering = function (documentEditor, pattern, appliedNumberingStyle) {
            if (!documentEditor.isReadOnly && documentEditor.editorModule) {
                appliedNumberingStyle.value = pattern.toLowerCase();
                var format = BulletListHelper.getLevelFormatNumber(documentEditor);
                documentEditor.editorModule.applyNumbering(format, pattern);
                setTimeout(function () {
                    documentEditor.focusIn();
                }, 30);
            }
        };
        BulletListHelper.getCurrentListPattern = function (documentEditor) {
            var levelPattern = 'None';
            Eif (!ej2_base_1.isNullOrUndefined(documentEditor.selectionModule.paragraphFormat)) {
                if (ej2_base_1.isNullOrUndefined(documentEditor.selectionModule.paragraphFormat.listId) ||
                    documentEditor.selectionModule.paragraphFormat.listId === -1) {
                    levelPattern = 'None';
                }
                else {
                    var list = documentEditor.documentHelper.getListById(documentEditor.selectionModule.paragraphFormat.listId);
                    var abstractList = documentEditor.documentHelper.getAbstractListById(list.abstractListId);
                    var startParagraph = documentEditor.selectionModule.isForward ?
                        documentEditor.selectionModule.start.paragraph : documentEditor.selectionModule.end.paragraph;
                    var level = abstractList.levels[startParagraph.paragraphFormat.listFormat.listLevelNumber];
                    levelPattern = level.listLevelPattern;
                }
            }
            return levelPattern;
        };
        BulletListHelper.getCurrentListText = function (documentEditor) {
            if (ej2_base_1.isNullOrUndefined(documentEditor.selectionModule.paragraphFormat.listId) ||
                documentEditor.selectionModule.paragraphFormat.listId === -1) {
                return documentEditor.selectionModule.paragraphFormat.listText;
            }
            else {
                var startParagraph = documentEditor.selectionModule.isForward ?
                    documentEditor.selectionModule.start.paragraph : documentEditor.selectionModule.end.paragraph;
                return startParagraph.paragraphFormat.listFormat.listLevel.numberFormat;
            }
        };
        BulletListHelper.BULLET_STYLES = {
            DOT: { style: 'dot', char: String.fromCharCode(61623), font: 'Symbol' },
            CIRCLE: { style: 'circle', char: String.fromCharCode(61551) + String.fromCharCode(32), font: 'Symbol' },
            SQUARE: { style: 'square', char: String.fromCharCode(61607), font: 'Wingdings' },
            FLOWER: { style: 'flower', char: String.fromCharCode(61558), font: 'Wingdings' },
            ARROW: { style: 'arrow', char: String.fromCharCode(61656), font: 'Wingdings' },
            TICK: { style: 'tick', char: String.fromCharCode(61692), font: 'Wingdings' }
        };
        return BulletListHelper;
    }());
    exports.BulletListHelper = BulletListHelper;
});