all files / document-editor/implementation/search/ options-pane.js

41.72% Statements 383/918
27.36% Branches 119/435
44.68% Functions 21/47
41.72% Lines 383/918
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 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250   144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144× 144×                                             144×                                 144×                                                                                                                                     144×                                                                                                         144×           144×                                                                                                         144×                                                   144×                                                   144×                                                           144×                 144×                                                                   144×             14486×                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       777× 20× 20× 20× 20×                                                                                                                                                                                                                   226× 226× 226×                                                               225×                                     225× 225×           225× 223×   225× 223×     226×             198×   198×   198×   198×   198× 198×   198×   198×   198×   198×   198×   198×   198×   198×   198×   198×     198× 99×   198× 198× 198×   198× 99×   198× 99×   198× 99×   198× 99×   198× 99×   198×          
define(["require", "exports", "@syncfusion/ej2-base", "../editor/editor-helper", "@syncfusion/ej2-buttons", "@syncfusion/ej2-navigations"], function (require, exports, ej2_base_1, editor_helper_1, ej2_buttons_1, ej2_navigations_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var OptionsPane = (function () {
        function OptionsPane(documentHelper) {
            var _this = this;
            this.isOptionsPaneShow = false;
            this.findOption = 'None';
            this.matchCase = undefined;
            this.wholeWord = undefined;
            this.searchText = 'Navigation';
            this.resultsText = 'Results';
            this.messageDivText = 'No matches';
            this.replaceButtonText = 'Replace';
            this.replaceAllButtonText = 'Replace All';
            this.focusedIndex = -1;
            this.focusedElement = [];
            this.isOptionsPane = true;
            this.replacePaneText = 'Replace';
            this.findPaneText = 'Find';
            this.headingPaneText = 'Heading';
            this.matchDivReplaceText = 'No matches';
            this.tabInstance = undefined;
            this.isReplace = false;
            this.isUpdateHeading = false;
            this.searchOptionChange = function () {
                _this.clearSearchResultItems();
                _this.documentHelper.owner.searchModule.clearSearchHighlight();
                var inputText = _this.searchInput.value;
                if (inputText === '') {
                    return;
                }
                var pattern = _this.documentHelper.owner.searchModule.textSearch.stringToRegex(inputText, _this.findOption);
                var endSelection = _this.documentHelper.selection.end;
                var selectionIndex = endSelection.getHierarchicalIndexInternal();
                _this.results = _this.documentHelper.owner.searchModule.textSearch.findAll(pattern, _this.findOption, selectionIndex);
                if (_this.results != null && _this.results.length > 0) {
                    _this.navigateSearchResult(false);
                }
                else {
                    _this.viewer.renderVisiblePages();
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('No matches');
                    _this.resultContainer.style.display = 'block';
                    _this.resultsListBlock.style.display = 'none';
                    _this.clearFocusElement();
                    _this.resultsListBlock.innerHTML = '';
                }
            };
            this.onEnableDisableReplaceButton = function () {
                if (_this.searchInput.value.length !== 0) {
                    _this.replaceButton.disabled = false;
                    _this.replaceAllButton.disabled = false;
                }
                else {
                    _this.replaceButton.disabled = true;
                    _this.replaceAllButton.disabled = true;
                }
                if (!ej2_base_1.isNullOrUndefined(_this.searchInput.value) && _this.searchInput.value.match(/[!\@\#$%\^&*\(\)_\-+\=\[\]\{\};:"\|,.<>\/?`~\s\\؟°÷×،؛]/) && _this.searchInput.value !== "") {
                    _this.wholeWord.checked = false;
                    _this.wholeWord.disabled = true;
                }
                else {
                    _this.wholeWord.disabled = false;
                }
            };
            this.onKeyDownOnOptionPane = function (event) {
                if (event.keyCode === 9) {
                    event.preventDefault();
                    var focusIndex = undefined;
                    if (event.shiftKey) {
                        focusIndex = (_this.focusedIndex === 0 || ej2_base_1.isNullOrUndefined(_this.focusedIndex)) ?
                            _this.focusedElement.length - 1 : _this.focusedIndex - 1;
                    }
                    else {
                        focusIndex = (_this.focusedElement.length - 1 === _this.focusedIndex || ej2_base_1.isNullOrUndefined(_this.focusedIndex)) ?
                            0 : _this.focusedIndex + 1;
                    }
                    var element = _this.focusedElement[focusIndex];
                    element.focus();
                    if (element instanceof HTMLInputElement) {
                        element.select();
                    }
                    _this.focusedIndex = focusIndex;
                    if (element instanceof HTMLLIElement) {
                        _this.scrollToPosition(element);
                    }
                }
                else if (event.keyCode === 13) {
                    _this.hideMatchDiv();
                    if (event.target !== _this.searchInput && event.target !== _this.closeButton) {
                        event.preventDefault();
                        var index = _this.focusedElement.indexOf(event.target);
                        if (index !== -1) {
                            var list = _this.focusedElement[index];
                            list.click();
                            list.focus();
                            _this.focusedIndex = index;
                        }
                    }
                }
                else if (event.keyCode === 40 || event.keyCode === 38) {
                    if (_this.resultsListBlock.style.display !== 'none') {
                        var index = void 0;
                        var element = void 0;
                        if (event.keyCode === 40) {
                            if (_this.focusedIndex > 7) {
                                if (_this.focusedIndex + 1 < _this.focusedElement.length) {
                                    element = _this.focusedElement[_this.focusedIndex + 1];
                                    element.focus();
                                    _this.focusedIndex = _this.focusedIndex + 1;
                                }
                            }
                            else {
                                index = (_this.focusedElement.length - _this.resultsListBlock.children.length) + _this.results.currentIndex + 1;
                                if (index < _this.focusedElement.length) {
                                    element = _this.focusedElement[index];
                                    element.focus();
                                    _this.focusedIndex = index;
                                }
                            }
                        }
                        else {
                            if (_this.focusedIndex > 6) {
                                index = _this.focusedIndex - 1;
                                element = _this.focusedElement[index];
                                element.focus();
                                _this.focusedIndex = index;
                            }
                        }
                    }
                }
            };
            this.onReplaceButtonClick = function () {
                var optionsPane = _this.optionsPane;
                var findText = _this.searchInput.value;
                var replaceText = _this.replaceWith.value;
                var results = _this.documentHelper.owner.searchModule.textSearchResults;
                if (findText !== '' && !ej2_base_1.isNullOrUndefined(findText)) {
                    if (_this.documentHelper.owner.selectionModule != null) {
                        var selectionText = _this.documentHelper.owner.selectionModule.text;
                        if (!_this.documentHelper.owner.selectionModule.isEmpty) {
                            if (_this.documentHelper.owner.selectionModule.isForward) {
                                _this.documentHelper.owner.selectionModule.selectContent(_this.documentHelper.owner.selectionModule.start, true);
                            }
                            else {
                                _this.documentHelper.owner.selectionModule.selectContent(_this.documentHelper.owner.selectionModule.end, true);
                            }
                        }
                        if (!ej2_base_1.isNullOrUndefined(results) && !ej2_base_1.isNullOrUndefined(results.currentSearchResult)) {
                            var result = results.currentSearchResult;
                            _this.documentHelper.owner.searchModule.navigate(result);
                            if (result.text === selectionText) {
                                var replace = ej2_base_1.isNullOrUndefined(replaceText) ? '' : replaceText;
                                _this.documentHelper.owner.searchModule.replace(replace, result, results);
                                var pattern = _this.documentHelper.owner.searchModule.textSearch.stringToRegex(findText, _this.findOption);
                                var endSelection = _this.documentHelper.selection.end;
                                var index = endSelection.getHierarchicalIndexInternal();
                                _this.results = _this.documentHelper.owner.searchModule.textSearch.findAll(pattern, _this.findOption, index);
                                if (!ej2_base_1.isNullOrUndefined(_this.results) && !ej2_base_1.isNullOrUndefined(_this.results.currentSearchResult)) {
                                    _this.documentHelper.owner.searchModule.navigate(_this.results.currentSearchResult);
                                }
                                else {
                                    _this.messageDiv.style.display = 'block';
                                    _this.messageDiv.innerHTML = _this.localeValue.getConstant(_this.matchDivReplaceText);
                                }
                                _this.documentHelper.owner.findResultsList = [];
                                if (!ej2_base_1.isNullOrUndefined(_this.results) && _this.results.innerList.length > 0) {
                                    _this.navigateSearchResult(true);
                                }
                                else {
                                    _this.resultsListBlock.innerHTML = '';
                                }
                            }
                            else {
                                _this.documentHelper.owner.searchModule.findAll(findText, _this.findOption);
                            }
                        }
                        else {
                            _this.documentHelper.owner.searchModule.findAll(findText, _this.findOption);
                            _this.messageDiv.style.display = 'block';
                            _this.messageDiv.innerHTML = _this.localeValue.getConstant(_this.matchDivReplaceText);
                        }
                    }
                }
            };
            this.onReplaceAllButtonClick = function () {
                _this.replaceAll();
                _this.resultsListBlock.style.display = 'none';
                _this.messageDiv.innerHTML = '';
                _this.documentHelper.updateFocus();
            };
            this.searchIconClickInternal = function () {
                var inputElement = document.getElementById(_this.documentHelper.owner.containerId + '_option_search_text_box');
                var text = inputElement.value;
                if (text === '') {
                    return;
                }
                _this.hideMatchDiv();
                if (_this.searchIcon.classList.contains('e-de-op-search-close-icon')) {
                    _this.searchIcon.classList.add('e-de-op-search-icon');
                    _this.searchIcon.classList.remove('e-de-op-search-close-icon');
                    inputElement.value = '';
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('No matches');
                    _this.resultContainer.style.display = 'block';
                    _this.resultsListBlock.style.display = 'none';
                    _this.matchDiv.style.display = 'none';
                    _this.occurrenceDiv.style.display = 'none';
                    _this.onEnableDisableReplaceButton();
                    _this.clearFocusElement();
                    _this.resultsListBlock.innerHTML = '';
                    _this.clearSearchResultItems();
                    _this.documentHelper.owner.searchModule.clearSearchHighlight();
                    _this.viewer.renderVisiblePages();
                    return;
                }
                if (_this.searchIcon.classList.contains('e-de-op-search-icon') && text.length >= 1) {
                    _this.searchIcon.classList.add('e-de-op-search-close-icon');
                    _this.searchIcon.classList.remove('e-de-op-search-icon');
                    _this.onEnableDisableReplaceButton();
                }
                _this.clearSearchResultItems();
                _this.documentHelper.owner.searchModule.clearSearchHighlight();
                var patterns = _this.documentHelper.owner.searchModule.textSearch.stringToRegex(text, _this.findOption);
                var endSelection = _this.documentHelper.selection.end;
                var index = endSelection.getHierarchicalIndexInternal();
                _this.results = _this.documentHelper.owner.searchModule.textSearch.findAll(patterns, _this.findOption, index);
                if (_this.results != null && _this.results.length > 0) {
                    var start = _this.results.innerList[_this.results.currentIndex].start;
                    var end = _this.results.innerList[_this.results.currentIndex].end;
                    _this.documentHelper.scrollToPosition(start, end, true);
                    _this.navigateSearchResult(false);
                    _this.getMessageDivHeight();
                    var height = _this.isOptionsPane ? 215 : 292;
                    var resultsContainerHeight = _this.optionsPane.offsetHeight - _this.findTab.offsetHeight;
                    _this.resultsListBlock.style.height = resultsContainerHeight + 'px';
                }
                else {
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('No matches');
                    _this.resultContainer.style.display = 'block';
                    _this.resultsListBlock.style.display = 'none';
                    _this.clearFocusElement();
                    _this.resultsListBlock.innerHTML = '';
                }
            };
            this.navigateNextResultButtonClick = function () {
                if (document.getElementById(_this.documentHelper.owner.containerId + '_list_box_container') != null &&
                    document.getElementById(_this.documentHelper.owner.containerId + '_list_box_container').style.display !== 'none') {
                    var selectionEnd = _this.documentHelper.owner.selectionModule.end;
                    var nextResult = void 0;
                    var currentIndex = 0;
                    if (selectionEnd.isExistAfter(_this.results.currentSearchResult.start)) {
                        currentIndex = _this.results.currentIndex;
                    }
                    for (var i = currentIndex; i < _this.results.length; i++) {
                        var result = _this.results.innerList[i];
                        if (selectionEnd.isExistBefore(result.start) || selectionEnd.isAtSamePosition(result.start)) {
                            nextResult = result;
                            _this.results.currentIndex = i;
                            break;
                        }
                    }
                    if (ej2_base_1.isNullOrUndefined(nextResult)) {
                        _this.results.currentIndex = 0;
                        nextResult = _this.results.innerList[0];
                    }
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('Result') + ' ' + (_this.results.currentIndex + 1) + ' ' + _this.localeValue.getConstant('of') + ' ' + _this.resultsListBlock.children.length;
                    _this.updateListItems(nextResult);
                    _this.focusedIndex = _this.focusedElement.indexOf(_this.navigateToNextResult);
                }
            };
            this.navigatePreviousResultButtonClick = function () {
                if (document.getElementById(_this.documentHelper.owner.containerId + '_list_box_container') != null &&
                    document.getElementById(_this.documentHelper.owner.containerId + '_list_box_container').style.display !== 'none') {
                    var previousResult = void 0;
                    var selectionStart = _this.documentHelper.owner.selectionModule.start;
                    var currentIndex = _this.results.currentIndex;
                    if (selectionStart.isExistAfter(_this.results.currentSearchResult.start)) {
                        currentIndex = _this.results.length - 1;
                    }
                    for (var i = currentIndex; i >= 0; i--) {
                        var result = _this.results.innerList[i];
                        if (selectionStart.isExistAfter(result.start) || _this.documentHelper.owner.selectionModule.end.isAtSamePosition(result.start)) {
                            previousResult = result;
                            _this.results.currentIndex = i;
                            break;
                        }
                    }
                    if (ej2_base_1.isNullOrUndefined(previousResult)) {
                        _this.results.currentIndex = _this.results.length - 1;
                        previousResult = _this.results.innerList[_this.results.currentIndex];
                    }
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('Result') + ' ' + (_this.results.currentIndex + 1) + ' ' + _this.localeValue.getConstant('of') + ' ' + _this.resultsListBlock.children.length;
                    _this.updateListItems(previousResult);
                    _this.focusedIndex = _this.focusedElement.indexOf(_this.navigateToPreviousResult);
                }
            };
            this.onKeyDown = function (event) {
                var code = event.which || event.keyCode;
                if (code === 13 && event.keyCode !== 9 && event.keyCode !== 40) {
                    event.preventDefault();
                    _this.findDiv.style.height = '';
                    _this.onKeyDownInternal();
                }
                else if (code === 8 && (_this.searchInput.value.length === 0)) {
                    _this.resultContainer.style.display = 'block';
                }
                else if (event.keyCode !== 9 && event.keyCode !== 40 && event.keyCode !== 27) {
                    _this.documentHelper.owner.searchModule.clearSearchHighlight();
                    _this.clearSearchResultItems();
                    _this.viewer.renderVisiblePages();
                    _this.resultsListBlock.style.display = 'none';
                    _this.messageDiv.innerHTML = _this.localeValue.getConstant('No matches');
                    _this.resultContainer.style.display = 'none';
                    _this.clearFocusElement();
                    _this.resultsListBlock.innerHTML = '';
                    if (_this.searchIcon.classList.contains('e-de-op-search-close-icon')) {
                        _this.searchIcon.classList.add('e-de-op-search-icon');
                        _this.searchIcon.classList.remove('e-de-op-search-close-icon');
                    }
                }
                else if (code === 27 && event.keyCode === 27) {
                    _this.showHideOptionsPane(false);
                    _this.documentHelper.owner.documentEditorSettings.showNavigationPane = false;
                    _this.documentHelper.updateFocus();
                }
            };
            this.close = function () {
                _this.clearFocusElement();
                _this.showHideOptionsPane(false);
                _this.documentHelper.owner.documentEditorSettings.showNavigationPane = false;
                _this.resultsListBlock.innerHTML = '';
                _this.focusedIndex = 1;
                _this.isOptionsPane = true;
                _this.documentHelper.updateFocus();
            };
            this.resultListBlockClick = function (args) {
                var currentlist = args.target;
                var element = _this.resultsListBlock.children;
                var index = 0;
                for (var i = 0; i < element.length; i++) {
                    var list_1 = element[i];
                    if (list_1.classList.contains('e-de-search-result-hglt')) {
                        list_1.classList.remove('e-de-search-result-hglt');
                        list_1.children[0].classList.remove('e-de-op-search-word-text');
                        list_1.classList.add('e-de-search-result-item');
                    }
                }
                var list;
                for (var i = 0; i < element.length; i++) {
                    if (currentlist === element[i]) {
                        index = i;
                        list = element[i];
                        if (list.classList.contains('e-de-search-result-item')) {
                            list.classList.remove('e-de-search-result-item');
                            list.classList.add('e-de-search-result-hglt');
                            list.children[0].classList.add('e-de-op-search-word-text');
                            _this.focusedIndex = _this.focusedElement.indexOf(list);
                        }
                    }
                }
                var currentelement = _this.results.innerList[index];
                _this.results.currentIndex = index;
                _this.messageDiv.innerHTML = _this.localeValue.getConstant('Result') + ' ' + (index + 1) + ' ' + _this.localeValue.getConstant('of') + ' ' + _this.resultsListBlock.children.length;
                _this.documentHelper.owner.searchModule.navigate(currentelement);
                _this.documentHelper.owner.searchModule.highlight(_this.results);
                if (list) {
                    list.focus();
                }
            };
            this.documentHelper = documentHelper;
        }
        Object.defineProperty(OptionsPane.prototype, "viewer", {
            get: function () {
                return this.documentHelper.owner.viewer;
            },
            enumerable: true,
            configurable: true
        });
        OptionsPane.prototype.getModuleName = function () {
            return 'OptionsPane';
        };
        OptionsPane.prototype.initOptionsPane = function (localeValue, isRtl) {
            var viewer = this.viewer;
            this.localeValue = localeValue;
            this.optionsPane = ej2_base_1.createElement('div', { className: 'e-de-op', styles: 'display:none;' });
            this.optionsPane.addEventListener('keydown', this.onKeyDownOnOptionPane);
            this.findTab = ej2_base_1.createElement('div', { id: this.documentHelper.owner.containerId + '_findTabDiv', className: 'e-de-op-tab' });
            this.optionsPane.appendChild(this.findTab);
            this.searchDiv = ej2_base_1.createElement('div', {
                className: 'e-de-op-header',
                innerHTML: localeValue.getConstant(this.searchText)
            });
            this.findTab.appendChild(this.searchDiv);
            this.closeButton = ej2_base_1.createElement('button', {
                className: 'e-de-op-close-button e-de-close-icon e-de-op-icon-btn e-btn e-flat e-icon-btn', id: 'close',
                attrs: { type: 'button' }
            });
            this.closeButton.setAttribute('aria-label', localeValue.getConstant('Close'));
            this.findTab.appendChild(this.closeButton);
            var closeSpan = ej2_base_1.createElement('span', { className: 'e-de-op-close-icon e-de-close-icon e-btn-icon e-icons' });
            this.closeButton.appendChild(closeSpan);
            this.focusedElement.push(this.closeButton);
            this.tabDiv = ej2_base_1.createElement('div');
            this.findTab.appendChild(this.tabDiv);
            this.findTabButton = ej2_base_1.createElement('div', { innerHTML: localeValue.getConstant(this.findPaneText) });
            this.replaceTabButton = ej2_base_1.createElement('div', { innerHTML: localeValue.getConstant(this.replacePaneText) });
            this.headingTabButton = ej2_base_1.createElement('div', { innerHTML: localeValue.getConstant(this.headingPaneText) });
            var items = [
                { header: { text: this.headingTabButton } },
                { header: { text: this.findTabButton } },
                { header: { text: this.replaceTabButton } }
            ];
            this.tabInstance = new ej2_navigations_1.Tab({ items: items, enableRtl: isRtl, selected: this.selectedTabItem.bind(this) });
            this.tabInstance.isStringTemplate = true;
            this.tabInstance.appendTo(this.tabDiv);
            this.findTabContentDiv = ej2_base_1.createElement('div', { className: 'e-de-search-tab-content', styles: 'display:none;' });
            this.findTab.appendChild(this.findTabContentDiv);
            this.searchTextBoxContainer = ej2_base_1.createElement('div', { className: 'e-input-group e-de-op-input-group' });
            this.findTabContentDiv.appendChild(this.searchTextBoxContainer);
            this.searchInput = ej2_base_1.createElement('input', { className: 'e-input e-de-search-input', id: this.documentHelper.owner.containerId + '_option_search_text_box', attrs: { placeholder: localeValue.getConstant('Search for') } });
            this.searchTextBoxContainer.appendChild(this.searchInput);
            this.searchIcon = ej2_base_1.createElement('span', {
                className: 'e-de-op-icon e-de-op-search-icon e-input-group-icon e-icon',
                id: this.documentHelper.owner.containerId + '_search-icon'
            });
            this.searchIcon.tabIndex = 0;
            this.searchTextBoxContainer.appendChild(this.searchIcon);
            this.focusedElement.push(this.searchIcon);
            this.navigateToPreviousResult = ej2_base_1.createElement('span', { className: 'e-de-op-icon e-de-op-nav-btn e-arrow-up e-spin-up e-btn-icon e-icon e-input-group-icon' });
            this.navigateToPreviousResult.tabIndex = 0;
            this.searchTextBoxContainer.appendChild(this.navigateToPreviousResult);
            this.focusedElement.push(this.navigateToPreviousResult);
            this.navigateToNextResult = ej2_base_1.createElement('span', { className: 'e-de-op-icon e-de-op-nav-btn e-arrow-down e-spin-down e-btn-icon e-icon e-input-group-icon' });
            this.navigateToNextResult.tabIndex = 0;
            this.searchTextBoxContainer.appendChild(this.navigateToNextResult);
            this.focusedElement.push(this.navigateToNextResult);
            this.checkboxDiv = ej2_base_1.createElement('div', { className: 'e-de-op-more-less', styles: 'display:none' });
            this.matchInput = ej2_base_1.createElement('input', {
                attrs: { type: 'checkbox' },
                id: this.documentHelper.owner.containerId + '_matchCase'
            });
            this.checkboxDiv.appendChild(this.matchInput);
            this.matchCase = new ej2_buttons_1.CheckBox({ label: localeValue.getConstant('Match case'), enableRtl: isRtl, checked: false, change: this.matchChange.bind(this) });
            this.matchCase.appendTo(this.matchInput);
            this.focusedElement.push(this.matchInput);
            this.matchInput.tabIndex = 0;
            var wholeWordLabel;
            Iif (isRtl) {
                wholeWordLabel = '_e-de-rtl';
            }
            else {
                wholeWordLabel = '_e-de-ltr';
            }
            this.wholeInput = ej2_base_1.createElement('input', {
                attrs: { type: 'checkbox' },
                id: this.documentHelper.owner.containerId + '_wholeWord' + wholeWordLabel
            });
            this.checkboxDiv.appendChild(this.wholeInput);
            this.wholeWord = new ej2_buttons_1.CheckBox({ label: localeValue.getConstant('Whole words'), enableRtl: isRtl, checked: false, change: this.wholeWordsChange.bind(this) });
            this.wholeWord.appendTo(this.wholeInput);
            this.focusedElement.push(this.wholeInput);
            this.wholeInput.tabIndex = 0;
            this.findTab.appendChild(this.checkboxDiv);
            this.replaceTabContentDiv = ej2_base_1.createElement('div', { className: 'e-de-op-replacetabcontentdiv', styles: 'display:none;' });
            this.findTab.appendChild(this.replaceTabContentDiv);
            this.createReplacePane(isRtl);
            this.resultContainer = ej2_base_1.createElement('div', { styles: 'width:85%;display:none;', className: 'e-de-op-result-container' });
            this.findTab.appendChild(this.resultContainer);
            this.messageDiv = ej2_base_1.createElement('div', { className: this.documentHelper.owner.containerId + '_messageDiv e-de-op-msg', innerHTML: this.localeValue.getConstant(this.messageDivText), id: this.documentHelper.owner.containerId + '_search_status' });
            this.resultContainer.appendChild(this.messageDiv);
            var resultDiv = ej2_base_1.createElement('div', { id: this.documentHelper.owner.containerId + '_resultDiv' });
            this.optionsPane.appendChild(resultDiv);
            this.findDiv = ej2_base_1.createElement('div', { className: 'findDiv', styles: 'display:none;' });
            resultDiv.appendChild(this.findDiv);
            this.resultsListBlock = ej2_base_1.createElement('div', { id: this.documentHelper.owner.containerId + '_list_box_container', styles: 'display:none;width:270px;list-style:none;padding-right:5px;overflow:auto;', className: 'e-de-result-list-block' });
            this.findDiv.appendChild(this.resultsListBlock);
            this.treeviewDiv = ej2_base_1.createElement('div', { className: 'e-de-scrollbar-hide', styles: 'height:375px;overflow:auto;padding-top:5px', id: this.documentHelper.owner.containerId + '_treeDiv' });
            this.initHeadingTab();
            this.onWireEvents();
            Iif (isRtl) {
                this.optionsPane.classList.add('e-de-rtl');
                this.closeButton.classList.add('e-de-rtl');
                this.searchDiv.classList.add('e-de-rtl');
            }
        };
        OptionsPane.prototype.updateHeadingTab = function () {
            if (!ej2_base_1.isNullOrUndefined(this.treeviewDiv)) {
                this.isUpdateHeading = true;
                this.treeviewDiv.innerHTML = '';
                this.data = this.dataForTreeview();
                this.initHeadingTab();
                this.isUpdateHeading = false;
            }
        };
        OptionsPane.prototype.initHeadingTab = function () {
            var tree = ej2_base_1.createElement('div', { id: 'tree' });
            Iif (!ej2_base_1.isNullOrUndefined(this.data) && this.data.length > 0) {
                this.treeviewObject = new ej2_navigations_1.TreeView({
                    fields: { dataSource: this.data, id: 'id', text: 'name', parentID: 'pid', hasChildren: 'hasChild', tooltip: 'tooltipText' },
                    nodeClicked: this.nodeClick.bind(this),
                    cssClass: 'e-de-custom-treeview',
                    nodeTemplate: this.customTemplate.bind(this),
                });
                if (!ej2_base_1.isNullOrUndefined(this.treeviewDiv)) {
                    this.treeviewDiv.innerHTML = "";
                    this.treeviewObject.appendTo(tree);
                    this.treeviewDiv.appendChild(tree);
                    if (!ej2_base_1.isNullOrUndefined(this.findTab)) {
                        this.findTab.appendChild(this.treeviewDiv);
                    }
                }
            }
            else {
                Eif (!ej2_base_1.isNullOrUndefined(this.treeviewDiv)) {
                    this.treeviewDiv.innerHTML = this.localeValue.getConstant('No Headings');
                    this.findTab.appendChild(this.treeviewDiv);
                }
            }
        };
        OptionsPane.prototype.customTemplate = function (data) {
            var s = document.createElement('span');
            s.innerText = data.name;
            return s.outerHTML;
        };
        OptionsPane.prototype.nodeClick = function (args) {
            var targetNodeId = this.treeviewObject.selectedNodes[0];
            if (!ej2_base_1.isNullOrUndefined(targetNodeId))
                this.documentHelper.selection.navigateBookmark(this.data[(targetNodeId - 1)].hyperlink.toString(), true);
        };
        OptionsPane.prototype.dataForTreeview = function () {
            this.data = [];
            var datas = this.createDataSourceForTreeview();
            this.documentHelper.blockToShift = undefined;
            var data = [];
            Eif (!ej2_base_1.isNullOrUndefined(this.treeviewDiv)) {
                var index = 1;
                Iif (!ej2_base_1.isNullOrUndefined(datas) && datas.length > 0) {
                    for (var i = 0; i < datas.length; i++) {
                        var parentId = null;
                        if (datas[i].paragraphFormat.outlineLevel !== "Level1" && i > 0) {
                            var currentIndex = i - 1;
                            if (datas[i].paragraphFormat.outlineLevel === datas[i - 1].paragraphFormat.outlineLevel) {
                                parentId = data[currentIndex].pid;
                            }
                            else if (Number(datas[i].paragraphFormat.outlineLevel.substr(5, 1)) > Number(datas[currentIndex].paragraphFormat.outlineLevel.substr(5, 1))) {
                                parentId = data[currentIndex].id;
                                data[currentIndex].hasChild = true;
                                data[currentIndex].expanded = true;
                            }
                            else {
                                currentIndex--;
                                while (currentIndex > 0) {
                                    if (Number(datas[i].paragraphFormat.outlineLevel.substr(5, 1)) > Number(datas[currentIndex].paragraphFormat.outlineLevel.substr(5, 1))) {
                                        parentId = data[currentIndex].id;
                                        data[currentIndex].hasChild = true;
                                        data[currentIndex].expanded = true;
                                        break;
                                    }
                                    else if (Number(datas[i].paragraphFormat.outlineLevel.substr(5, 1)) === Number(datas[currentIndex].paragraphFormat.outlineLevel.substr(5, 1))) {
                                        parentId = data[currentIndex].pid;
                                        break;
                                    }
                                    currentIndex--;
                                }
                            }
                        }
                        var widget = datas[i].childWidgets[0];
                        var name_1 = void 0;
                        var tooltipText = void 0;
                        var text = void 0;
                        if (ej2_base_1.isNullOrUndefined(widget.children[3])) {
                            name_1 = widget.children[0].text;
                            tooltipText = widget.children[0].text;
                            var value = index;
                            text = 'Toc00000000' + value;
                            index++;
                        }
                        else {
                            tooltipText = widget.children[3].text;
                            name_1 = widget.children[3].text;
                            text = widget.children[1].text;
                        }
                        var newItem = {
                            pid: parentId,
                            id: i + 1,
                            name: name_1,
                            hyperlink: text.length > 15 ? text.substring(15, text.length - 2) : text,
                            tooltipText: tooltipText,
                        };
                        data.push(newItem);
                    }
                }
            }
            return data;
        };
        OptionsPane.prototype.createDataSourceForTreeview = function () {
            var headingPaneSettings = {
                startLevel: 1,
                endLevel: 9,
                includeOutlineLevels: true,
                includeHyperlink: true,
            };
            var startPosition = this.documentHelper.selection.start.clone();
            var endPosition = this.documentHelper.selection.end.clone();
            this.documentHelper.owner.editor.initComplexHistory('TOC');
            var code = undefined;
            code = this.constructHeadingFieldCode(headingPaneSettings);
            var widgets = this.documentHelper.owner.editorModule.buildToc(this.validateHeadingSettings(headingPaneSettings), code, false, true, true);
            Eif (this.documentHelper.owner.editorHistory) {
                this.documentHelper.owner.editorHistory.updateComplexHistory();
                Iif (this.documentHelper.owner.editorHistory.undoStack.length > 1
                    && !ej2_base_1.isNullOrUndefined(this.documentHelper.owner.editorHistory.undoStack[this.documentHelper.owner.editorHistory.undoStack.length - 1].modifiedActions)) {
                    this.documentHelper.owner.editorHistory.undoStack.pop();
                }
            }
            this.documentHelper.selection.selectPosition(startPosition, endPosition);
            return widgets;
        };
        OptionsPane.prototype.validateHeadingSettings = function (navigationSettings) {
            Iif (ej2_base_1.isNullOrUndefined(navigationSettings.startLevel) || navigationSettings.startLevel < 1) {
                navigationSettings.startLevel = 1;
            }
            Iif (ej2_base_1.isNullOrUndefined(navigationSettings.endLevel) || navigationSettings.endLevel < navigationSettings.endLevel) {
                navigationSettings.endLevel = navigationSettings.startLevel > 3 ? navigationSettings.startLevel : 3;
            }
            Iif (ej2_base_1.isNullOrUndefined(navigationSettings.includeHyperlink)) {
                navigationSettings.includeHyperlink = false;
            }
            Eif (ej2_base_1.isNullOrUndefined(navigationSettings.includePageNumber)) {
                navigationSettings.includePageNumber = false;
            }
            Eif (ej2_base_1.isNullOrUndefined(navigationSettings.rightAlign)) {
                navigationSettings.rightAlign = false;
            }
            Eif (ej2_base_1.isNullOrUndefined(navigationSettings.levelSettings)) {
                navigationSettings.levelSettings = {};
            }
            return navigationSettings;
        };
        OptionsPane.prototype.constructHeadingFieldCode = function (navigationSettings) {
            var headingFieldCode = 'TOC';
            Eif (!ej2_base_1.isNullOrUndefined(navigationSettings.startLevel) && navigationSettings.startLevel !== 0 && !ej2_base_1.isNullOrUndefined(navigationSettings.endLevel) && navigationSettings.endLevel !== 0) {
                headingFieldCode = headingFieldCode + ' \\o "' + navigationSettings.startLevel + '-' + navigationSettings.endLevel + '"';
            }
            Iif (navigationSettings.includePageNumber && !navigationSettings.rightAlign) {
                headingFieldCode = headingFieldCode + ' \\p " "';
            }
            Eif (!navigationSettings.includePageNumber) {
                headingFieldCode = headingFieldCode + ' \\n';
            }
            Eif (navigationSettings.includeHyperlink) {
                headingFieldCode = headingFieldCode + ' \\h \\z';
            }
            Eif (navigationSettings.includeOutlineLevels) {
                headingFieldCode = headingFieldCode + ' \\u';
            }
            var tSwitch = this.constructTSwitch(navigationSettings);
            Iif (tSwitch.length > 6) {
                headingFieldCode = headingFieldCode + tSwitch;
            }
            return headingFieldCode;
        };
        OptionsPane.prototype.constructTSwitch = function (navigationSettings) {
            var tSwitch = '';
            var prefix = ' \\t ';
            Iif (!ej2_base_1.isNullOrUndefined(navigationSettings.levelSettings)) {
                for (var _i = 0, _a = Object.keys(navigationSettings.levelSettings); _i < _a.length; _i++) {
                    var key = _a[_i];
                    tSwitch = tSwitch + key + ',' + navigationSettings.levelSettings[key].toString() + ',';
                }
            }
            tSwitch = tSwitch.slice(0, -1);
            tSwitch = prefix + '"' + tSwitch + '"';
            return tSwitch;
        };
        OptionsPane.prototype.createReplacePane = function (isRtl) {
            this.replaceDiv = ej2_base_1.createElement('div');
            this.replaceTabContentDiv.appendChild(this.replaceDiv);
            this.replaceWith = ej2_base_1.createElement('input', {
                className: 'e-de-op-replacewith e-input',
                attrs: { placeholder: this.localeValue.getConstant('Replace with') }
            });
            this.replaceDiv.appendChild(this.replaceWith);
            var replaceButtonDivTextAlign;
            var replaceButtonMargin;
            Iif (isRtl) {
                replaceButtonDivTextAlign = 'text-align:left';
                replaceButtonMargin = 'margin-left:10px';
            }
            else {
                replaceButtonDivTextAlign = 'text-align:right';
                replaceButtonMargin = 'margin-right:10px';
            }
            var replaceButtonDiv = ej2_base_1.createElement('div', { styles: replaceButtonDivTextAlign, className: 'e-de-op-dlg-footer' });
            this.replaceDiv.appendChild(replaceButtonDiv);
            this.replaceButton = ej2_base_1.createElement('button', {
                className: 'e-control e-btn e-flat e-replace',
                styles: replaceButtonMargin,
                innerHTML: this.localeValue.getConstant(this.replaceButtonText),
                attrs: { type: 'button' }
            });
            replaceButtonDiv.appendChild(this.replaceButton);
            this.replaceButton.setAttribute('aria-label', this.localeValue.getConstant(this.replaceButtonText));
            this.replaceAllButton = ej2_base_1.createElement('button', {
                className: 'e-control e-btn e-flat e-replaceall',
                innerHTML: this.localeValue.getConstant(this.replaceAllButtonText),
                attrs: { type: 'button' }
            });
            replaceButtonDiv.appendChild(this.replaceAllButton);
            this.replaceAllButton.setAttribute('aria-label', this.localeValue.getConstant(this.replaceAllButtonText));
            this.matchDiv = ej2_base_1.createElement('div', { styles: 'display:none;padding-top:10px;' });
            this.replaceDiv.appendChild(this.matchDiv);
            var emptyDiv6 = ej2_base_1.createElement('div', { className: 'e-de-op-search-replacediv' });
            this.replaceDiv.appendChild(emptyDiv6);
            this.occurrenceDiv = ej2_base_1.createElement('div', { styles: 'display:none;' });
            this.replaceDiv.appendChild(this.occurrenceDiv);
        };
        OptionsPane.prototype.selectedTabItem = function (args) {
            var contentParent = this.findTab.getElementsByClassName('e-content').item(0);
            Eif (args.previousIndex !== args.selectedIndex) {
                var previousTab = contentParent.children[0];
                var nextTab = contentParent.children[1];
                var element = previousTab.firstElementChild;
                Iif (element) {
                    if (element.parentElement) {
                        element.parentElement.removeChild(element);
                    }
                    nextTab.appendChild(element);
                }
            }
            var selectedElement = contentParent.children[0];
            Eif (!ej2_base_1.isNullOrUndefined(selectedElement)) {
                Iif (args.selectedIndex === 0) {
                    this.isOptionsPane = false;
                    this.onHeadingPane();
                }
                else Eif (args.selectedIndex === 1) {
                    this.isOptionsPane = true;
                    this.onFindPane();
                }
                else {
                    this.isOptionsPane = false;
                    this.onReplacePane();
                }
            }
        };
        OptionsPane.prototype.navigateSearchResult = function (navigate) {
            if (navigate) {
                this.documentHelper.owner.searchModule.navigate(this.results.innerList[this.results.currentIndex]);
            }
            this.documentHelper.owner.searchModule.highlight(this.results);
            this.documentHelper.owner.searchModule.addFindResultView(this.results);
            this.resultsListBlock.style.display = 'block';
            this.resultContainer.style.display = 'block';
            var lists = this.documentHelper.owner.findResultsList;
            var text = '';
            for (var i = 0; i < lists.length; i++) {
                text += lists[i];
            }
            var resultsContainerHeight = this.optionsPane.offsetHeight - this.findTab.offsetHeight;
            this.resultsListBlock.style.height = resultsContainerHeight + 'px';
            this.clearFocusElement();
            this.resultsListBlock.innerHTML = text;
            for (var i = 0; i < this.resultsListBlock.children.length; i++) {
                this.focusedElement.push(this.resultsListBlock.children[i]);
            }
            var currentIndexValue = this.results.currentIndex;
            this.messageDiv.innerHTML = this.localeValue.getConstant('Result') + ' ' + (currentIndexValue + 1) + ' ' + this.localeValue.getConstant('of') + ' ' + this.resultsListBlock.children.length;
            var listElement = this.resultsListBlock.children[currentIndexValue];
            if (listElement.classList.contains('e-de-search-result-item')) {
                listElement.classList.remove('e-de-search-result-item');
                listElement.classList.add('e-de-search-result-hglt');
                listElement.children[0].classList.add('e-de-op-search-word-text');
                this.scrollToPosition(listElement);
            }
        };
        OptionsPane.prototype.wholeWordsChange = function () {
            if (this.matchInput.checked && this.wholeInput.checked) {
                this.findOption = 'CaseSensitiveWholeWord';
            }
            else if (this.matchInput.checked && !(this.wholeInput.checked)) {
                this.findOption = 'CaseSensitive';
            }
            else if (!(this.matchInput.checked) && this.wholeInput.checked) {
                this.findOption = 'WholeWord';
            }
            else {
                this.findOption = 'None';
            }
            this.searchOptionChange();
        };
        OptionsPane.prototype.matchChange = function () {
            if (this.matchInput.checked && this.wholeInput.checked) {
                this.findOption = 'CaseSensitiveWholeWord';
            }
            else if (!(this.matchInput.checked) && this.wholeInput.checked) {
                this.findOption = 'WholeWord';
            }
            else if (this.matchInput.checked && !(this.wholeInput.checked)) {
                this.findOption = 'CaseSensitive';
            }
            else {
                this.findOption = 'None';
            }
            var resultsContainerHeight = this.optionsPane.offsetHeight - this.findTab.offsetHeight;
            this.resultsListBlock.style.height = resultsContainerHeight + 'px';
            this.searchOptionChange();
        };
        OptionsPane.prototype.onWireEvents = function () {
            this.searchIcon.addEventListener('click', this.searchIconClickInternal);
            this.navigateToNextResult.addEventListener('click', this.navigateNextResultButtonClick);
            this.navigateToPreviousResult.addEventListener('click', this.navigatePreviousResultButtonClick);
            this.searchInput.addEventListener('keydown', this.onKeyDown);
            this.searchInput.addEventListener('keyup', this.onEnableDisableReplaceButton);
            this.resultsListBlock.addEventListener('click', this.resultListBlockClick);
            this.closeButton.addEventListener('click', this.close);
            this.replaceButton.addEventListener('click', this.onReplaceButtonClick);
            this.replaceAllButton.addEventListener('click', this.onReplaceAllButtonClick);
        };
        OptionsPane.prototype.onKeyDownInternal = function () {
            var inputElement = document.getElementById(this.documentHelper.owner.containerId + '_option_search_text_box');
            if (ej2_base_1.isNullOrUndefined(inputElement)) {
                return;
            }
            inputElement.blur();
            var text = inputElement.value;
            if (text === '') {
                return;
            }
            if (text.length >= 1 && this.searchIcon.classList.contains('e-de-op-search-icon')) {
                this.searchIcon.classList.add('e-de-op-search-close-icon');
                this.searchIcon.classList.remove('e-de-op-search-icon');
            }
            var height = this.isOptionsPane ? 215 : 292;
            this.clearSearchResultItems();
            this.documentHelper.owner.searchModule.clearSearchHighlight();
            var pattern = this.documentHelper.owner.searchModule.textSearch.stringToRegex(text, this.findOption);
            var endSelection = this.documentHelper.selection.end;
            var index = endSelection.getHierarchicalIndexInternal();
            this.results = this.documentHelper.owner.searchModule.textSearch.findAll(pattern, this.findOption, index);
            var results = this.results;
            if (ej2_base_1.isNullOrUndefined(results)) {
                this.viewer.renderVisiblePages();
            }
            if (results != null && results.length > 0) {
                if ((this.focusedElement.indexOf(this.navigateToPreviousResult) === -1) && this.isOptionsPane) {
                    this.focusedElement.push(this.navigateToPreviousResult);
                }
                if ((this.focusedElement.indexOf(this.navigateToNextResult) === -1) && this.isOptionsPane) {
                    this.focusedElement.push(this.navigateToNextResult);
                }
                this.documentHelper.owner.searchModule.navigate(this.results.innerList[this.results.currentIndex]);
                this.documentHelper.owner.searchModule.highlight(results);
                this.documentHelper.owner.searchModule.addFindResultView(results);
                this.resultContainer.style.display = 'block';
                this.resultsListBlock.style.display = 'block';
                var resultsContainerHeight = this.optionsPane.offsetHeight - this.findTab.offsetHeight;
                this.resultsListBlock.style.height = resultsContainerHeight + 'px';
                var list = this.documentHelper.owner.findResultsList;
                var text_1 = '';
                this.clearFocusElement();
                this.resultsListBlock.innerHTML = '';
                for (var i = 0; i < list.length; i++) {
                    text_1 += list[i];
                }
                this.resultsListBlock.innerHTML = text_1;
                for (var i = 0; i < this.resultsListBlock.children.length; i++) {
                    this.focusedElement.push(this.resultsListBlock.children[i]);
                }
                var lists = this.resultsListBlock.children;
                var currentIndex = this.results.currentIndex;
                this.messageDiv.innerHTML = this.localeValue.getConstant('Result') + ' ' + (currentIndex + 1) + ' ' + this.localeValue.getConstant('of') + ' ' + this.resultsListBlock.children.length;
                var listElement = this.resultsListBlock.children[currentIndex];
                if (listElement.classList.contains('e-de-search-result-item')) {
                    listElement.classList.remove('e-de-search-result-item');
                    listElement.classList.add('e-de-search-result-hglt');
                    listElement.children[0].classList.add('e-de-op-search-word-text');
                }
                this.navigateToNextResult.focus();
                this.focusedIndex = this.focusedElement.indexOf(this.navigateToNextResult);
                this.getMessageDivHeight();
            }
            else {
                this.messageDiv.innerHTML = this.localeValue.getConstant('No matches');
                this.resultContainer.style.display = 'block';
                this.resultsListBlock.style.display = 'none';
                this.clearFocusElement();
                this.resultsListBlock.innerHTML = '';
            }
        };
        OptionsPane.prototype.onHeadingPane = function () {
            this.treeviewDiv.style.display = 'block';
            this.refreshHeadingPaneHeight();
            this.messageDiv.classList.remove('e-de-op-msg');
            this.messageDiv.classList.remove('e-de-op-replace-messagediv');
            this.replaceDiv.style.display = 'none';
            this.occurrenceDiv.style.display = 'none';
            this.findDiv.style.display = 'none';
            this.findTabContentDiv.style.display = 'none';
            this.checkboxDiv.style.display = 'none';
            this.resultContainer.style.display = 'none';
        };
        OptionsPane.prototype.refreshHeadingPaneHeight = function () {
            if (!ej2_base_1.isNullOrUndefined(this.optionsPane) && !ej2_base_1.isNullOrUndefined(this.searchDiv) && !ej2_base_1.isNullOrUndefined(this.tabDiv)) {
                var computedStyle = window.getComputedStyle(this.searchDiv);
                var marginBottom = parseFloat(computedStyle.marginBottom);
                var resultsContainerHeight = this.optionsPane.offsetHeight - (marginBottom + this.searchDiv.offsetHeight + this.tabDiv.offsetHeight);
                this.treeviewDiv.style.height = resultsContainerHeight + 'px';
            }
        };
        OptionsPane.prototype.onFindPane = function () {
            this.replaceDiv.style.display = 'none';
            this.occurrenceDiv.style.display = 'none';
            this.treeviewDiv.style.display = 'none';
            this.findDiv.style.display = 'block';
            this.findTabContentDiv.style.display = 'block';
            this.checkboxDiv.style.display = 'block';
            this.resultContainer.style.display = 'block';
            Iif (!ej2_base_1.isNullOrUndefined(this.results) && this.results.length === 0) {
                this.resultsListBlock.innerHTML = '';
                this.resultsListBlock.style.display = 'none';
                this.messageDiv.innerHTML = this.localeValue.getConstant('No matches');
            }
            var height = this.isOptionsPane ? 215 : 292;
            var resultsContainerHeight = this.optionsPane.offsetHeight - (this.findTab.offsetHeight - this.replaceTabContentDiv.offsetHeight);
            this.resultsListBlock.style.height = resultsContainerHeight + 'px';
            this.replaceTabContentDiv.style.display = 'none';
            this.findDiv.style.display = 'block';
            this.messageDiv.style.display = 'block';
            this.focusedElement = [];
            this.focusedElement.push(this.closeButton, this.searchInput, this.searchIcon, this.navigateToPreviousResult, this.navigateToNextResult, this.matchInput, this.wholeInput);
            this.focusedIndex = 1;
            this.searchInput.select();
            this.getMessageDivHeight();
        };
        OptionsPane.prototype.getMessageDivHeight = function () {
            Iif (!this.isOptionsPane && this.messageDiv.classList.contains('e-de-op-msg')) {
                this.messageDiv.classList.add('e-de-op-replace-messagediv');
                this.messageDiv.classList.remove('e-de-op-msg');
            }
            else Iif (this.isOptionsPane && this.messageDiv.classList.contains('e-de-op-replace-messagediv')) {
                this.messageDiv.classList.add('e-de-op-msg');
                this.messageDiv.classList.remove('e-de-op-replace-messagediv');
            }
        };
        OptionsPane.prototype.onReplacePane = function () {
            this.findDiv.style.display = 'block';
            this.replaceDiv.style.display = 'block';
            this.replaceTabContentDiv.style.display = 'block';
            this.findDiv.style.display = 'block';
            this.treeviewDiv.style.display = 'none';
            this.findTabContentDiv.style.display = 'block';
            this.checkboxDiv.style.display = 'block';
            this.resultContainer.style.display = 'block';
            var height = this.isOptionsPane ? 215 : 292;
            var resultsContainerHeight = this.optionsPane.offsetHeight - this.findTab.offsetHeight;
            this.resultsListBlock.style.height = resultsContainerHeight + 'px';
            this.isOptionsPane = false;
            if (this.searchInput.value.length !== 0) {
                this.replaceButton.disabled = false;
                this.replaceAllButton.disabled = false;
            }
            else {
                this.replaceButton.disabled = true;
                this.replaceAllButton.disabled = true;
            }
            this.focusedElement = [];
            this.focusedElement.push(this.closeButton, this.searchInput, this.searchIcon, this.navigateToPreviousResult, this.navigateToNextResult, this.matchInput, this.wholeInput, this.replaceWith, this.replaceButton, this.replaceAllButton);
            this.focusedIndex = 1;
            if (this.searchInput.value === '') {
                this.searchInput.select();
            }
            else {
                this.replaceWith.select();
            }
            this.getMessageDivHeight();
        };
        OptionsPane.prototype.replaceAll = function () {
            var optionsPane = this.optionsPane;
            var findText = this.searchInput.value;
            var replaceText = this.replaceWith.value;
            if (findText !== '' && !ej2_base_1.isNullOrUndefined(findText)) {
                var pattern = this.documentHelper.owner.searchModule.textSearch.stringToRegex(findText, this.findOption);
                var endSelection = this.documentHelper.selection.end;
                var index = endSelection.getHierarchicalIndexInternal();
                var results = this.documentHelper.owner.searchModule.textSearch.findAll(pattern, this.findOption, index);
                var replace = ej2_base_1.isNullOrUndefined(replaceText) ? '' : replaceText;
                var count = ej2_base_1.isNullOrUndefined(results) ? 0 : results.length;
                this.documentHelper.owner.searchModule.replaceAll(replace, results);
                this.documentHelper.layout.isReplacingAll = false;
                this.matchDiv.style.display = 'block';
                this.matchDiv.innerHTML = this.localeValue.getConstant('All Done') + '!';
                this.occurrenceDiv.style.display = 'block';
                this.occurrenceDiv.innerHTML = this.localeValue.getConstant('We replaced all') + ' ' + count + ' ' + this.localeValue.getConstant('instances') + ' ' + this.localeValue.getConstant('of') + ' "' + findText + '" ' + this.localeValue.getConstant('with') + ' "' + replaceText + '" ';
            }
        };
        OptionsPane.prototype.hideMatchDiv = function () {
            this.matchDiv.style.display = 'none';
            this.occurrenceDiv.style.display = 'none';
        };
        OptionsPane.prototype.updateListItems = function (textSearchResult) {
            var searchElements = this.resultsListBlock.getElementsByClassName('e-de-search-result-hglt');
            for (var j = 0; j < searchElements.length; j++) {
                var list = searchElements[j];
                ej2_base_1.classList(list, ['e-de-search-result-item'], ['e-de-search-result-hglt']);
                ej2_base_1.classList(list.children[0], [], ['e-de-op-search-word-text']);
            }
            var listElement = this.resultsListBlock.children[this.results.currentIndex];
            ej2_base_1.classList(listElement, ['e-de-search-result-hglt'], ['e-de-search-result-item']);
            ej2_base_1.classList(listElement.children[0], ['e-de-op-search-word-text'], []);
            this.scrollToPosition(listElement);
            this.documentHelper.owner.searchModule.navigate(textSearchResult);
            this.documentHelper.owner.searchModule.highlight(this.results);
        };
        OptionsPane.prototype.scrollToPosition = function (list) {
            var rect = list.getBoundingClientRect();
            var top;
            if (rect.top > 0) {
                top = rect.top - list.parentElement.getBoundingClientRect().top;
                if ((list.parentElement.offsetHeight - top) <= list.offsetHeight) {
                    if (Math.ceil(top + list.offsetHeight) === list.parentElement.scrollHeight) {
                        list.parentElement.scrollTop = top;
                    }
                    list.parentElement.scrollTop = list.parentElement.scrollTop + (list.parentElement.offsetHeight / 100) * 30;
                }
                else if (top < 0) {
                    list.parentElement.scrollTop = list.parentElement.scrollTop - (list.parentElement.offsetHeight / 100) * 30;
                }
            }
            else {
                list.parentElement.scrollTop = 0;
            }
        };
        OptionsPane.prototype.clearFocusElement = function () {
            for (var i = 0; i < this.resultsListBlock.children.length; i++) {
                var index = this.focusedElement.indexOf(this.resultsListBlock.children[i]);
                if (index !== -1) {
                    this.focusedElement.splice(index, 1);
                }
            }
            this.focusedIndex = 1;
        };
        OptionsPane.prototype.showHideOptionsPane = function (show) {
            Eif (!ej2_base_1.isNullOrUndefined(this.documentHelper.owner.selectionModule)) {
                this.documentHelper.owner.fireOptionPaneChange(show);
                if (show) {
                    this.localeValue = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
                    this.localeValue.setLocale(this.documentHelper.owner.locale);
                    Eif (ej2_base_1.isNullOrUndefined(this.optionsPane)) {
                        this.initOptionsPane(this.localeValue, this.documentHelper.owner.enableRtl);
                        var isRtl = this.documentHelper.owner.enableRtl;
                        var optionsPaneContainerStyle = void 0;
                        Iif (isRtl) {
                            optionsPaneContainerStyle = 'display:inline-flex;direction:rtl;';
                        }
                        else {
                            optionsPaneContainerStyle = 'display:inline-flex;';
                        }
                        this.documentHelper.optionsPaneContainer.setAttribute('style', optionsPaneContainerStyle);
                        this.documentHelper.optionsPaneContainer.insertBefore(this.documentHelper.owner.optionsPaneModule.optionsPane, this.documentHelper.viewerContainer);
                    }
                    this.optionsPane.style.display = 'block';
                    Iif (this.documentHelper.owner.isReadOnlyMode) {
                        this.tabInstance.hideTab(2);
                    }
                    else {
                        this.tabInstance.hideTab(2, false);
                    }
                    Iif (this.isReplace && !this.documentHelper.owner.isReadOnlyMode) {
                        this.tabInstance.select(2);
                        this.isReplace = false;
                        this.isOptionsPane = false;
                    }
                    else {
                        this.tabInstance.select(1);
                    }
                    var treeViewResult = document.getElementById(this.documentHelper.owner.containerId + '_treeDiv');
                    Eif (!ej2_base_1.isNullOrUndefined(treeViewResult)) {
                        treeViewResult.innerHTML = '';
                        this.data = this.dataForTreeview();
                        this.initHeadingTab();
                    }
                    this.searchDiv.innerHTML = this.localeValue.getConstant(this.searchText);
                    this.isOptionsPaneShow = true;
                    var textBox = document.getElementById(this.documentHelper.owner.getDocumentEditorElement().id + '_option_search_text_box');
                    var selectedText = this.documentHelper.owner.selectionModule.text;
                    Eif (!ej2_base_1.isNullOrUndefined(selectedText)) {
                        var char = ['\v', '\r'];
                        var index = editor_helper_1.HelperMethods.indexOfAny(selectedText, char);
                        selectedText = index < 0 ? selectedText : selectedText.substring(0, index);
                    }
                    textBox.value = selectedText;
                    textBox.select();
                    Iif (!ej2_base_1.isNullOrUndefined(textBox.value) && textBox.value.match(/[!\@\#$%\^&*\(\)_\-+\=\[\]\{\};:"\|,.<>\/?`~\s\\؟°÷×،؛]/) && textBox.value !== "") {
                        this.wholeInput.checked = false;
                        this.wholeWord.disabled = true;
                    }
                    else {
                        this.wholeWord.disabled = false;
                    }
                    this.messageDiv.innerHTML = '';
                    Iif (this.searchIcon.classList.contains('e-de-op-search-close-icon')) {
                        this.searchIcon.classList.add('e-de-op-search-icon');
                        this.searchIcon.classList.remove('e-de-op-search-close-icon');
                    }
                    this.documentHelper.selection.caret.style.display = 'none';
                    this.focusedIndex = 1;
                    this.focusedElement = [];
                    Eif (this.isOptionsPane) {
                        this.focusedElement.push(this.closeButton, this.searchInput, this.searchIcon, this.navigateToPreviousResult, this.navigateToNextResult, this.matchInput, this.wholeInput);
                    }
                    else {
                        this.focusedElement.push(this.closeButton, this.searchInput, this.searchIcon, this.navigateToPreviousResult, this.navigateToNextResult, this.matchInput, this.wholeInput, this.replaceWith, this.replaceButton, this.replaceAllButton);
                    }
                    this.documentHelper.updateViewerSize();
                }
                else {
                    Iif (!ej2_base_1.isNullOrUndefined(this.optionsPane)) {
                        this.clearSearchResultItems();
                        if (!ej2_base_1.isNullOrUndefined(this.documentHelper.owner.searchModule)) {
                            this.documentHelper.owner.searchModule.clearSearchHighlight();
                        }
                        this.isOptionsPaneShow = false;
                        var resultListBox = document.getElementById(this.documentHelper.owner.containerId + '_list_box_container');
                        var message = document.getElementById(this.documentHelper.owner.containerId + '_search_status');
                        if (!ej2_base_1.isNullOrUndefined(resultListBox) && !ej2_base_1.isNullOrUndefined(message)) {
                            resultListBox.style.display = 'none';
                            this.clearFocusElement();
                            resultListBox.innerHTML = '';
                            message.innerHTML = this.localeValue.getConstant('No matches');
                        }
                        var treeViewResult = document.getElementById(this.documentHelper.owner.containerId + '_treeDiv');
                        if (!ej2_base_1.isNullOrUndefined(treeViewResult)) {
                            treeViewResult.innerHTML = '';
                        }
                    }
                    this.documentHelper.updateViewerSize();
                    Iif (!ej2_base_1.isNullOrUndefined(this.optionsPane)) {
                        if (this.optionsPane.style.display !== 'none') {
                            this.documentHelper.selection.updateCaretPosition();
                            this.optionsPane.style.display = 'none';
                        }
                    }
                    if (this.documentHelper.owner.enableAutoFocus) {
                        this.documentHelper.updateFocus();
                    }
                    if (this.documentHelper.owner.enableAutoFocus) {
                        this.documentHelper.selection.caret.style.display = 'block';
                    }
                }
                this.documentHelper.owner.triggerResize();
            }
        };
        OptionsPane.prototype.clearSearchResultItems = function () {
            if (!ej2_base_1.isNullOrUndefined(this.documentHelper.owner.findResultsList)) {
                this.documentHelper.owner.findResultsList = [];
            }
        };
        OptionsPane.prototype.destroy = function () {
            if (this.optionsPane) {
                this.optionsPane.innerHTML = '';
                this.optionsPane = undefined;
            }
            if (this.resultsListBlock) {
                this.resultsListBlock.innerHTML = '';
                this.resultsListBlock = undefined;
            }
            if (this.messageDiv) {
                this.messageDiv.innerHTML = '';
                this.messageDiv = undefined;
            }
            if (this.resultContainer) {
                this.resultContainer.innerHTML = '';
            }
            this.resultContainer = undefined;
            if (this.searchInput) {
                this.searchInput.value = '';
                this.searchInput = undefined;
            }
            if (this.searchDiv) {
                this.searchDiv.innerHTML = '';
                this.searchDiv = undefined;
            }
            if (this.searchTextBoxContainer) {
                this.searchTextBoxContainer.innerHTML = '';
                this.searchTextBoxContainer = undefined;
            }
            if (this.replaceWith) {
                this.replaceWith.innerHTML = '';
                this.replaceWith = undefined;
            }
            if (this.findDiv) {
                this.findDiv.innerHTML = '';
                this.findDiv = undefined;
            }
            if (this.treeviewDiv) {
                this.treeviewDiv.innerHTML = '';
                this.treeviewDiv = undefined;
            }
            if (this.replaceButton) {
                this.replaceButton.innerHTML = '';
                this.replaceButton = undefined;
            }
            if (this.replaceAllButton) {
                this.replaceAllButton.innerHTML = '';
                this.replaceAllButton = undefined;
            }
            if (this.matchInput) {
                this.matchInput.innerHTML = '';
                this.matchCase = undefined;
            }
            if (this.wholeInput) {
                this.wholeInput.innerHTML = '';
                this.wholeWord = undefined;
            }
            Iif (!ej2_base_1.isNullOrUndefined(this.results)) {
                this.results.destroy();
            }
            if (this.focusedElement) {
                this.focusedElement = [];
            }
            this.focusedElement = undefined;
            this.destroyInternal();
            this.documentHelper = undefined;
        };
        OptionsPane.prototype.destroyInternal = function () {
            if (this.searchText) {
                this.searchText = undefined;
            }
            if (this.resultsText) {
                this.resultsText = undefined;
            }
            if (this.messageDivText) {
                this.messageDivText = undefined;
            }
            if (this.replaceButtonText) {
                this.replaceButtonText = undefined;
            }
            if (this.replaceAllButtonText) {
                this.replaceAllButtonText = undefined;
            }
            if (this.tabDiv) {
                this.tabDiv = undefined;
            }
        };
        return OptionsPane;
    }());
    exports.OptionsPane = OptionsPane;
});