all files / document-editor-container/tool-bar/ tool-bar.js

57.28% Statements 350/611
40.63% Branches 156/384
46.81% Functions 22/47
57.28% Lines 350/611
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   93× 93× 93×     2764×         125×     59× 59× 59×   59×     59× 59× 59× 59× 59× 59× 59× 59× 59× 59× 59× 59× 59×   59×       59× 57×       59× 59× 59× 59× 59×   59× 59× 59× 59× 59× 59×                   59×   59× 59×               59×   59× 59×                         59×   59× 59×           59×       59× 59×             59×   59×     59×     59×     59×     59× 59×   59× 59×   59× 59× 59× 59×     59×                     59×   59× 59×                 59×                                                                                                                                       708× 708× 708× 708× 708× 708×         708×   59× 59× 59×   59×                                                                                                       59× 59× 59× 59× 59× 59× 1888× 59×   1829× 59×   1770× 354×   1416× 354×   1062× 59×     1003×   1888×   413×     413×   59×       59×   59×       59×   59×       59×   59×       59×   59×         59×   59×           59×   59×       59×   59×       59×   59×         59×   59×         59×   59×           59×   59×         59×   59×       59×   59×       59×   59×         59×   59×       59×   59×       59×   59×             59×   59×       59×   59×         59×   59×           59×   59×           59×   59×           59×   59×       59×   59×         59×           59× 1888× 1888× 1888× 1888×     59×                                                                                                                                                                                               181× 181×     179× 179×                                                                                                                                                                                                                                                                                                       74× 74× 19×     257× 257× 257× 257× 257×   254× 245×       245×         74× 74× 74× 2364× 2364× 2364×     1550×   1549×               74×   1475×       1475× 1475× 1455×       74× 74×   74× 74×                                                                     74× 73× 73×   73×   74× 74×   74×   74×                         151× 151× 151× 151× 150×     151× 151× 151× 150×                             73× 73×           57× 57× 57×   57× 57× 57×   57× 57× 57×   57× 57× 57×   57× 57× 57×   57× 57× 57×   57× 57× 57× 57× 57×   57× 57× 57×   57× 57×   57× 57×   57× 57× 57×   57× 57× 57× 57×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-navigations", "@syncfusion/ej2-buttons", "@syncfusion/ej2-splitbuttons", "@syncfusion/ej2-popups", "../../document-editor/base/index", "./../../index", "@syncfusion/ej2-lists"], function (require, exports, ej2_base_1, ej2_navigations_1, ej2_buttons_1, ej2_splitbuttons_1, ej2_popups_1, index_1, index_2, ej2_lists_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TOOLBAR_ID = '_toolbar';
    var NEW_ID = '_new';
    var OPEN_ID = '_open';
    var UNDO_ID = '_undo';
    var REDO_ID = '_redo';
    var INSERT_IMAGE_ID = '_image';
    var INSERT_IMAGE_LOCAL_ID = '_image_local';
    var INSERT_IMAGE_ONLINE_ID = '_image_url';
    var INSERT_TABLE_ID = '_table';
    var INSERT_LINK_ID = '_link';
    var BOOKMARK_ID = '_bookmark';
    var COMMENT_ID = '_comment';
    var TRACK_ID = '_track';
    var TABLE_OF_CONTENT_ID = '_toc';
    var HEADER_ID = '_header';
    var FOOTER_ID = '_footer';
    var PAGE_SET_UP_ID = '_page_setup';
    var PAGE_NUMBER_ID = '_page_number';
    var BREAK_ID = '_break';
    var LISTVIEW_ID = '_listView';
    var FIND_ID = '_find';
    var CLIPBOARD_ID = '_use_local_clipboard';
    var RESTRICT_EDITING_ID = '_restrict_edit';
    var PAGE_BREAK = '_page_break';
    var SECTION_BREAK = '_section_break';
    var SECTION_BREAK_CONTINUOUS = '_section_break_continuous';
    var COLUMN_BREAK = '_column_break';
    var READ_ONLY = '_read_only';
    var PROTECTIONS = '_protections';
    var FORM_FIELDS_ID = '_form_fields';
    var UPDATE_FIELDS_ID = '_update_fields';
    var TEXT_FORM = '_text_form';
    var CHECKBOX = '_checkbox';
    var DROPDOWN = '_dropdown';
    var FOOTNOTE_ID = '_footnote';
    var ENDNOTE_ID = '_endnote';
    var COLUMNS_ID = '_columns';
    var PAGE_SET_UP = '_page_set';
    var CONTENT_CONTROL_ID = '_content_control';
    var RICHTEXT_CONTENT_CONTROL_ID = '_richtext_content_control';
    var PLAINTEXT_CONTENT_CONTROL_ID = '_plaintext_content_control';
    var COMBOBOX_CONTENT_CONTROL_ID = '_combobox_content_control';
    var DROPDOWNDOWN_CONTENT_CONTROL_ID = '_dropdown_content_control';
    var DATEPICKER_CONTENT_CONTROL_ID = '_datepicker_content_control';
    var CHECKBOX_CONTENT_CONTROL_ID = '_checkbox_content_control';
    var PICTURE_CONTENT_CONTROL_ID = '_picture_content_control';
    var XMLMAPPING_ID = '_xmlmapping';
    var Toolbar = (function () {
        function Toolbar(container) {
            this.isCommentEditing = false;
            this.container = container;
            this.importHandler = new index_1.XmlHttpRequestHandler();
        }
        Object.defineProperty(Toolbar.prototype, "documentEditor", {
            get: function () {
                return this.container.documentEditor;
            },
            enumerable: true,
            configurable: true
        });
        Toolbar.prototype.getModuleName = function () {
            return 'toolbar';
        };
        Toolbar.prototype.enableItems = function (itemIndex, isEnable) {
            this.toolbar.enableItems(itemIndex, isEnable);
        };
        Toolbar.prototype.initToolBar = function (items) {
            this.toolbarItems = items;
            this.renderToolBar();
            this.wireEvent();
        };
        Toolbar.prototype.renderToolBar = function () {
            Iif (ej2_base_1.isNullOrUndefined(this.container)) {
                return;
            }
            var toolbarContainer = this.container.toolbarContainer;
            var toolbarWrapper = ej2_base_1.createElement('div', { className: 'e-de-tlbr-wrapper' });
            var toolbarTarget = ej2_base_1.createElement('div', { className: 'e-de-toolbar' });
            this.initToolbarItems();
            toolbarWrapper.appendChild(toolbarTarget);
            toolbarContainer.appendChild(toolbarWrapper);
            var locale = this.container.localObj;
            var propertiesPaneDiv = ej2_base_1.createElement('div', { className: 'e-de-ctnr-properties-pane-btn' });
            this.buttonElement = ej2_base_1.createElement('button', { attrs: { type: 'button', 'aria-label': locale.getConstant('Hide properties pane'), 'aria-pressed': 'true' } });
            propertiesPaneDiv.appendChild(this.buttonElement);
            var cssClassName = 'e-tbar-btn e-tbtn-txt e-control e-btn e-de-showhide-btn';
            var iconCss = 'e-icons e-de-ctnr-showhide';
            if (this.container.enableRtl) {
                cssClassName += '-rtl';
                iconCss = 'e-icons e-de-ctnr-showhide e-de-flip';
            }
            this.propertiesPaneButton = new ej2_buttons_1.Button({
                cssClass: cssClassName,
                iconCss: iconCss
            });
            if (this.container.showPropertiesPane) {
                this.buttonElement.title = locale.getConstant('Hide properties pane');
            }
            else {
                this.buttonElement.title = locale.getConstant('Show properties pane');
                ej2_base_1.classList(propertiesPaneDiv, this.container.restrictEditing ? ['e-de-overlay'] : [], this.container.restrictEditing ? [] : ['e-de-overlay']);
                propertiesPaneDiv.classList.add('e-de-pane-disable-clr');
            }
            this.propertiesPaneButton.appendTo(this.buttonElement);
            ej2_base_1.EventHandler.add(this.buttonElement, 'click', this.showHidePropertiesPane, this);
            toolbarContainer.appendChild(propertiesPaneDiv);
            this.toolbar.appendTo(toolbarTarget);
            this.initToolbarDropdown(toolbarTarget);
        };
        Toolbar.prototype.initToolbarDropdown = function (toolbarTarget) {
            var _this = this;
            Eif (this.container) {
                var locale = this.container.localObj;
                var id_1 = this.container.element.id + TOOLBAR_ID;
                Eif (this.toolbarItems.indexOf('Image') >= 0) {
                    this.imgDropDwn = new ej2_splitbuttons_1.DropDownButton({
                        items: [
                            {
                                text: locale.getConstant('Upload from computer'), iconCss: 'e-icons e-de-ctnr-upload',
                                id: id_1 + INSERT_IMAGE_LOCAL_ID
                            }
                        ],
                        cssClass: 'e-de-toolbar-btn-first e-caret-hide',
                        select: this.onDropDownButtonSelect.bind(this)
                    });
                    this.imgDropDwn.appendTo('#' + id_1 + INSERT_IMAGE_ID);
                }
                Eif (this.toolbarItems.indexOf('PageSetup') >= 0) {
                    this.PageSetUpDropDwn = new ej2_splitbuttons_1.DropDownButton({
                        items: [
                            { text: locale.getConstant('Page Setup'), iconCss: 'e-icons e-de-ctnr-page-size', id: id_1 + PAGE_SET_UP },
                            { text: locale.getConstant('Columns'), iconCss: 'e-icons e-de-ctnr-columns', id: id_1 + COLUMNS_ID }
                        ],
                        cssClass: 'e-de-toolbar-btn-first e-caret-hide',
                        select: this.onDropDownButtonSelect.bind(this)
                    });
                    this.PageSetUpDropDwn.appendTo('#' + id_1 + PAGE_SET_UP_ID);
                }
                Eif (this.toolbarItems.indexOf('ContentControl') >= 0) {
                    this.ContentControlDropDwn = new ej2_splitbuttons_1.DropDownButton({
                        items: [
                            { text: locale.getConstant('Rich Text Content Control'), iconCss: 'e-icons e-de-ctnr-change-case', id: id_1 + RICHTEXT_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Plain Text Content Control'), iconCss: 'e-icons e-de-ctnr-change-case', id: id_1 + PLAINTEXT_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Picture Content Control'), iconCss: 'e-icons e-de-ctnr-image', id: id_1 + PICTURE_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Combo Box Content Control'), iconCss: 'e-icons e-de-combo-box', id: id_1 + COMBOBOX_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Drop-Down List Content Control'), iconCss: 'e-icons e-de-dropdown-list', id: id_1 + DROPDOWNDOWN_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Date Picker Content Control'), iconCss: 'e-icons e-timeline-today', id: id_1 + DATEPICKER_CONTENT_CONTROL_ID },
                            { text: locale.getConstant('Check Box Content Control'), iconCss: 'e-icons e-check-box', id: id_1 + CHECKBOX_CONTENT_CONTROL_ID }
                        ],
                        cssClass: 'e-de-toolbar-btn-first e-caret-hide',
                        select: this.onDropDownButtonSelect.bind(this)
                    });
                    this.ContentControlDropDwn.appendTo('#' + id_1 + CONTENT_CONTROL_ID);
                }
                Eif (this.toolbarItems.indexOf('Break') >= 0) {
                    var breakDataSource = [
                        { text: locale.getConstant('Page'), iconCss: 'e-de-listview e-de-listview-icon e-icons e-de-ctnr-page-break', id: PAGE_BREAK, category: locale.getConstant('Page Breaks') },
                        { text: locale.getConstant('Column'), iconCss: 'e-de-listview e-de-listview-icon e-icons e-de-ctnr-page-break-column', id: COLUMN_BREAK, category: locale.getConstant('Page Breaks') },
                        { text: locale.getConstant('Next Page'), iconCss: 'e-de-listview e-de-listview-icon e-icons e-de-ctnr-section-break', id: SECTION_BREAK, category: locale.getConstant('Section Breaks') },
                        { text: locale.getConstant('Continuous'), iconCss: 'e-de-listview e-de-listview-icon e-icons e-de-ctnr-section-break-continuous', id: SECTION_BREAK_CONTINUOUS, category: locale.getConstant('Section Breaks') }
                    ];
                    var ddbOption = {
                        target: '#' + id_1 + BREAK_ID + LISTVIEW_ID,
                        cssClass: 'e-caret-hide'
                    };
                    this.breakDropDwn = new ej2_splitbuttons_1.DropDownButton(ddbOption, '#' + id_1 + BREAK_ID);
                    this.breakListView = new ej2_lists_1.ListView({
                        dataSource: breakDataSource,
                        width: '170px',
                        fields: { iconCss: 'iconCss', groupBy: 'category' },
                        showIcon: true,
                        select: this.onListViewSelection.bind(this)
                    });
                    this.breakListView.appendTo('#' + id_1 + BREAK_ID + LISTVIEW_ID);
                }
                this.filePicker = ej2_base_1.createElement('input', {
                    attrs: { type: 'file', accept: '.doc,.docx,.rtf,.txt,.htm,.html,.sfdt' }, className: 'e-de-ctnr-file-picker'
                });
                Iif (ej2_base_1.Browser.isIE) {
                    document.body.appendChild(this.filePicker);
                }
                this.imagePicker = ej2_base_1.createElement('input', {
                    attrs: { type: 'file', accept: '.jpg,.jpeg,.png,.bmp,.svg' }, className: 'e-de-ctnr-file-picker'
                });
                Iif (ej2_base_1.Browser.isIE) {
                    document.body.appendChild(this.imagePicker);
                }
                Eif (this.toolbarItems.indexOf('LocalClipboard') >= 0) {
                    this.toggleButton(id_1 + CLIPBOARD_ID, this.container.enableLocalPaste);
                }
                Eif (this.toolbarItems.indexOf('TrackChanges') >= 0) {
                    this.toggleButton(id_1 + TRACK_ID, this.container.enableTrackChanges);
                }
                Eif (this.toolbarItems.indexOf('RestrictEditing') >= 0) {
                    this.toggleButton(id_1 + RESTRICT_EDITING_ID, this.container.restrictEditing);
                    var restrictIconCss = '';
                    Iif (this.container.restrictEditing) {
                        restrictIconCss = ' e-de-selected-item';
                    }
                    this.restrictDropDwn = new ej2_splitbuttons_1.DropDownButton({
                        items: [
                            { text: locale.getConstant('Read only'), id: id_1 + READ_ONLY, iconCss: 'e-icons' + restrictIconCss },
                            { text: locale.getConstant('Protections'), id: id_1 + PROTECTIONS, iconCss: 'e-icons' }
                        ],
                        cssClass: 'e-de-toolbar-btn-first e-caret-hide',
                        select: this.onDropDownButtonSelect.bind(this),
                        beforeItemRender: function (args) {
                            _this.onBeforeRenderRestrictDropdown(args, id_1);
                        }
                    });
                    this.restrictDropDwn.appendTo('#' + id_1 + RESTRICT_EDITING_ID);
                }
                Eif (this.toolbarItems.indexOf('FormFields') >= 0) {
                    this.formFieldDropDown = new ej2_splitbuttons_1.DropDownButton({
                        items: [
                            { text: locale.getConstant('Text Form'), iconCss: 'e-icons e-de-textform', id: id_1 + TEXT_FORM },
                            { text: locale.getConstant('Check Box'), iconCss: 'e-icons e-de-checkbox-form', id: id_1 + CHECKBOX },
                            { text: locale.getConstant('DropDown'), iconCss: 'e-icons e-de-dropdownform', id: id_1 + DROPDOWN }
                        ],
                        cssClass: 'e-de-toolbar-btn-first e-caret-hide',
                        select: this.onDropDownButtonSelect.bind(this)
                    });
                    this.formFieldDropDown.appendTo('#' + id_1 + FORM_FIELDS_ID);
                }
            }
        };
        Toolbar.prototype.onListViewSelection = function (args) {
            var parentId = this.container.element.id + TOOLBAR_ID;
            var id = args.item.id;
            if (id === parentId + BREAK_ID + LISTVIEW_ID + '_' + PAGE_BREAK) {
                this.container.documentEditor.editorModule.insertPageBreak();
            }
            else if (id === parentId + BREAK_ID + LISTVIEW_ID + '_' + SECTION_BREAK) {
                this.container.documentEditor.editorModule.insertSectionBreak();
            }
            else if (id === parentId + BREAK_ID + LISTVIEW_ID + '_' + SECTION_BREAK_CONTINUOUS) {
                this.container.documentEditor.editorModule.insertSectionBreak(index_2.SectionBreakType.Continuous);
            }
            else if (id === parentId + BREAK_ID + LISTVIEW_ID + '_' + COLUMN_BREAK) {
                this.container.documentEditor.editorModule.insertColumnBreak();
            }
            args.item.classList.remove('e-active');
        };
        Toolbar.prototype.onBeforeRenderRestrictDropdown = function (args, id) {
            var selectedIcon = args.element.getElementsByClassName('e-menu-icon')[0];
            if (!ej2_base_1.isNullOrUndefined(selectedIcon)) {
                if (args.item.id === id + READ_ONLY) {
                    this.toggleRestrictIcon(selectedIcon, this.container.restrictEditing);
                }
                if (args.item.id === id + PROTECTIONS) {
                    var restrictPane = document.getElementsByClassName('e-de-restrict-pane')[0];
                    if (!ej2_base_1.isNullOrUndefined(restrictPane)) {
                        var toggleProtection = !(restrictPane.style.display === 'none');
                        this.toggleRestrictIcon(selectedIcon, toggleProtection);
                    }
                }
            }
        };
        Toolbar.prototype.toggleRestrictIcon = function (icon, toggle) {
            if (toggle) {
                icon.classList.add('e-de-selected-item');
            }
            else {
                icon.classList.remove('e-de-selected-item');
            }
        };
        Toolbar.prototype.showHidePropertiesPane = function () {
            var paneDiv = document.getElementsByClassName('e-de-ctnr-properties-pane-btn')[0];
            var locale = this.container.localObj;
            if (this.container.propertiesPaneContainer.style.display === 'none') {
                this.container.showPropertiesPane = true;
                paneDiv.classList.remove('e-de-pane-disable-clr');
                this.buttonElement.title = locale.getConstant('Hide properties pane');
                this.buttonElement.setAttribute('aria-label', locale.getConstant('Hide properties pane'));
                this.buttonElement.setAttribute('aria-pressed', 'true');
                ej2_base_1.classList(paneDiv, ['e-de-pane-enable-clr'], []);
                this.container.trigger(index_1.beforePaneSwitchEvent, { type: 'PropertiesPane' });
            }
            else if (this.container.previousContext.indexOf('Header') >= 0
                || this.container.previousContext.indexOf('Footer') >= 0) {
                this.container.showHeaderProperties = !this.container.showHeaderProperties;
            }
            else {
                this.container.showPropertiesPane = false;
                paneDiv.classList.remove('e-de-pane-enable-clr');
                this.buttonElement.title = locale.getConstant('Show properties pane');
                this.buttonElement.setAttribute('aria-label', locale.getConstant('Show properties pane'));
                this.buttonElement.setAttribute('aria-pressed', 'false');
                ej2_base_1.classList(paneDiv, ['e-de-pane-disable-clr'], []);
            }
            this.enableDisablePropertyPaneButton(this.container.showPropertiesPane);
            this.container.showPropertiesPaneOnSelection();
            this.documentEditor.focusIn();
        };
        Toolbar.prototype.onWrapText = function (text) {
            var content = '';
            var index = text.lastIndexOf(' ');
            Eif (index !== -1) {
                content = text.slice(0, index);
                text.slice(index);
                content += '<div class="e-de-text-wrap">' + text.slice(index) + '</div>';
            }
            else {
                content = text;
            }
            return content;
        };
        Toolbar.prototype.wireEvent = function () {
            this.propertiesPaneButton.on('click', this.togglePropertiesPane.bind(this));
            ej2_base_1.EventHandler.add(this.filePicker, 'change', this.onFileChange, this);
            ej2_base_1.EventHandler.add(this.imagePicker, 'change', this.onImageChange, this);
        };
        Toolbar.prototype.initToolbarItems = function () {
            this.toolbar = new ej2_navigations_1.Toolbar({
                enableRtl: this.container.enableRtl,
                clicked: this.clickHandler.bind(this),
                items: this.getToolbarItems()
            });
        };
        Toolbar.prototype.reInitToolbarItems = function (items) {
            var _this = this;
            for (var i = 0; i < items.length; i++) {
                switch (items[parseInt(i.toString(), 10)]) {
                    case 'RestrictEditing':
                        if (!ej2_base_1.isNullOrUndefined(this.restrictDropDwn)) {
                            this.restrictDropDwn.destroy();
                        }
                        break;
                    case 'Break':
                        if (!ej2_base_1.isNullOrUndefined(this.breakDropDwn)) {
                            this.breakDropDwn.destroy();
                        }
                        break;
                    case 'PageSetup':
                        if (!ej2_base_1.isNullOrUndefined(this.PageSetUpDropDwn)) {
                            this.PageSetUpDropDwn.destroy();
                        }
                        break;
                    case 'Image':
                        if (!ej2_base_1.isNullOrUndefined(this.imgDropDwn)) {
                            this.imgDropDwn.destroy();
                        }
                        break;
                    case 'FormFields':
                        if (!ej2_base_1.isNullOrUndefined(this.formFieldDropDown)) {
                            this.formFieldDropDown.destroy();
                        }
                        break;
                }
            }
            this.toolbarItems = items;
            var toolbarTarget = this.container.toolbarContainer;
            this.toolbar.items = this.getToolbarItems();
            this.toolbarTimer = Number(setTimeout(function () {
                if (_this.toolbarTimer) {
                    clearTimeout(_this.toolbarTimer);
                }
                _this.initToolbarDropdown(toolbarTarget);
                if (items.indexOf('Open') >= 0) {
                    ej2_base_1.EventHandler.add(_this.filePicker, 'change', _this.onFileChange, _this);
                }
                if (items.indexOf('Image') >= 0) {
                    ej2_base_1.EventHandler.add(_this.imagePicker, 'change', _this.onImageChange, _this);
                }
            }, 200));
        };
        Toolbar.prototype.getToolbarItems = function () {
            var locale = this.container.localObj;
            var id = this.container.element.id + TOOLBAR_ID;
            var toolbarItems = [];
            var className;
            var tItem = this.toolbarItems;
            for (var i = 0; i < this.toolbarItems.length; i++) {
                if (i === 0) {
                    className = 'e-de-toolbar-btn-start';
                }
                else if ((tItem[i + 1] === 'Separator') && (tItem[i - 1] === 'Separator')) {
                    className = 'e-de-toolbar-btn';
                }
                else if (tItem[i + 1] === 'Separator') {
                    className = 'e-de-toolbar-btn-last';
                }
                else if (tItem[i - 1] === 'Separator') {
                    className = 'e-de-toolbar-btn-first';
                }
                else if (i === (this.toolbarItems.length - 1)) {
                    className = 'e-de-toolbar-btn-end';
                }
                else {
                    className = 'e-de-toolbar-btn-middle';
                }
                switch (tItem[parseInt(i.toString(), 10)]) {
                    case 'Separator':
                        toolbarItems.push({
                            type: 'Separator', cssClass: 'e-de-separator'
                        });
                        break;
                    case 'New':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-new', tooltipText: locale.getConstant('Create a new document'),
                            id: id + NEW_ID, text: locale.getConstant('New'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Create a new document') }
                        });
                        break;
                    case 'Open':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-open', tooltipText: locale.getConstant('Open a document'), id: id + OPEN_ID,
                            text: locale.getConstant('Open'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Open a document') }
                        });
                        break;
                    case 'Undo':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-undo', tooltipText: locale.getConstant('Undo Tooltip'),
                            id: id + UNDO_ID, text: locale.getConstant('Undo'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Undo Tooltip') }
                        });
                        break;
                    case 'Redo':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-redo', tooltipText: locale.getConstant('Redo Tooltip'),
                            id: id + REDO_ID, text: locale.getConstant('Redo'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Redo Tooltip') }
                        });
                        break;
                    case 'Comments':
                        toolbarItems.push({
                            prefixIcon: 'e-de-cnt-cmt-add',
                            tooltipText: locale.getConstant('Show comments'),
                            id: id + COMMENT_ID, text: locale.getConstant('Comments'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Show comments') }
                        });
                        break;
                    case 'TrackChanges':
                        toolbarItems.push({
                            prefixIcon: 'e-de-cnt-track',
                            tooltipText: locale.getConstant('Track Changes'),
                            id: id + TRACK_ID, text: this.onWrapText(locale.getConstant('TrackChanges')), cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('TrackChanges'), 'aria-pressed': this.container.enableTrackChanges, role: 'button', 'aria-hidden': 'true' }
                        });
                        break;
                    case 'Image':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Insert inline picture from a file') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-de-toolbar-btn-first e-caret-hide" type="button" id="' + id + INSERT_IMAGE_ID + '"><span class="e-btn-icon e-icons e-de-ctnr-image e-icon-left"></span><span class="e-tbar-btn-text">' + locale.getConstant('Image') + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button>',
                            id: id + INSERT_IMAGE_ID, htmlAttributes: { 'aria-label': locale.getConstant('Insert inline picture from a file'), 'aria-haspopup': false }
                        });
                        break;
                    case 'Table':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-table', tooltipText: locale.getConstant('Insert a table into the document'),
                            id: id + INSERT_TABLE_ID, text: locale.getConstant('Table'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Insert a table into the document'), 'aria-haspopup': true }
                        });
                        break;
                    case 'Hyperlink':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-link',
                            tooltipText: locale.getConstant('Create Hyperlink'),
                            id: id + INSERT_LINK_ID, text: locale.getConstant('Link'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Create Hyperlink'), 'aria-haspopup': true }
                        });
                        break;
                    case 'Bookmark':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-bookmark',
                            tooltipText: locale.getConstant('Insert a bookmark in a specific place in this document'),
                            id: id + BOOKMARK_ID, text: locale.getConstant('Bookmark'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Insert a bookmark in a specific place in this document'), 'aria-haspopup': true }
                        });
                        break;
                    case 'TableOfContents':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-tableofcontent',
                            tooltipText: locale.getConstant('Provide an overview of your document by adding a table of contents'),
                            id: id + TABLE_OF_CONTENT_ID, text: this.onWrapText(locale.getConstant('Table of Contents')),
                            cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Table of Contents') }
                        });
                        break;
                    case 'Header':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-header', tooltipText: locale.getConstant('Add or edit the header'),
                            id: id + HEADER_ID, text: locale.getConstant('Header'), cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('Add or edit the header') }
                        });
                        break;
                    case 'Footer':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-footer', tooltipText: locale.getConstant('Add or edit the footer'),
                            id: id + FOOTER_ID, text: locale.getConstant('Footer'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Add or edit the footer') }
                        });
                        break;
                    case 'PageSetup':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Page Setup') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-caret-hide" type="button" id="' + id + PAGE_SET_UP_ID + '"><span class="e-btn-icon e-icons e-de-ctnr-pagesetup e-icon-left"></span><span class="e-tbar-btn-text">' + this.onWrapText(locale.getConstant('Page Setup')) + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button>',
                            id: id + PAGE_SET_UP_ID, htmlAttributes: { 'aria-label': locale.getConstant('Page Setup') }
                        });
                        break;
                    case 'PageNumber':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-pagenumber', tooltipText: locale.getConstant('Add page numbers'),
                            id: id + PAGE_NUMBER_ID, text: this.onWrapText(locale.getConstant('Page Number')),
                            cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Page Number') }
                        });
                        break;
                    case 'Break':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Break') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-caret-hide" type="button" id="' + id + BREAK_ID + '"><span class="e-btn-icon e-icons e-de-ctnr-break e-icon-left"></span><span class="e-tbar-btn-text">' + locale.getConstant('Break') + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button><div id="' + id + BREAK_ID + LISTVIEW_ID + '"></div>',
                            id: id + BREAK_ID, htmlAttributes: { 'aria-label': locale.getConstant('Break') }
                        });
                        break;
                    case 'Find':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-find', tooltipText: locale.getConstant('Find Text'),
                            id: id + FIND_ID, text: locale.getConstant('Find'), cssClass: className, htmlAttributes: { 'aria-label': locale.getConstant('Find Text') }
                        });
                        break;
                    case 'LocalClipboard':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-paste',
                            tooltipText: locale.getConstant('Toggle between the internal clipboard and system clipboard'),
                            id: id + CLIPBOARD_ID, text: this.onWrapText(locale.getConstant('Local Clipboard')),
                            cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('Local Clipboard'), 'aria-pressed': this.container.enableLocalPaste, role: 'button', 'aria-hidden': 'true' }
                        });
                        break;
                    case 'RestrictEditing':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Restrict editing') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-de-toolbar-btn-first e-caret-hide" type="button" id="' + id + RESTRICT_EDITING_ID + '"><span class="e-btn-icon e-de-ctnr-lock e-icons e-icon-left"></span><span class="e-tbar-btn-text">' + this.onWrapText(locale.getConstant('Restrict Editing')) + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button>',
                            htmlAttributes: { 'aria-label': locale.getConstant('Restrict editing') }
                        });
                        break;
                    case 'FormFields':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Form Fields') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-de-toolbar-btn-first e-caret-hide" type="button" id="' + id + FORM_FIELDS_ID + '"><span class="e-btn-icon e-de-formfield e-icons e-icon-left"></span><span class="e-tbar-btn-text">' + this.onWrapText(locale.getConstant('Form Fields')) + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button>',
                            id: id + FORM_FIELDS_ID,
                            htmlAttributes: { 'aria-label': locale.getConstant('Form Fields') }
                        });
                        break;
                    case 'UpdateFields':
                        toolbarItems.push({
                            prefixIcon: 'e-de-update-field', tooltipText: locale.getConstant('Update cross reference fields'),
                            id: id + UPDATE_FIELDS_ID, text: this.onWrapText(locale.getConstant('Update Fields')),
                            cssClass: className + ' e-de-formfields',
                            htmlAttributes: { 'aria-label': locale.getConstant('Update cross reference fields') }
                        });
                        break;
                    case 'InsertFootnote':
                        toolbarItems.push({
                            prefixIcon: 'e-de-footnote', tooltipText: locale.getConstant('Footnote Tooltip'),
                            text: this.onWrapText(locale.getConstant('Insert Footnote')), id: id + FOOTNOTE_ID,
                            cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('Insert Footnote') }
                        });
                        break;
                    case 'InsertEndnote':
                        toolbarItems.push({
                            prefixIcon: 'e-de-endnote', tooltipText: locale.getConstant('Endnote Tooltip'),
                            text: this.onWrapText(locale.getConstant('Insert Endnote')), id: id + ENDNOTE_ID,
                            cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('Insert Endnote') }
                        });
                        break;
                    case 'ContentControl':
                        toolbarItems.push({
                            template: '<button title="' + locale.getConstant('Content Control') + '" class="e-tbar-btn e-tbtn-txt e-control e-btn e-lib e-dropdown-btn e-caret-hide" type="button" id="' + id + CONTENT_CONTROL_ID + '"><span class="e-btn-icon e-icons e-de-ctnr-content-control e-icon-left"></span><span class="e-tbar-btn-text">' + this.onWrapText(locale.getConstant('Content Control')) + '</span><span class="e-btn-icon e-icons e-icon-right e-caret"></span></button>',
                            id: id + CONTENT_CONTROL_ID, htmlAttributes: { 'aria-label': locale.getConstant('Content Control') }
                        });
                        break;
                    case 'XML Mapping':
                        toolbarItems.push({
                            prefixIcon: 'e-de-ctnr-xml-mapping', tooltipText: locale.getConstant('XML Mapping Pane'),
                            id: id + XMLMAPPING_ID, text: this.onWrapText(locale.getConstant('XML Mapping Pane')), cssClass: className,
                            htmlAttributes: { 'aria-label': locale.getConstant('XML Mapping Pane') }
                        });
                        break;
                    default:
                        toolbarItems.push(tItem[parseInt(i.toString(), 10)]);
                        break;
                }
            }
            for (var i = 0; i < toolbarItems.length; i++) {
                var tabindex = void 0;
                Eif (toolbarItems[i].text !== 'Separator') {
                    tabindex = i.toString();
                    toolbarItems[i].htmlattributes = { 'tabindex': tabindex };
                }
            }
            return toolbarItems;
        };
        Toolbar.prototype.clickHandler = function (args) {
            var id = this.container.element.id + TOOLBAR_ID;
            switch (args.item.id) {
                case id + NEW_ID:
                    this.container.documentEditor.openBlank();
                    this.documentEditor.focusIn();
                    break;
                case id + OPEN_ID:
                    this.filePicker.value = '';
                    this.filePicker.click();
                    this.documentEditor.focusIn();
                    break;
                case id + UNDO_ID:
                    this.container.documentEditor.editorHistoryModule.undo();
                    break;
                case id + REDO_ID:
                    this.container.documentEditor.editorHistoryModule.redo();
                    break;
                case id + INSERT_TABLE_ID:
                    this.container.documentEditor.showDialog('Table');
                    break;
                case id + INSERT_LINK_ID:
                    this.container.documentEditor.showDialog('Hyperlink');
                    break;
                case id + BOOKMARK_ID:
                    this.container.documentEditor.showDialog('Bookmark');
                    break;
                case id + COMMENT_ID:
                    this.documentEditor.editorModule.isUserInsert = true;
                    this.documentEditor.editorModule.insertComment('');
                    this.documentEditor.editorModule.isUserInsert = false;
                    break;
                case id + TRACK_ID:
                    this.toggleTrackChangesInternal(args.item.id);
                    break;
                case id + HEADER_ID:
                    this.container.documentEditor.selectionModule.goToHeader();
                    this.container.statusBar.toggleWebLayout();
                    break;
                case id + TABLE_OF_CONTENT_ID:
                    this.onToc();
                    break;
                case id + XMLMAPPING_ID:
                    if (!this.container.documentEditor.isXmlPaneTool) {
                        this.container.documentEditor.showXmlPane();
                    }
                    this.container.statusBar.toggleWebLayout();
                    break;
                case id + FOOTER_ID:
                    this.container.documentEditor.selectionModule.goToFooter();
                    this.container.statusBar.toggleWebLayout();
                    break;
                case id + PAGE_NUMBER_ID:
                    this.container.documentEditor.editorModule.insertPageNumber();
                    break;
                case id + FIND_ID:
                    this.container.documentEditor.showOptionsPane();
                    break;
                case id + CLIPBOARD_ID:
                    this.toggleLocalPaste(args.item.id);
                    break;
                case id + UPDATE_FIELDS_ID:
                    this.documentEditor.updateFields();
                    break;
                case id + FOOTNOTE_ID:
                    this.documentEditor.editorModule.insertFootnote();
                    break;
                case id + ENDNOTE_ID:
                    this.documentEditor.editorModule.insertEndnote();
                    break;
                default:
                    this.container.trigger(index_1.toolbarClickEvent, args);
                    break;
            }
            if (args.item.id === id + NEW_ID || args.item.id === id + OPEN_ID || args.item.id === id + UNDO_ID || args.item.id === REDO_ID
                || args.item.id === id + XMLMAPPING_ID || args.item.id === id + COMMENT_ID || args.item.id === id + TRACK_ID
                || args.item.id === id + HEADER_ID || args.item.id === id + TABLE_OF_CONTENT_ID || args.item.id === id + FOOTER_ID
                || args.item.id === id + PAGE_NUMBER_ID || args.item.id === id + CLIPBOARD_ID || args.item.id === id + UPDATE_FIELDS_ID
                || args.item.id === id + FOOTNOTE_ID || args.item.id === id + ENDNOTE_ID || args.item.id === id + PAGE_SET_UP_ID ||
                args.item.id === id + BREAK_ID || args.item.id === id + RESTRICT_EDITING_ID || args.item.id === id + FORM_FIELDS_ID) {
                this.documentEditor.focusIn();
            }
        };
        Toolbar.prototype.toggleLocalPaste = function (id) {
            this.container.enableLocalPaste = !this.container.enableLocalPaste;
            this.toggleButton(id, this.container.enableLocalPaste);
        };
        Toolbar.prototype.toggleEditing = function () {
            this.container.restrictEditing = !this.container.restrictEditing;
            this.container.showPropertiesPane = !this.container.restrictEditing;
        };
        Toolbar.prototype.toggleRestrictEditing = function (enable) {
            var restrictEditingId = this.container.element.id + TOOLBAR_ID + RESTRICT_EDITING_ID;
            var element = document.getElementById(restrictEditingId);
            if (element) {
                this.toggleButton(restrictEditingId, enable);
            }
        };
        Toolbar.prototype.toggleButton = function (id, toggle) {
            var element = document.getElementById(id);
            if (toggle) {
                ej2_base_1.classList(element, ['e-btn-toggle'], []);
                element.setAttribute('aria-pressed', 'true');
            }
            else {
                ej2_base_1.classList(element, [], ['e-btn-toggle']);
                element.setAttribute('aria-pressed', 'false');
            }
        };
        Toolbar.prototype.toggleTrackChangesInternal = function (id, enable) {
            Eif (!ej2_base_1.isNullOrUndefined(enable)) {
                this.container.enableTrackChanges = !enable;
            }
            this.container.enableTrackChanges = !this.container.enableTrackChanges;
            this.toggleButton(id, this.container.enableTrackChanges);
        };
        Toolbar.prototype.togglePropertiesPane = function () {
            this.container.showPropertiesPane = !this.container.showPropertiesPane;
        };
        Toolbar.prototype.onDropDownButtonSelect = function (args) {
            var _this = this;
            var parentId = this.container.element.id + TOOLBAR_ID;
            var id = args.item.id;
            if (id === parentId + INSERT_IMAGE_LOCAL_ID) {
                this.imagePicker.value = '';
                this.imagePicker.click();
            }
            else if (id === parentId + PAGE_SET_UP) {
                this.container.documentEditor.showDialog('PageSetup');
            }
            else if (id === parentId + COLUMNS_ID) {
                this.container.documentEditor.showDialog('Columns');
            }
            else if (id === parentId + DATEPICKER_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('Date');
            }
            else if (id === parentId + CHECKBOX_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('CheckBox');
            }
            else if (id === parentId + COMBOBOX_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('ComboBox');
            }
            else if (id === parentId + RICHTEXT_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('RichText');
            }
            else if (id === parentId + PLAINTEXT_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('Text');
            }
            else if (id === parentId + PICTURE_CONTENT_CONTROL_ID) {
                this.container.documentEditor.showDialog('PictureContentControl');
            }
            else if (id === parentId + DROPDOWNDOWN_CONTENT_CONTROL_ID) {
                this.container.documentEditor.editor.insertContentControl('DropDownList');
            }
            else if (id === parentId + INSERT_IMAGE_ONLINE_ID) {
            }
            else if (id === parentId + READ_ONLY) {
                this.toggleEditing();
            }
            else if (id === parentId + PROTECTIONS) {
                this.documentEditor.documentHelper.restrictEditingPane.showHideRestrictPane(true);
            }
            else if (id === parentId + CHECKBOX) {
                this.documentEditor.editorModule.insertFormField('CheckBox');
            }
            else if (id === parentId + DROPDOWN) {
                this.documentEditor.editorModule.insertFormField('DropDown');
            }
            else if (id === parentId + TEXT_FORM) {
                this.documentEditor.editorModule.insertFormField('Text');
            }
            setTimeout(function () {
                _this.documentEditor.focusIn();
            }, 30);
        };
        Toolbar.prototype.onFileChange = function () {
            var _this = this;
            var file = this.filePicker.files[0];
            var filesize = file.size;
            var check;
            var eventArgs = { fileSize: filesize, isCanceled: check };
            this.documentEditor.trigger(index_1.beforeFileOpenEvent, eventArgs);
            if (eventArgs.isCanceled) {
                return;
            }
            if (file) {
                var formatType_1 = file.name.substr(file.name.lastIndexOf('.'));
                if (formatType_1 === '.sfdt' || formatType_1 === '.txt') {
                    var fileReader_1 = new FileReader();
                    fileReader_1.onload = function () {
                        if (formatType_1 === '.txt') {
                            _this.container.documentEditor.documentHelper.openTextFile(fileReader_1.result);
                        }
                        else {
                            _this.container.documentEditor.openAsync(fileReader_1.result);
                        }
                    };
                    fileReader_1.readAsText(file);
                }
                else {
                    if (this.isSupportedFormatType(formatType_1.toLowerCase())) {
                        this.documentEditor.open(file);
                    }
                    else {
                        var localizeValue = new ej2_base_1.L10n('documenteditor', this.documentEditor.defaultLocale);
                        ej2_popups_1.DialogUtility.alert({
                            content: localizeValue.getConstant('Unsupported format'),
                            closeOnEscape: true, showCloseIcon: true,
                            position: { X: 'center', Y: 'center' }
                        }).enableRtl = this.container.enableRtl;
                    }
                }
                this.container.documentEditor.documentName = file.name.substr(0, file.name.lastIndexOf('.'));
            }
        };
        Toolbar.prototype.isSupportedFormatType = function (formatType) {
            switch (formatType) {
                case '.dotx':
                case '.docx':
                case '.docm':
                case '.dotm':
                case '.dot':
                case '.doc':
                case '.rtf':
                case '.txt':
                case '.xml':
                case '.html':
                    return true;
                default:
                    return false;
            }
        };
        Toolbar.prototype.failureHandler = function (args) {
            if (args.name === 'onError') {
                ej2_popups_1.DialogUtility.alert({
                    content: this.container.localObj.getConstant('Error in establishing connection with web server'),
                    closeOnEscape: true, showCloseIcon: true,
                    position: { X: 'center', Y: 'center' }
                }).enableRtl = this.container.enableRtl;
            }
            else {
                alert('Failed to load the file');
                this.documentEditor.fireServiceFailure(args);
            }
            ej2_popups_1.hideSpinner(this.container.containerTarget);
        };
        Toolbar.prototype.successHandler = function (result) {
            this.container.documentEditor.open(result.data);
            ej2_popups_1.hideSpinner(this.container.containerTarget);
        };
        Toolbar.prototype.onImageChange = function () {
            var _this = this;
            var file = this.imagePicker.files[0];
            var fileReader = new FileReader();
            fileReader.onload = function () {
                _this.insertImage(fileReader.result);
            };
            fileReader.readAsDataURL(file);
        };
        Toolbar.prototype.insertImage = function (data) {
            var image = document.createElement('img');
            var container = this.container;
            image.addEventListener('load', function () {
                container.documentEditor.editorModule.insertImageInternal(data, true, this.width, this.height, this.alt);
            });
            image.src = data;
        };
        Toolbar.prototype.enableDisableFormField = function (enable) {
            var ele = document.getElementById('container_toolbar_form_fields');
            if (!ej2_base_1.isNullOrUndefined(ele)) {
                this.toolbar.enableItems(ele.parentElement, enable);
            }
        };
        Toolbar.prototype.enableDisableInsertComment = function (enable) {
            this.isCommentEditing = !enable;
            var id = this.container.element.id + TOOLBAR_ID;
            var commentId = id + COMMENT_ID;
            var element = document.getElementById(commentId);
            if (!this.container.enableComment && element) {
                this.toolbar.removeItems(element.parentElement);
            }
            else if (element) {
                Iif (!ej2_base_1.isNullOrUndefined(this.documentEditor) && (this.documentEditor.isReadOnly ||
                    this.documentEditor.documentHelper.isDocumentProtected)) {
                    enable = this.documentEditor.documentHelper.isCommentOnlyMode || !this.documentEditor.isReadOnlyMode;
                }
                this.toolbar.enableItems(element.parentElement, enable);
            }
        };
        Toolbar.prototype.toggleTrackChanges = function (enable) {
            var trackId = this.container.element.id + TOOLBAR_ID + TRACK_ID;
            var element = document.getElementById(trackId);
            Eif (element) {
                this.toggleTrackChangesInternal(trackId, enable);
            }
        };
        Toolbar.prototype.enableDisableToolBarItem = function (enable, isProtectedContent) {
            Eif (!ej2_base_1.isNullOrUndefined(this.container.element)) {
                var id = this.container.element.id + TOOLBAR_ID;
                for (var _i = 0, _a = this.toolbar.items; _i < _a.length; _i++) {
                    var item = _a[_i];
                    var itemId = item.id;
                    if (itemId !== id + NEW_ID && itemId !== id + OPEN_ID && itemId !== id + FIND_ID &&
                        itemId !== id + CLIPBOARD_ID && itemId !== id + RESTRICT_EDITING_ID
                        && item.type !== 'Separator') {
                        if (enable && this.isCommentEditing && itemId === id + COMMENT_ID) {
                            continue;
                        }
                        if (itemId !== id + UNDO_ID && itemId !== id + REDO_ID && itemId !== id + INSERT_TABLE_ID &&
                            itemId !== id + INSERT_LINK_ID && itemId !== id + BOOKMARK_ID && itemId !== id + COMMENT_ID &&
                            itemId !== id + HEADER_ID && itemId !== id + XMLMAPPING_ID && itemId !== id + TABLE_OF_CONTENT_ID &&
                            itemId !== id + FOOTER_ID && itemId !== id + PAGE_SET_UP_ID && itemId !== id + CONTENT_CONTROL_ID
                            && itemId !== id + PAGE_NUMBER_ID && itemId !== id + INSERT_IMAGE_ID && itemId !== id + FORM_FIELDS_ID
                            && itemId !== id + BREAK_ID && itemId !== id + TRACK_ID && itemId !== id + FOOTNOTE_ID
                            && itemId !== id + ENDNOTE_ID &&
                            itemId !== id + UPDATE_FIELDS_ID) {
                            continue;
                        }
                        Iif (isProtectedContent && this.documentEditor.documentHelper.isFormFillProtectedMode
                            && itemId === id + UPDATE_FIELDS_ID) {
                            continue;
                        }
                        var element = document.getElementById(item.id);
                        if (!ej2_base_1.isNullOrUndefined(element) && !ej2_base_1.isNullOrUndefined(element.parentElement)) {
                            this.toolbar.enableItems(element.parentElement, enable);
                        }
                    }
                }
                Eif (!ej2_base_1.isNullOrUndefined(this.documentEditor)) {
                    this.enableDisableFormField(!this.documentEditor.enableHeaderAndFooter && enable && !this.documentEditor.isReadOnlyMode);
                }
                var isPlainContetnControl = this.documentEditor.selectionModule.isPlainContentControl();
                Iif (this.documentEditor.selectionModule.isinFootnote || this.documentEditor.selectionModule.isinEndnote
                    || this.documentEditor.enableHeaderAndFooter || isPlainContetnControl) {
                    if (this.containsItem(id + ENDNOTE_ID)) {
                        this.toolbar.enableItems(document.getElementById(id + ENDNOTE_ID).parentElement, false);
                    }
                    if (this.containsItem(id + FOOTNOTE_ID)) {
                        this.toolbar.enableItems(document.getElementById(id + FOOTNOTE_ID).parentElement, false);
                    }
                    if (this.containsItem(id + BREAK_ID)) {
                        this.toolbar.enableItems(document.getElementById(id + BREAK_ID).parentElement, false);
                    }
                    if (isPlainContetnControl) {
                        if (this.containsItem(id + INSERT_TABLE_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + INSERT_TABLE_ID).parentElement, false);
                        }
                        if (this.containsItem(id + INSERT_IMAGE_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + INSERT_IMAGE_ID).parentElement, false);
                        }
                        if (this.containsItem(id + COMMENT_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + COMMENT_ID).parentElement, false);
                        }
                        if (this.containsItem(id + BOOKMARK_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + BOOKMARK_ID).parentElement, false);
                        }
                        if (this.containsItem(id + INSERT_LINK_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + INSERT_LINK_ID).parentElement, false);
                        }
                        if (this.containsItem(id + FORM_FIELDS_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + FORM_FIELDS_ID).parentElement, false);
                        }
                        if (this.containsItem(id + CONTENT_CONTROL_ID)) {
                            this.toolbar.enableItems(document.getElementById(id + CONTENT_CONTROL_ID).parentElement, false);
                        }
                    }
                }
                if (!isProtectedContent || this.container.showPropertiesPane) {
                    Eif (isProtectedContent) {
                        enable = this.container.showPropertiesPane;
                    }
                    ej2_base_1.classList(this.propertiesPaneButton.element.parentElement, !enable ? ['e-de-overlay'] : [], !enable ? [] : ['e-de-overlay']);
                }
                var protectionType = this.documentEditor.documentHelper.protectionType;
                Eif (enable || (this.documentEditor.documentHelper.isDocumentProtected &&
                    (protectionType === 'FormFieldsOnly' || protectionType === 'CommentsOnly'))) {
                    this.enableDisableUndoRedo();
                }
                Iif (this.documentEditor.documentHelper.isTrackedOnlyMode && this.containsItem(id + TRACK_ID)) {
                    this.toolbar.enableItems(document.getElementById(id + TRACK_ID).parentElement, false);
                }
            }
        };
        Toolbar.prototype.containsItem = function (id) {
            for (var _i = 0, _a = this.toolbar.items; _i < _a.length; _i++) {
                var item = _a[_i];
                if (item.id === id) {
                    return true;
                }
            }
            return false;
        };
        Toolbar.prototype.enableDisableUndoRedo = function () {
            var id = this.container.element.id + TOOLBAR_ID;
            Eif (this.toolbarItems.indexOf('Undo') >= 0) {
                var undoElement = document.getElementById(id + UNDO_ID);
                if (!ej2_base_1.isNullOrUndefined(undoElement)) {
                    this.toolbar.enableItems(undoElement.parentElement, this.container.documentEditor.editorHistoryModule.canUndo());
                }
            }
            Eif (this.toolbarItems.indexOf('Redo') >= 0) {
                var redoElement = document.getElementById(id + REDO_ID);
                if (!ej2_base_1.isNullOrUndefined(redoElement)) {
                    this.toolbar.enableItems(redoElement.parentElement, this.container.documentEditor.editorHistoryModule.canRedo());
                }
            }
        };
        Toolbar.prototype.onToc = function () {
            if (this.container.previousContext === 'TableOfContents' && this.container.propertiesPaneContainer.style.display === 'none') {
                this.container.showPropertiesPane = false;
                this.documentEditor.focusIn();
                return;
            }
            if (this.container.headerFooterProperties.element.style.display === 'block') {
                this.documentEditor.selectionModule.closeHeaderFooter();
            }
            this.enableDisablePropertyPaneButton(false);
            this.container.showProperties('toc');
        };
        Toolbar.prototype.enableDisablePropertyPaneButton = function (isShow) {
            Eif (isShow) {
                ej2_base_1.classList(this.propertiesPaneButton.element.firstChild, ['e-pane-enabled'], ['e-pane-disabled']);
            }
            else {
                ej2_base_1.classList(this.propertiesPaneButton.element.firstChild, ['e-pane-disabled'], ['e-pane-enabled']);
            }
        };
        Toolbar.prototype.destroy = function () {
            Eif (this.restrictDropDwn) {
                this.restrictDropDwn.destroy();
                this.restrictDropDwn = undefined;
            }
            Eif (this.imgDropDwn) {
                this.imgDropDwn.destroy();
                this.imgDropDwn = undefined;
            }
            Eif (this.PageSetUpDropDwn) {
                this.PageSetUpDropDwn.destroy();
                this.PageSetUpDropDwn = undefined;
            }
            Eif (this.breakDropDwn) {
                this.breakDropDwn.destroy();
                this.breakDropDwn = undefined;
            }
            Eif (this.formFieldDropDown) {
                this.formFieldDropDown.destroy();
                this.formFieldDropDown = undefined;
            }
            Eif (this.ContentControlDropDwn) {
                this.ContentControlDropDwn.destroy();
                this.ContentControlDropDwn = undefined;
            }
            Eif (this.toolbar) {
                var toolbarElement = this.toolbar.element;
                this.toolbar.destroy();
                this.toolbar = undefined;
                toolbarElement.parentElement.removeChild(toolbarElement);
            }
            Eif (this.container.toolbarContainer) {
                this.container.containerTarget.removeChild(this.container.toolbarContainer);
                this.container.toolbarContainer = undefined;
            }
            Eif (this.container.toolbarModule) {
                this.container.toolbarModule = undefined;
            }
            Eif (this.propertiesPaneButton) {
                this.propertiesPaneButton.destroy();
            }
            Eif (this.breakListView) {
                this.breakListView.destroy();
                this.breakListView = undefined;
            }
            this.propertiesPaneButton = undefined;
            this.toolbarItems = [];
            this.toolbarItems = undefined;
            this.container = undefined;
        };
        return Toolbar;
    }());
    exports.Toolbar = Toolbar;
});