all files / rich-text-editor/actions/ html-editor.js

95.98% Statements 645/672
90.29% Branches 530/587
100% Functions 41/41
95.98% Lines 644/671
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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088   1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763×   3507× 1745×   1762×   1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762×   1762×   1762×     1762×     1762×     1762× 272×   1762× 1762×   1762×   1838× 1838×   1763×     1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763× 1763×   1775× 23× 23×     1752× 1752×     696× 696× 696×   594× 594× 594×     2357× 2357× 287×   13×       20× 20× 20×       20× 20× 20×   14×             13× 13×       13× 13×       84× 20× 13×       11× 11×             20×       118× 118×   118× 118× 118×       118× 118×   49×   49×       118×     118× 118× 118× 52× 52×   52×   52× 52× 52× 52×   12×   11×   11×     20×   20×                   52× 52× 44× 44× 39×     52×           52×             609× 609×       609×   609× 609× 609×   606× 556× 556× 556×   606× 16× 16× 13× 13× 13×   12× 12× 12× 12×                                         16×   606×     191× 191× 190× 190× 190× 190×           190× 190×       606× 17× 17× 17× 17× 17× 17× 10×   17×                                           606×     11× 11× 11× 11× 11× 11×   11×   606×   17× 17× 17× 17× 42×       11×   17× 17× 17× 17× 32×       13×   10× 10× 10×         10× 10×           556× 556× 556×     556× 556×   556×       13×       11× 11×                       10× 10×   10×                                                 556× 556× 556× 556×     12× 12×                         12× 12×   12×                                                                     12× 12× 12× 12× 12× 12×   12×         23× 45× 22×     23×     23×         30× 30× 14×   13× 13× 13× 13× 13× 13× 13× 13× 21×     17× 17× 17× 17× 88× 28×     60× 60×     17× 13×           13× 13× 13× 13× 13× 13× 21× 21× 21× 64× 15×       49×     21×   13× 13×   13× 13×             191× 191× 191× 191× 191× 191× 191× 191× 191×                           1127× 1127× 1127× 1127× 1127× 1127× 1127× 1127× 1127× 1115× 182×   181×   181× 181× 181× 181×   182× 58×       182×       182× 14×       182× 15×       182× 79×           933× 933× 933×   790× 790× 782×   790× 790×   933×   15× 15×     35×     35×           67×     67×   35×     35×   57×     57×   59×     59×   40× 40×   20× 20×     51×         37× 37×         490× 490×         12×                     1763× 82×     1681×     1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762× 1762×   1763× 1763× 1763× 1763× 1746×           1746×     17×   1763× 10×   1763× 1751×   1763× 89×   89×     1763×   170× 11×   170×       32823×   30× 30× 27×     107×   458×                   10× 24× 24×   22× 13× 13× 10×       13× 13×                
define(["require", "exports", "../base/constant", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../formatter/html-formatter", "../base/enum", "../base/classes", "./html-toolbar-status", "../renderer/iframe-content-renderer", "../renderer/content-renderer", "../../selection/selection", "../../editor-manager/plugin/inserthtml", "../base/util", "../../common/util", "./xhtml-validation", "./../../common/constant", "../base/constant"], function (require, exports, events, ej2_base_1, ej2_base_2, html_formatter_1, enum_1, classes, html_toolbar_status_1, iframe_content_renderer_1, content_renderer_1, selection_1, inserthtml_1, util_1, util_2, xhtml_validation_1, constant_1, CONSTANT) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HtmlEditor = (function () {
        function HtmlEditor(parent, serviceLocator) {
            this.rangeCollection = [];
            this.isImageDelete = false;
            this.parent = parent;
            this.locator = serviceLocator;
            this.renderFactory = this.locator.getService('rendererFactory');
            this.xhtmlValidation = new xhtml_validation_1.XhtmlValidation(parent);
            this.addEventListener();
            this.isDestroyed = false;
            this.isCopyAll = false;
        }
        HtmlEditor.prototype.destroy = function () {
            if (this.isDestroyed) {
                return;
            }
            if (this.clickTimeout) {
                clearTimeout(this.clickTimeout);
                this.clickTimeout = null;
            }
            this.removeEventListener();
            this.locator = null;
            this.contentRenderer = null;
            this.renderFactory = null;
            this.toolbarUpdate = null;
            this.nodeSelectionObj = null;
            this.isCopyAll = null;
            if (this.rangeCollection.length > 0) {
                this.rangeCollection = [];
            }
            if (this.rangeElement) {
                this.rangeElement = null;
            }
            Iif (this.oldRangeElement) {
                this.oldRangeElement = null;
            }
            Iif (this.deleteRangeElement) {
                this.deleteRangeElement = null;
            }
            Iif (this.deleteOldRangeElement) {
                this.deleteOldRangeElement = null;
            }
            if (this.saveSelection) {
                this.saveSelection = null;
            }
            Eif (this.xhtmlValidation) {
                this.xhtmlValidation = null;
            }
            this.isDestroyed = true;
        };
        HtmlEditor.prototype.sanitizeHelper = function (value) {
            value = util_1.sanitizeHelper(value, this.parent);
            return value;
        };
        HtmlEditor.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.nodeSelectionObj = new selection_1.NodeSelection(this.parent.inputElement);
            this.parent.on(events.initialLoad, this.instantiateRenderer, this);
            this.parent.on(events.htmlToolbarClick, this.onToolbarClick, this);
            this.parent.on(events.keyDown, this.onKeyDown, this);
            this.parent.on(events.keyUp, this.onKeyUp, this);
            this.parent.on(events.initialEnd, this.render, this);
            this.parent.on(events.modelChanged, this.onPropertyChanged, this);
            this.parent.on(events.destroy, this.destroy, this);
            this.parent.on(events.selectAll, this.selectAll, this);
            this.parent.on(events.selectRange, this.selectRange, this);
            this.parent.on(events.getSelectedHtml, this.getSelectedHtml, this);
            this.parent.on(events.selectionSave, this.onSelectionSave, this);
            this.parent.on(events.selectionRestore, this.onSelectionRestore, this);
            this.parent.on(events.readOnlyMode, this.updateReadOnly, this);
            this.parent.on(events.paste, this.onPaste, this);
            this.parent.on(events.tableclass, this.isTableClassAdded, this);
            this.parent.on(events.onHandleFontsizeChange, this.onHandleFontsizeChange, this);
        };
        HtmlEditor.prototype.updateReadOnly = function () {
            if (this.parent.readonly) {
                ej2_base_1.attributes(this.parent.contentModule.getEditPanel(), { contenteditable: 'false' });
                ej2_base_1.addClass([this.parent.element], classes.CLS_RTE_READONLY);
            }
            else {
                ej2_base_1.attributes(this.parent.contentModule.getEditPanel(), { contenteditable: 'true' });
                ej2_base_1.removeClass([this.parent.element], classes.CLS_RTE_READONLY);
            }
        };
        HtmlEditor.prototype.onSelectionSave = function () {
            var currentDocument = this.contentRenderer.getDocument();
            var range = this.nodeSelectionObj.getRange(currentDocument);
            this.saveSelection = this.nodeSelectionObj.save(range, currentDocument);
        };
        HtmlEditor.prototype.onSelectionRestore = function (e) {
            this.parent.isBlur = false;
            Eif (ej2_base_1.isNullOrUndefined(e.items) || e.items) {
                this.saveSelection.restore();
            }
        };
        HtmlEditor.prototype.isTableClassAdded = function () {
            var tableElement = this.parent.inputElement.querySelectorAll('table');
            for (var i = 0; i < tableElement.length; i++) {
                if (!tableElement[i].classList.contains('e-rte-table') && !tableElement[i].classList.contains('e-rte-paste-table')
                    && !tableElement[i].classList.contains('e-rte-custom-table')) {
                    tableElement[i].classList.add('e-rte-table');
                }
            }
        };
        HtmlEditor.prototype.onHandleFontsizeChange = function (e) {
            var keyboardArgs = e.args;
            var args = { name: 'dropDownSelect' };
            args.item = {
                command: 'Font',
                subCommand: 'FontSize'
            };
            var items = this.parent.fontSize.items;
            var activeElem;
            if (this.parent.toolbarModule && this.parent.toolbarModule.dropDownModule &&
                this.parent.toolbarModule.dropDownModule.fontSizeDropDown && !ej2_base_2.isNullOrUndefined(this.parent.toolbarModule.dropDownModule.fontSizeDropDown.activeElem[0].textContent) && this.parent.toolbarModule.dropDownModule.fontSizeDropDown.activeElem[0].textContent !== '') {
                activeElem = this.parent.toolbarModule.dropDownModule.fontSizeDropDown.activeElem[0].textContent;
            }
            else {
                var fontSizeValue = void 0;
                var selection = this.parent.contentModule.getDocument().getSelection();
                Eif (selection && selection.focusNode && selection.focusNode.parentElement) {
                    fontSizeValue = document.defaultView.getComputedStyle(selection.focusNode.parentElement, null).getPropertyValue('font-size');
                }
                else {
                    fontSizeValue = this.parent.fontSize.width;
                }
                fontSizeValue = ej2_base_2.isNullOrUndefined(fontSizeValue) ? this.parent.fontSize.width : fontSizeValue;
                var actualTxtFontValues = fontSizeValue.match(/^([\d.]+)(\D+)$/);
                var size_1 = parseInt(actualTxtFontValues[1], 10);
                var unit = actualTxtFontValues[2];
                var defaultFontValues = items[1].value.match(/^([\d.]+)(\D+)$/);
                if (defaultFontValues[2] === unit) {
                    var index = items.findIndex(function (_a) {
                        var value = _a.value;
                        return parseInt(value, 10) >= size_1;
                    });
                    activeElem = items[index].text;
                }
                else {
                    var convertedSize_1 = this.convertFontSize(size_1, unit, defaultFontValues[2]);
                    var index = items.findIndex(function (_a) {
                        var value = _a.value;
                        return parseInt(value, 10) >= convertedSize_1;
                    });
                    activeElem = items[index].text;
                }
            }
            var fontIndex = items.findIndex(function (size) { return size.text === (activeElem === 'Font Size' ? 'Default' : activeElem); });
            if (keyboardArgs.action === 'increase-fontsize' && fontIndex !== -1) {
                if (fontIndex >= items.length - 1) {
                    var fontValues = items[fontIndex].value.match(/^([\d.]+)(\D+)$/);
                    Eif (fontValues) {
                        var size = parseInt(fontValues[1], 10);
                        var unit = fontValues[2];
                        var roundedSize = size % 10 === 0 ? Math.ceil((size + 1) / 10) * 10 : Math.ceil(size / 10) * 10;
                        args.item.value = roundedSize.toLocaleString() + unit;
                        args.item.text = roundedSize.toLocaleString() + ' ' + unit;
                    }
                    this.parent.fontSize.items.push(args.item);
                }
                else {
                    args.item.value = items[fontIndex + 1].value;
                    args.item.text = items[fontIndex + 1].text;
                }
            }
            else if (keyboardArgs.action === 'decrease-fontsize' && fontIndex !== -1 && fontIndex > 0) {
                args.item.value = items[fontIndex - 1].value;
                args.item.text = items[fontIndex - 1].text;
            }
            else {
                Eif (fontIndex >= 0 && fontIndex < items.length && items[fontIndex]) {
                    args.item.value = items[fontIndex].value;
                    args.item.text = items[fontIndex].text;
                }
            }
            this.parent.formatter.process(this.parent, args, keyboardArgs);
        };
        HtmlEditor.prototype.convertFontSize = function (value, originalUnit, targetUnit) {
            Eif (CONSTANT.supportedUnits.indexOf(originalUnit) !== -1 || CONSTANT.supportedUnits.indexOf(targetUnit) !== -1) {
                originalUnit = 'px';
            }
            var convertedValue = value * CONSTANT.conversionFactors[originalUnit][targetUnit];
            return convertedValue;
        };
        HtmlEditor.prototype.onKeyUp = function (e) {
            var args = e.args;
            var restrictKeys = [8, 9, 13, 17, 18, 20, 27, 37, 38, 39, 40, 44, 45, 46, 91,
                112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123];
            var range = this.parent.getRange();
            var regEx = new RegExp('\u200B', 'g');
            var isEmptyNode = range.startContainer === range.endContainer && range.startOffset === range.endOffset &&
                range.startOffset === 1 && range.startContainer.textContent.length === 1 &&
                range.startContainer.textContent.charCodeAt(0) === 8203 &&
                range.startContainer.textContent.replace(regEx, '').length === 0;
            var isMention = false;
            if (range.startContainer === range.endContainer &&
                range.startOffset === range.endOffset && (range.startContainer !== this.parent.inputElement && range.startOffset !== 0)) {
                var mentionStartNode = range.startContainer.nodeType === 3 ?
                    range.startContainer : range.startContainer.childNodes[range.startOffset - 1];
                isMention = args.keyCode === 16 &&
                    mentionStartNode.textContent.charCodeAt(0) === 8203 &&
                    !ej2_base_2.isNullOrUndefined(mentionStartNode.previousSibling) && mentionStartNode.previousSibling.contentEditable === 'false';
            }
            Iif (this.isCopyAll) {
                return;
            }
            var pointer;
            var isRootParent = false;
            if (restrictKeys.indexOf(args.keyCode) < 0 && !args.shiftKey && !args.ctrlKey && !args.altKey && !isEmptyNode && !isMention) {
                pointer = range.startOffset;
                range.startContainer.nodeName === '#text' ? range.startContainer.parentElement !== this.parent.inputElement ? range.startContainer.parentElement.classList.add('currentStartMark')
                    : isRootParent = true : range.startContainer.classList.add('currentStartMark');
                if (range.startContainer.textContent.charCodeAt(0) === 8203) {
                    var previousLength_1 = range.startContainer.textContent.length;
                    var previousRange = range.startOffset;
                    range.startContainer.textContent = range.startContainer.textContent.replace(regEx, '');
                    pointer = previousRange === 0 ? previousRange : previousRange - (previousLength_1 - range.startContainer.textContent.length);
                    this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), range.startContainer, pointer);
                }
                var previousLength = this.parent.inputElement.innerHTML.length;
                var currentLength = this.parent.inputElement.innerHTML.replace(regEx, '').length;
                var focusNode = range.startContainer;
                if (previousLength > currentLength && !isRootParent) {
                    if (focusNode.textContent.trim().length !== 0 && focusNode.previousSibling) {
                        var tempSpan = document.createElement('span');
                        tempSpan.className = 'tempSpan';
                        range.insertNode(tempSpan);
                    }
                    var currentChild = this.parent.inputElement.firstChild;
                    while (!ej2_base_2.isNullOrUndefined(currentChild)) {
                        if (currentChild.nodeName === '#text') {
                            currentChild = currentChild.nextElementSibling;
                            continue;
                        }
                        if (currentChild.textContent.replace(regEx, '').trim().length > 0 && currentChild.textContent.includes('\u200B')) {
                            currentChild.innerHTML = currentChild.innerHTML.replace(regEx, '');
                        }
                        currentChild = currentChild.nextElementSibling;
                    }
                    var tempSpanToRemove = this.parent.inputElement.querySelector('.tempSpan');
                    if (tempSpanToRemove && tempSpanToRemove.previousSibling && focusNode.textContent.trim().length !== 0) {
                        focusNode = tempSpanToRemove.previousSibling;
                        pointer = tempSpanToRemove.previousSibling.textContent.length;
                        var parentElement = tempSpanToRemove.parentNode;
                        parentElement.removeChild(tempSpanToRemove);
                        tempSpanToRemove = null;
                    }
                    var currentChildNode = this.parent.inputElement.querySelector('.currentStartMark').childNodes;
                    if (currentChildNode.length > 1) {
                        for (var i = 0; i < currentChildNode.length; i++) {
                            if (currentChildNode[i].nodeName === '#text' && currentChildNode[i].textContent.length === 0) {
                                ej2_base_1.detach(currentChildNode[i]);
                                i--;
                            }
                            if (!ej2_base_2.isNullOrUndefined(currentChildNode[i]) && focusNode.textContent.replace(regEx, '') === currentChildNode[i].textContent) {
                                pointer = focusNode.textContent.length > 1 ?
                                    (focusNode.textContent === currentChildNode[i].textContent ? pointer :
                                        pointer - (focusNode.textContent.length - focusNode.textContent.replace(regEx, '').length)) :
                                    focusNode.textContent.length;
                                focusNode = currentChildNode[i];
                            }
                        }
                    }
                    else Eif (currentChildNode.length === 1) {
                        Eif (focusNode.textContent.replace(regEx, '') === currentChildNode[0].textContent) {
                            focusNode = currentChildNode[0];
                        }
                    }
                    this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), focusNode, pointer);
                }
                var currentElem = this.parent.inputElement.querySelector('.currentStartMark');
                if (!ej2_base_2.isNullOrUndefined(currentElem)) {
                    currentElem.classList.remove('currentStartMark');
                    if (currentElem.getAttribute('class').trim() === '') {
                        currentElem.removeAttribute('class');
                    }
                }
                Iif (!ej2_base_2.isNullOrUndefined(range.startContainer.previousSibling) && !ej2_base_2.isNullOrUndefined(range.startContainer.previousSibling.parentElement) &&
                    range.startContainer.parentElement === range.startContainer.previousSibling.parentElement &&
                    range.startContainer.previousSibling.textContent.charCodeAt(0) === 8203 &&
                    range.startContainer.previousSibling.textContent.length <= 1) {
                    range.startContainer.previousSibling.textContent = range.startContainer.previousSibling.textContent.replace(regEx, '');
                }
                Iif (range.endContainer.textContent.charCodeAt(range.endOffset) === 8203) {
                    pointer = range.startOffset;
                    range.endContainer.textContent = range.endContainer.textContent.replace(regEx, '');
                    this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), range.startContainer, pointer);
                }
            }
        };
        HtmlEditor.prototype.onKeyDown = function (e) {
            var _this = this;
            Iif (e.args.ctrlKey && e.args.keyCode === 65) {
                this.isCopyAll = true;
            }
            else {
                this.isCopyAll = false;
            }
            var currentRange;
            var args = e.args;
            if (this.parent.inputElement.querySelectorAll('.e-cell-select').length > 1 && (args.keyCode === 8 || args.keyCode === 32 || args.keyCode === 13)) {
                this.tableSelectionKeyAction(e);
                this.parent.autoResize();
                return;
            }
            if (ej2_base_1.Browser.info.name === 'chrome') {
                currentRange = this.parent.getRange();
                this.backSpaceCleanup(e, currentRange);
                this.deleteCleanup(e, currentRange);
            }
            if (args.keyCode === 9 && this.parent.enableTabKey) {
                this.parent.formatter.saveData(e);
                if (!ej2_base_2.isNullOrUndefined(args.target) && ej2_base_1.isNullOrUndefined(ej2_base_1.closest(args.target, '.e-rte-toolbar'))) {
                    var range = this.nodeSelectionObj.getRange(this.contentRenderer.getDocument());
                    var parentNode = this.nodeSelectionObj.getParentNodeCollection(range);
                    if (!((parentNode[0].nodeName === 'LI' || ej2_base_1.closest(parentNode[0], 'li') ||
                        ej2_base_1.closest(parentNode[0], 'table')))) {
                        args.preventDefault();
                        var selection = this.contentRenderer.getDocument().getSelection().getRangeAt(0);
                        var alignmentNodes = this.parent.formatter.editorManager.domNode.blockNodes();
                        if (this.parent.enterKey === 'BR') {
                            if (selection.startOffset !== selection.endOffset && selection.startOffset === 0) {
                                var save = this.nodeSelectionObj.save(range, this.contentRenderer.getDocument());
                                this.parent.formatter.editorManager.domNode.setMarker(save);
                                alignmentNodes = this.parent.formatter.editorManager.domNode.blockNodes();
                                this.parent.formatter.editorManager.domNode.convertToBlockNodes(alignmentNodes, false);
                                this.marginTabAdd(args.shiftKey, alignmentNodes);
                                save = this.parent.formatter.editorManager.domNode.saveMarker(save);
                                save.restore();
                            }
                            else {
                                inserthtml_1.InsertHtml.Insert(this.contentRenderer.getDocument(), '&nbsp;&nbsp;&nbsp;&nbsp;');
                                this.rangeCollection.push(this.nodeSelectionObj.getRange(this.contentRenderer.getDocument()));
                            }
                        }
                        else {
                            if (!args.shiftKey) {
                                if (selection.startOffset !== selection.endOffset && selection.startOffset === 0) {
                                    this.marginTabAdd(args.shiftKey, alignmentNodes);
                                }
                                else {
                                    inserthtml_1.InsertHtml.Insert(this.contentRenderer.getDocument(), '&nbsp;&nbsp;&nbsp;&nbsp;');
                                    this.rangeCollection.push(this.nodeSelectionObj.getRange(this.contentRenderer.getDocument()));
                                }
                            }
                            else Iif (this.rangeCollection.length > 0 &&
                                this.rangeCollection[this.rangeCollection.length - 1].startContainer.textContent.length === 4) {
                                var textCont = this.rangeCollection[this.rangeCollection.length - 1].startContainer;
                                this.nodeSelectionObj.setSelectionText(this.contentRenderer.getDocument(), textCont, textCont, 0, textCont.textContent.length);
                                inserthtml_1.InsertHtml.Insert(this.contentRenderer.getDocument(), document.createTextNode(''));
                                this.rangeCollection.pop();
                            }
                            else {
                                this.marginTabAdd(args.shiftKey, alignmentNodes);
                            }
                        }
                    }
                }
                this.parent.formatter.saveData(e);
            }
            if (e.args.action === 'space' ||
                e.args.action === 'enter' ||
                e.args.keyCode === 13) {
                this.spaceLink(e.args);
                if (this.parent.editorMode === 'HTML' && !this.parent.readonly) {
                    var currentLength = this.parent.getText().trim().replace(/(\r\n|\n|\r|\t)/gm, '').replace(/\u200B/g, '').length;
                    var selectionLength = this.parent.getSelection().length;
                    var totalLength = (currentLength - selectionLength) + 1;
                    Iif (!(this.parent.maxLength === -1 || totalLength <= this.parent.maxLength) &&
                        e.args.keyCode === 13) {
                        e.args.preventDefault();
                        return;
                    }
                    else {
                        this.parent.notify(events.enterHandler, { args: e.args });
                        util_2.scrollToCursor(this.parent.contentModule.getDocument(), this.parent.inputElement);
                    }
                }
            }
            if (e.args.action === 'space') {
                var currentRange_1 = this.parent.getRange();
                var editorValue = currentRange_1.startContainer.textContent.slice(0, currentRange_1.startOffset);
                var orderedList_1 = this.isOrderedList(editorValue);
                var unOrderedList = this.isUnOrderedList(editorValue);
                var hasSplitedText = false;
                if (orderedList_1 || unOrderedList) {
                    hasSplitedText = this.hasMultipleTextNode(currentRange_1);
                }
                if (!hasSplitedText && (orderedList_1 && !unOrderedList || unOrderedList && !orderedList_1)) {
                    var eventArgs_1 = {
                        callBack: null,
                        event: e.args,
                        name: 'keydown-handler'
                    };
                    var actionBeginArgs = {
                        cancel: false,
                        item: { command: 'Lists', subCommand: orderedList_1 ? 'OL' : 'UL' },
                        name: 'actionBegin',
                        originalEvent: e.args,
                        requestType: orderedList_1 ? 'OL' : 'UL'
                    };
                    this.parent.trigger(events.actionBegin, actionBeginArgs, function (actionBeginArgs) {
                        if (!actionBeginArgs.cancel) {
                            _this.parent.formatter.editorManager.observer.notify(constant_1.ON_BEGIN, eventArgs_1);
                            _this.parent.trigger(events.actionComplete, {
                                editorMode: _this.parent.editorMode,
                                elements: _this.parent.formatter.editorManager.domNode.blockNodes(),
                                event: e.args,
                                name: events.actionComplete,
                                range: _this.parent.getRange(),
                                requestType: orderedList_1 ? 'OL' : 'UL'
                            });
                        }
                    });
                }
            }
            if (ej2_base_1.Browser.info.name === 'chrome' && (!ej2_base_1.isNullOrUndefined(this.rangeElement) && !ej2_base_1.isNullOrUndefined(this.oldRangeElement) ||
                !ej2_base_1.isNullOrUndefined(this.deleteRangeElement) && !ej2_base_1.isNullOrUndefined(this.deleteOldRangeElement)) &&
                currentRange.startContainer.parentElement.tagName !== 'TD' && currentRange.startContainer.parentElement.tagName !== 'TH') {
                this.rangeElement = null;
                this.oldRangeElement = null;
                this.deleteRangeElement = null;
                this.deleteOldRangeElement = null;
                Eif (!this.isImageDelete) {
                    args.preventDefault();
                }
                args.preventDefault();
            }
            this.parent.autoResize();
        };
        HtmlEditor.prototype.isOrderedList = function (editorValue) {
            editorValue = editorValue.replace(/\u200B/g, '');
            var olListStartRegex = [/^[1]+[.]+$/, /^[i]+[.]+$/, /^[a]+[.]+$/];
            Eif (!ej2_base_1.isNullOrUndefined(editorValue)) {
                for (var i = 0; i < olListStartRegex.length; i++) {
                    if (olListStartRegex[i].test(editorValue)) {
                        return true;
                    }
                }
            }
            return false;
        };
        HtmlEditor.prototype.isUnOrderedList = function (editorValue) {
            editorValue = editorValue.replace(/\u200B/g, '');
            var ulListStartRegex = [/^[*]$/, /^[-]$/];
            Eif (!ej2_base_1.isNullOrUndefined(editorValue)) {
                for (var i = 0; i < ulListStartRegex.length; i++) {
                    if (ulListStartRegex[i].test(editorValue)) {
                        return true;
                    }
                }
            }
            return false;
        };
        HtmlEditor.prototype.hasMultipleTextNode = function (range) {
            Eif (range && range.startContainer && range.startContainer.parentNode) {
                var parentNode = range.startContainer.parentNode;
                if (range.startContainer.previousElementSibling &&
                    range.startContainer.previousElementSibling.classList.contains('e-mention-chip')
                    && !range.startContainer.previousElementSibling.isContentEditable) {
                    return true;
                }
                if (this.parent.enterKey === 'BR' || ej2_base_1.closest(parentNode, 'table')) {
                    return false;
                }
                var childNodes = parentNode.childNodes;
                var textNodes = [];
                for (var i = 0; i < childNodes.length; i++) {
                    var node = childNodes[i];
                    if (node && node.nodeType === Node.TEXT_NODE) {
                        textNodes.push(node);
                        if (textNodes.length > 1) {
                            return true;
                        }
                    }
                }
            }
            return false;
        };
        HtmlEditor.prototype.backSpaceCleanup = function (e, currentRange) {
            var isLiElement = false;
            var isPreviousNotContentEditable = true;
            if (!ej2_base_2.isNullOrUndefined(currentRange.startContainer.previousSibling) &&
                currentRange.startContainer.previousSibling.nodeName === 'SPAN') {
                isPreviousNotContentEditable = currentRange.startContainer.previousSibling.contentEditable === 'false' ? false : true;
            }
            var checkNode = currentRange.startContainer.nodeName === '#text' ? currentRange.startContainer.parentElement : currentRange.startContainer;
            var isSelectedPositionNotStart = ej2_base_1.closest(currentRange.startContainer.nodeName === '#text' ? currentRange.startContainer.parentElement : currentRange.startContainer, 'li') ?
                checkNode.nodeName !== 'li' && ej2_base_2.isNullOrUndefined(checkNode.previousSibling) : true;
            if (e.args.code === 'Backspace' && e.args.keyCode === 8 && currentRange.startOffset === 0 &&
                currentRange.endOffset === 0 && this.parent.getSelection().length === 0 && currentRange.startContainer.textContent.length > 0 &&
                currentRange.startContainer.parentElement.tagName !== 'TD' && currentRange.startContainer.parentElement.tagName !== 'TH' &&
                isPreviousNotContentEditable && isSelectedPositionNotStart) {
                if ((!this.parent.formatter.editorManager.domNode.isBlockNode(checkNode) &&
                    !ej2_base_2.isNullOrUndefined(checkNode.previousSibling) && checkNode.previousSibling.nodeName === 'BR') ||
                    (!ej2_base_2.isNullOrUndefined(currentRange.startContainer.previousSibling) && currentRange.startContainer.previousSibling.nodeName === 'BR')) {
                    return;
                }
                this.rangeElement = this.getRootBlockNode(currentRange.startContainer);
                if (this.rangeElement.tagName === 'OL' || this.rangeElement.tagName === 'UL') {
                    var liElement = this.getRangeLiNode(currentRange.startContainer);
                    Eif (liElement.previousElementSibling && liElement.previousElementSibling.childElementCount > 0) {
                        this.oldRangeElement = liElement.previousElementSibling.lastElementChild.nodeName === 'BR' ?
                            liElement.previousElementSibling : liElement.previousElementSibling.lastChild;
                        if (!ej2_base_2.isNullOrUndefined(liElement.lastElementChild) && liElement.lastElementChild.nodeName !== 'BR' &&
                            ej2_base_2.isNullOrUndefined(liElement.lastElementChild.previousSibling) && liElement.lastChild.nodeName !== '#text') {
                            this.rangeElement = liElement.lastElementChild;
                            isLiElement = true;
                        }
                        else {
                            this.rangeElement = liElement;
                        }
                    }
                }
                else if (this.rangeElement === this.parent.inputElement || this.rangeElement.tagName === 'TABLE' ||
                    (!ej2_base_2.isNullOrUndefined(this.rangeElement.previousElementSibling) && this.rangeElement.previousElementSibling.tagName === 'TABLE')) {
                    return;
                }
                else {
                    this.oldRangeElement = this.rangeElement.previousElementSibling;
                }
                var findBlockElement = this.parent.formatter.editorManager.domNode.blockNodes();
                if (!ej2_base_2.isNullOrUndefined(findBlockElement[0]) && currentRange.collapsed && currentRange.startOffset === 0 && currentRange.endOffset === 0 && findBlockElement[0].style.marginLeft !== '') {
                    findBlockElement[0].style.marginLeft = (parseInt(findBlockElement[0].style.marginLeft, 10) <= 20) ? '' : (parseInt(findBlockElement[0].style.marginLeft, 10) - 20 + 'px');
                }
                if (ej2_base_2.isNullOrUndefined(this.oldRangeElement)) {
                    return;
                }
                else {
                    Iif (this.oldRangeElement.tagName === 'OL' || this.oldRangeElement.tagName === 'UL') {
                        this.oldRangeElement = this.oldRangeElement.lastElementChild.lastElementChild
                            ? this.oldRangeElement.lastElementChild.lastElementChild :
                            this.oldRangeElement.lastElementChild;
                    }
                    var lastNode = this.oldRangeElement.lastChild ? this.oldRangeElement.lastChild : this.oldRangeElement;
                    while (lastNode.nodeType !== 3 && lastNode.nodeName !== '#text' &&
                        lastNode.nodeName !== 'BR' && !ej2_base_2.isNullOrUndefined(lastNode.lastChild)) {
                        lastNode = lastNode.lastChild;
                    }
                    Iif (lastNode.nodeName === 'IMG') {
                        this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), lastNode.parentElement, lastNode.parentElement.childNodes.length);
                    }
                    else {
                        this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), lastNode, lastNode.textContent.length);
                    }
                    var checkParent = false;
                    if (this.oldRangeElement && this.oldRangeElement.nodeName !== '#text' && this.oldRangeElement.querySelectorAll('BR').length === 1) {
                        var brElement = this.oldRangeElement.querySelector('BR');
                        Eif (brElement) {
                            var brParentElement = brElement.parentNode;
                            var currentState = this.oldRangeElement.innerHTML;
                            this.parent.formatter.saveData(currentState);
                            ej2_base_1.detach(brElement);
                            if (brParentElement && brParentElement.childNodes.length === 0) {
                                ej2_base_1.detach(brParentElement);
                                checkParent = true;
                            }
                        }
                    }
                    if (!ej2_base_2.isNullOrUndefined(this.rangeElement) && this.oldRangeElement !== this.rangeElement && !checkParent) {
                        while (this.rangeElement.firstChild) {
                            if (this.oldRangeElement.nodeName === '#text') {
                                this.oldRangeElement.parentElement.appendChild(this.rangeElement.childNodes[0]);
                            }
                            else {
                                this.oldRangeElement.appendChild(this.rangeElement.childNodes[0]);
                            }
                        }
                        !isLiElement ? ej2_base_1.detach(this.rangeElement) : ej2_base_1.detach(this.rangeElement.parentElement);
                        this.oldRangeElement.normalize();
                    }
                }
            }
        };
        HtmlEditor.prototype.deleteCleanup = function (e, currentRange) {
            var isLiElement = false;
            var liElement;
            var rootElement;
            if (e.args.code === 'Delete' && e.args.keyCode === 46 &&
                this.parent.contentModule.getText().trim().replace(/(\r\n|\n|\r|\t)/gm, '').replace(/\u200B/g, '').length !== 0 && this.parent.getSelection().length === 0 && currentRange.startContainer.parentElement.tagName !== 'TD' &&
                currentRange.startContainer.parentElement.tagName !== 'TH') {
                this.deleteRangeElement = rootElement = this.getRootBlockNode(currentRange.startContainer);
                if (this.deleteRangeElement.tagName === 'OL' || this.deleteRangeElement.tagName === 'UL') {
                    liElement = this.getRangeLiNode(currentRange.startContainer);
                    if (liElement.nextElementSibling && liElement.nextElementSibling.childElementCount > 0
                        && !liElement.nextElementSibling.querySelector('BR')) {
                        Eif (!ej2_base_1.isNullOrUndefined(liElement.lastElementChild)) {
                            this.deleteRangeElement = liElement.lastElementChild;
                            isLiElement = true;
                        }
                        else {
                            this.deleteRangeElement = liElement;
                        }
                    }
                    else {
                        this.deleteRangeElement = this.getRangeElement(liElement);
                    }
                }
                else Iif (this.deleteRangeElement.nodeType === 3 || (this.deleteRangeElement.tagName === 'TABLE' ||
                    (!ej2_base_1.isNullOrUndefined(this.deleteRangeElement.nextElementSibling) && this.deleteRangeElement.nextElementSibling.tagName === 'TABLE'))) {
                    return;
                }
                var isImgWithEmptyBlockNode = false;
                if (this.deleteRangeElement.querySelectorAll('img').length > 0 && this.deleteRangeElement.textContent.trim() === '') {
                    isImgWithEmptyBlockNode = true;
                }
                if (this.getCaretIndex(currentRange, this.deleteRangeElement) === this.deleteRangeElement.textContent.length &&
                    !isImgWithEmptyBlockNode) {
                    if (!ej2_base_1.isNullOrUndefined(liElement)) {
                        Eif (isLiElement || !ej2_base_1.isNullOrUndefined(liElement.nextElementSibling)) {
                            this.deleteOldRangeElement = this.getRangeElement(liElement.nextElementSibling);
                        }
                        else {
                            this.deleteOldRangeElement = rootElement.nextElementSibling;
                        }
                    }
                    else {
                        this.deleteOldRangeElement = this.deleteRangeElement.nextElementSibling;
                    }
                    Iif (ej2_base_1.isNullOrUndefined(this.deleteOldRangeElement)) {
                        return;
                    }
                    else {
                        Iif (currentRange.startOffset === 0 && currentRange.endOffset === 1 &&
                            this.deleteRangeElement.childNodes[0].nodeName === 'IMG') {
                            this.parent.formatter.editorManager.nodeSelection.setSelectionText(this.parent.contentModule.getDocument(), this.deleteRangeElement, this.deleteRangeElement, 0, 1);
                            this.isImageDelete = true;
                        }
                        else {
                            this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), this.deleteRangeElement, this.deleteRangeElement.childNodes.length);
                            this.isImageDelete = false;
                        }
                        var brNode = this.deleteRangeElement.querySelector('BR');
                        var brLastChildNode = this.deleteRangeElement.lastChild;
                        var brParentNode = brLastChildNode.parentNode;
                        if (brNode && brNode.classList.contains('e-rte-image-remove-focus')) {
                            ej2_base_1.removeClass([brNode], ['e-rte-image-focus']);
                            return;
                        }
                        else if (brNode && brLastChildNode && brLastChildNode.nodeName === 'BR') {
                            ej2_base_1.detach(brLastChildNode);
                            if (!ej2_base_1.isNullOrUndefined(brParentNode) && brParentNode.childNodes.length === 0) {
                                ej2_base_1.detach(brParentNode);
                            }
                            e.args.preventDefault();
                        }
                        if (!ej2_base_1.isNullOrUndefined(this.deleteRangeElement) && (this.deleteOldRangeElement.tagName !== 'OL' && this.deleteOldRangeElement.tagName !== 'UL')
                            && this.deleteOldRangeElement !== this.deleteRangeElement) {
                            while (this.deleteOldRangeElement.firstChild) {
                                this.deleteRangeElement.appendChild(this.deleteOldRangeElement.childNodes[0]);
                            }
                            if (!isLiElement) {
                                ej2_base_1.detach(this.deleteOldRangeElement);
                            }
                            else {
                                ej2_base_1.detach(this.deleteOldRangeElement.parentElement);
                            }
                            this.deleteRangeElement.normalize();
                        }
                        else {
                            this.deleteRangeElement = null;
                            this.deleteOldRangeElement = null;
                        }
                    }
                }
                else {
                    this.deleteRangeElement = null;
                }
            }
        };
        HtmlEditor.prototype.getCaretIndex = function (currentRange, element) {
            var position = 0;
            Eif (this.parent.contentModule.getDocument().getSelection().rangeCount !== 0) {
                var preCaretRange = currentRange.cloneRange();
                preCaretRange.selectNodeContents(element);
                preCaretRange.setEnd(currentRange.endContainer, currentRange.endOffset);
                position = preCaretRange.toString().length;
            }
            return position;
        };
        HtmlEditor.prototype.getRangeElement = function (element) {
            var rangeElement = element.lastElementChild ? element.lastElementChild.tagName === 'BR' ?
                element.lastElementChild.previousElementSibling ? element.lastElementChild.previousElementSibling
                    : element : element.lastElementChild : element;
            return rangeElement;
        };
        HtmlEditor.prototype.getRootBlockNode = function (rangeBlockNode) {
            for (; rangeBlockNode && this.parent && this.parent.inputElement !== rangeBlockNode; rangeBlockNode = rangeBlockNode) {
                if (rangeBlockNode.parentElement === this.parent.inputElement) {
                    break;
                }
                else {
                    rangeBlockNode = rangeBlockNode.parentElement;
                }
            }
            return rangeBlockNode;
        };
        HtmlEditor.prototype.getRangeLiNode = function (rangeLiNode) {
            var node = rangeLiNode.parentElement;
            while (node !== this.parent.inputElement) {
                if (node.nodeType === 1 && node.tagName === 'LI') {
                    break;
                }
                node = node.parentElement;
            }
            return node;
        };
        HtmlEditor.prototype.onPaste = function (e) {
            var regex = new RegExp(/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi);
            if (e.text.match(regex)) {
                if (e.isWordPaste) {
                    return;
                }
                e.args.preventDefault();
                var range = this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.contentModule.getDocument());
                var saveSelection = this.parent.formatter.editorManager.nodeSelection.save(range, this.parent.contentModule.getDocument());
                var httpRegex = new RegExp(/([^\S]|^)(((https?\:\/\/)))/gi);
                var wwwRegex = new RegExp(/([^\S]|^)(((www\.))(\S+))/gi);
                var enterSplitText = e.text.split('\n');
                var contentInnerElem = '';
                for (var i = 0; i < enterSplitText.length; i++) {
                    if (enterSplitText[i].trim() === '') {
                        contentInnerElem += util_1.getDefaultValue(this.parent);
                    }
                    else {
                        var contentWithSpace = '';
                        var spaceBetweenContent = true;
                        var spaceSplit = enterSplitText[i].split(' ');
                        for (var j = 0; j < spaceSplit.length; j++) {
                            if (spaceSplit[j].trim() === '') {
                                contentWithSpace += spaceBetweenContent ? '&nbsp;' : ' ';
                            }
                            else {
                                spaceBetweenContent = false;
                                contentWithSpace += spaceSplit[j] + ' ';
                            }
                        }
                        if (i === 0) {
                            contentInnerElem += '<span>' + contentWithSpace.trim() + '</span>';
                        }
                        else {
                            contentInnerElem += '<p>' + contentWithSpace.trim() + '</p>';
                        }
                    }
                }
                var divElement = this.parent.createElement('div');
                divElement.setAttribute('class', 'pasteContent');
                divElement.style.display = 'inline';
                divElement.innerHTML = contentInnerElem.replace('&para', '&amp;para');
                var paraElem = divElement.querySelectorAll('span, p');
                for (var i = 0; i < paraElem.length; i++) {
                    var splitTextContent = paraElem[i].innerHTML.split(' ');
                    var resultSplitContent = '';
                    for (var j = 0; j < splitTextContent.length; j++) {
                        if (splitTextContent[j].match(httpRegex) || splitTextContent[j].match(wwwRegex)) {
                            resultSplitContent += '<a class="e-rte-anchor" href="' + splitTextContent[j] +
                                '" title="' + splitTextContent[j] + '" target="_blank"' + ' aria-label="' + this.parent.serviceLocator.getService('rteLocale').getConstant('linkAriaLabel') + '">' + splitTextContent[j] + ' </a>';
                        }
                        else {
                            resultSplitContent += splitTextContent[j] + ' ';
                        }
                    }
                    paraElem[i].innerHTML = resultSplitContent.trim();
                }
                var anchorElement = divElement.childNodes[0];
                if (!ej2_base_1.isNullOrUndefined(anchorElement) && !ej2_base_1.isNullOrUndefined(anchorElement.childNodes[0]) && anchorElement.nodeName === 'SPAN' && anchorElement.childNodes[0].nodeName === 'A') {
                    divElement.innerHTML = divElement.innerHTML.replace('<span>', '').replace('</span>', '');
                }
                Eif (!ej2_base_1.isNullOrUndefined(this.parent.pasteCleanupModule)) {
                    e.callBack(divElement.innerHTML);
                }
                else {
                    this.parent.formatter.editorManager.execCommand('insertHTML', null, null, null, divElement);
                }
            }
        };
        HtmlEditor.prototype.spaceLink = function (e) {
            var range = this.nodeSelectionObj.getRange(this.contentRenderer.getDocument());
            var selectNodeEle = this.nodeSelectionObj.getParentNodeCollection(range);
            var text = range.startContainer.textContent.substr(0, range.endOffset);
            var splitText = text.split(' ');
            var urlText = splitText[splitText.length - 1];
            var urlTextRange = range.startOffset - (text.length - splitText[splitText.length - 1].length);
            urlText = urlText.slice(0, urlTextRange);
            var regex = new RegExp(/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi);
            if (selectNodeEle[0] && selectNodeEle[0].nodeName !== 'A' && urlText.match(regex)) {
                var selection = this.nodeSelectionObj.save(range, this.parent.contentModule.getDocument());
                var url = urlText.indexOf('http') > -1 ? urlText : 'http://' + urlText;
                var selectParent = this.parent.formatter.editorManager.nodeSelection.getParentNodeCollection(range);
                var value = {
                    url: url,
                    selection: selection, selectParent: selectParent,
                    text: urlText,
                    title: '',
                    target: '_blank'
                };
                this.parent.formatter.process(this.parent, {
                    item: {
                        'command': 'Links',
                        'subCommand': 'CreateLink'
                    }
                }, e, value);
            }
        };
        HtmlEditor.prototype.onToolbarClick = function (args) {
            var _this = this;
            var save;
            var selectNodeEle;
            var selectParentEle;
            var item = args.item;
            var closestElement = ej2_base_1.closest(args.originalEvent.target, '.e-rte-quick-popup');
            var target = args.originalEvent.target;
            this.parent.notify(events.closeTooltip, { target: target });
            if (item.command !== 'FormatPainter') {
                if (closestElement && !closestElement.classList.contains('e-rte-inline-popup') && !closestElement.classList.contains('e-rte-text-popup')) {
                    if (!(item.subCommand === 'SourceCode' || item.subCommand === 'Preview' ||
                        item.subCommand === 'FontColor' || item.subCommand === 'BackgroundColor')) {
                        if (util_2.isIDevice() && item.command === 'Images') {
                            this.nodeSelectionObj.restore();
                        }
                        var range = this.nodeSelectionObj.getRange(this.parent.contentModule.getDocument());
                        save = this.nodeSelectionObj.save(range, this.parent.contentModule.getDocument());
                        selectNodeEle = this.nodeSelectionObj.getNodeCollection(range);
                        selectParentEle = this.nodeSelectionObj.getParentNodeCollection(range);
                    }
                    if (item.command === 'Images') {
                        this.parent.notify(events.imageToolbarAction, {
                            member: 'image', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                        });
                    }
                    if (item.command === 'Audios') {
                        this.parent.notify(events.audioToolbarAction, {
                            member: 'audio', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                        });
                    }
                    if (item.command === 'Videos') {
                        this.parent.notify(events.videoToolbarAction, {
                            member: 'video', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                        });
                    }
                    if (item.command === 'Links') {
                        this.parent.notify(events.linkToolbarAction, {
                            member: 'link', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                        });
                    }
                    if (item.command === 'Table') {
                        this.parent.notify(events.tableToolbarAction, {
                            member: 'table', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                        });
                    }
                }
                else {
                    var linkDialog = document.getElementById(this.parent.getID() + '_rtelink');
                    var imageDialog = document.getElementById(this.parent.getID() + '_image');
                    if (!(item.subCommand === 'SourceCode' || item.subCommand === 'Preview' ||
                        item.subCommand === 'FontColor' || item.subCommand === 'BackgroundColor' || item.subCommand === 'NumberFormatList' || item.subCommand === 'BulletFormatList')) {
                        var range = this.nodeSelectionObj.getRange(this.parent.contentModule.getDocument());
                        if (ej2_base_1.isNullOrUndefined(linkDialog) && ej2_base_1.isNullOrUndefined(imageDialog)) {
                            save = this.nodeSelectionObj.save(range, this.parent.contentModule.getDocument());
                        }
                        selectNodeEle = this.nodeSelectionObj.getNodeCollection(range);
                        selectParentEle = this.nodeSelectionObj.getParentNodeCollection(range);
                    }
                    switch (item.subCommand) {
                        case 'Maximize':
                            this.parent.notify(events.enableFullScreen, { args: args });
                            break;
                        case 'Minimize':
                            this.parent.notify(events.disableFullScreen, { args: args });
                            break;
                        case 'CreateLink':
                            this.parent.notify(events.insertLink, {
                                member: 'link', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'RemoveLink':
                            this.parent.notify(events.unLink, {
                                member: 'link', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'Print':
                            this.parent.print();
                            break;
                        case 'Image':
                            this.parent.notify(events.insertImage, {
                                member: 'image', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'Audio':
                            this.parent.notify(events.insertAudio, {
                                member: 'audio', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'Video':
                            this.parent.notify(events.insertVideo, {
                                member: 'video', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'CreateTable':
                            this.parent.notify(events.createTable, {
                                member: 'table', args: args, selection: save
                            });
                            break;
                        case 'SourceCode':
                            this.parent.notify(events.sourceCode, { member: 'viewSource', args: args });
                            break;
                        case 'Preview':
                            this.parent.notify(events.updateSource, { member: 'updateSource', args: args });
                            break;
                        case 'FontColor':
                        case 'BackgroundColor':
                            break;
                        case 'File':
                            this.parent.notify(events.renderFileManager, {
                                member: 'fileManager', args: args, selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                            });
                            break;
                        case 'EmojiPicker':
                            this.parent.notify(events.emojiPicker, { member: 'emojiPicker', args: args });
                            break;
                        case 'ImportWord':
                            this.parent.notify(events.onImport, {});
                            break;
                        case 'ExportWord':
                            this.parent.notify(events.onExport, { member: 'ExportWord', args: args });
                            break;
                        case 'ExportPdf':
                            this.parent.notify(events.onExport, { member: 'ExportPdf', args: args });
                            break;
                        default:
                            this.parent.formatter.process(this.parent, args, args.originalEvent, null);
                            break;
                    }
                }
            }
            else {
                if (args.originalEvent.detail === 1) {
                    clearTimeout(this.clickTimeout);
                    this.clickTimeout = setTimeout(function () {
                        _this.parent.notify(events.formatPainterClick, {
                            member: 'formatPainter', args: args
                        });
                    }, 200);
                }
                else {
                    clearTimeout(this.clickTimeout);
                    this.parent.notify(events.formatPainterDoubleClick, {
                        member: 'formatPainter', args: args
                    });
                }
            }
        };
        HtmlEditor.prototype.instantiateRenderer = function () {
            if (this.parent.iframeSettings.enable) {
                this.renderFactory.addRenderer(enum_1.RenderType.Content, new iframe_content_renderer_1.IframeContentRender(this.parent));
            }
            else {
                this.renderFactory.addRenderer(enum_1.RenderType.Content, new content_renderer_1.ContentRender(this.parent));
            }
        };
        HtmlEditor.prototype.removeEventListener = function () {
            this.parent.off(events.initialEnd, this.render);
            this.parent.off(events.modelChanged, this.onPropertyChanged);
            this.parent.off(events.htmlToolbarClick, this.onToolbarClick);
            this.parent.off(events.destroy, this.destroy);
            this.parent.off(events.keyDown, this.onKeyDown);
            this.parent.off(events.initialLoad, this.instantiateRenderer);
            this.parent.off(events.selectAll, this.selectAll);
            this.parent.off(events.selectRange, this.selectRange);
            this.parent.off(events.getSelectedHtml, this.getSelectedHtml);
            this.parent.off(events.selectionSave, this.onSelectionSave);
            this.parent.off(events.selectionRestore, this.onSelectionRestore);
            this.parent.off(events.readOnlyMode, this.updateReadOnly);
            this.parent.off(events.paste, this.onPaste);
            this.parent.off(events.tableclass, this.isTableClassAdded);
        };
        HtmlEditor.prototype.render = function () {
            this.contentRenderer = this.renderFactory.getRenderer(enum_1.RenderType.Content);
            var editElement = this.contentRenderer.getEditPanel();
            var option = { undoRedoSteps: this.parent.undoRedoSteps, undoRedoTimer: this.parent.undoRedoTimer };
            if (ej2_base_1.isNullOrUndefined(this.parent.formatter)) {
                var formatterClass = new html_formatter_1.HTMLFormatter({
                    currentDocument: this.contentRenderer.getDocument(),
                    element: editElement,
                    options: option,
                    formatPainterSettings: this.parent.formatPainterSettings
                });
                this.parent.setProperties({ formatter: formatterClass }, true);
            }
            else {
                this.parent.formatter.updateFormatter(editElement, this.contentRenderer.getDocument(), option);
            }
            if (this.parent.enableXhtml) {
                this.parent.notify(events.xhtmlValidation, {});
            }
            if (this.parent.toolbarSettings.enable) {
                this.toolbarUpdate = new html_toolbar_status_1.HtmlToolbarStatus(this.parent);
            }
            if (this.parent.inlineMode.enable) {
                if (!ej2_base_1.isNullOrUndefined(this.parent.fontFamily.default)) {
                    editElement.style.fontFamily = this.parent.fontFamily.default;
                }
                if (!ej2_base_1.isNullOrUndefined(this.parent.fontSize.default)) {
                    editElement.style.fontSize = this.parent.fontSize.default;
                }
            }
            this.parent.notify(events.bindOnEnd, {});
        };
        HtmlEditor.prototype.onPropertyChanged = function (e) {
            if (!ej2_base_2.isNullOrUndefined(e) && !ej2_base_2.isNullOrUndefined(e.newProp.toolbarSettings) && !ej2_base_2.isNullOrUndefined(e.newProp.toolbarSettings.enable)) {
                this.toolbarUpdate = new html_toolbar_status_1.HtmlToolbarStatus(this.parent);
            }
            if (!ej2_base_1.isNullOrUndefined(e.newProp.formatter)) {
                var editElement = this.contentRenderer.getEditPanel();
                var option = { undoRedoSteps: this.parent.undoRedoSteps,
                    undoRedoTimer: this.parent.undoRedoTimer };
                this.parent.formatter.updateFormatter(editElement, this.contentRenderer.getDocument(), option);
            }
        };
        HtmlEditor.prototype.getModuleName = function () {
            return 'htmlEditor';
        };
        HtmlEditor.prototype.selectAll = function () {
            var nodes = util_1.getTextNodesUnder(this.parent.contentModule.getDocument(), this.parent.contentModule.getEditPanel());
            if (nodes.length > 0) {
                this.parent.formatter.editorManager.nodeSelection.setSelectionText(this.parent.contentModule.getDocument(), nodes[0], nodes[nodes.length - 1], 0, nodes[nodes.length - 1].textContent.length);
            }
        };
        HtmlEditor.prototype.selectRange = function (e) {
            this.parent.formatter.editorManager.nodeSelection.setRange(this.parent.contentModule.getDocument(), e.range);
        };
        HtmlEditor.prototype.getSelectedHtml = function (e) {
            e.callBack(this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.contentModule.getDocument()).toString());
        };
        HtmlEditor.prototype.tableSelectionKeyAction = function (e) {
            var args = e.args;
            var tableCellSelectNodes = this.parent.inputElement.querySelectorAll('.e-cell-select');
            for (var i = 0; i < tableCellSelectNodes.length; i++) {
                var currentCell = tableCellSelectNodes[i];
                util_2.removeClassWithAttr([currentCell], [classes.CLS_TABLE_SEL, classes.CLS_TABLE_MULTI_CELL, classes.CLS_TABLE_SEL_END]);
                if (i === 0) {
                    if (args.keyCode === 32) {
                        currentCell.innerHTML = '&#8203;<br>';
                    }
                    else {
                        currentCell.innerHTML = '<br>';
                    }
                    this.nodeSelectionObj.setCursorPoint(this.parent.contentModule.getDocument(), currentCell.firstChild, 0);
                }
                else {
                    currentCell.innerHTML = '<br>';
                }
            }
        };
        HtmlEditor.prototype.marginTabAdd = function (val, alignmentNodes) {
            for (var index = 0; index < alignmentNodes.length; index++) {
                var element = alignmentNodes[index];
                if (element.closest('li')) {
                    continue;
                }
                if (element.style.marginLeft) {
                    var count = parseInt(element.style.marginLeft, 10);
                    if (val) {
                        count -= 20;
                    }
                    else {
                        count += 20;
                    }
                    element.style.marginLeft = count.toString() + 'px';
                    if (element.style.marginLeft === '0px') {
                        element.removeAttribute('style');
                    }
                }
                else Eif (!val) {
                    element.style.marginLeft = '20px';
                }
            }
        };
        return HtmlEditor;
    }());
    exports.HtmlEditor = HtmlEditor;
});