all files / document-editor-container/properties-pane/ table-of-content-pane.js

90.8% Statements 227/250
57.81% Branches 37/64
80.77% Functions 21/26
90.8% Lines 227/250
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   60× 60× 60× 60× 60× 60×     170×                     78× 78×           60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60×   60× 60× 60×   60× 60× 60×                               60× 60× 60× 59× 59×       60×       60× 60× 60×     60× 60× 60×       60×   60×   60×     60×   60× 60×     60× 60× 60×     60× 60× 60×     60× 60×   60× 60× 60× 60×   60× 60× 60×   60× 60× 60× 60×   60× 60× 60× 59×       60× 60× 60× 60× 60× 59×       60× 60× 60× 60× 60× 60× 60×     60×   60× 60× 59×       60× 60× 60× 60× 60× 60× 60× 60×       60× 60× 60× 60× 60× 60× 60×       60× 60× 60× 60× 60× 60× 60×       60×   60× 60× 59×       60× 60× 60×       60× 60×     60× 60×       60× 60×     60× 60×   77× 67×     10×     77× 55× 55×   55×   22× 22× 22× 22× 22×                 22×   22× 22× 22×                                   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× 59×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-dropdowns"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_dropdowns_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TocProperties = (function () {
        function TocProperties(container, isRtl) {
            this.onCloseClickHook = this.onCloseClick.bind(this);
            this.onInsertToClickHook = this.onInsertToc.bind(this);
            this.container = container;
            this.elementId = this.documentEditor.element.id;
            this.isRtl = isRtl;
            this.initializeTocPane();
        }
        Object.defineProperty(TocProperties.prototype, "documentEditor", {
            get: function () {
                return this.container.documentEditor;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(TocProperties.prototype, "toolbar", {
            get: function () {
                return this.container.toolbarModule;
            },
            enumerable: true,
            configurable: true
        });
        TocProperties.prototype.enableDisableElements = function (enable) {
            Eif (enable) {
                ej2_base_1.classList(this.element, [], ['e-de-overlay']);
            }
            else {
                ej2_base_1.classList(this.element, ['e-de-overlay'], []);
            }
        };
        TocProperties.prototype.initializeTocPane = function () {
            this.localObj = new ej2_base_1.L10n('documenteditorcontainer', this.container.defaultLocale, this.container.locale);
            this.element = ej2_base_1.createElement('div', { id: this.elementId + '_tocProperties', className: 'e-de-prop-pane' });
            var container = ej2_base_1.createElement('div', { className: 'e-de-cntr-pane-padding e-de-prop-separator-line' });
            this.tocHeaderDiv(container);
            this.initTemplates(container);
            container = ej2_base_1.createElement('div', { className: 'e-de-cntr-pane-padding' });
            this.tocOptionsDiv(container);
            this.contentStylesDropdown(container);
            this.checkboxContent(container);
            this.buttonDiv(container);
            this.wireEvents();
            this.updateTocProperties();
            this.container.propertiesPaneContainer.appendChild(this.element);
        };
        TocProperties.prototype.updateTocProperties = function () {
            this.rightalignPageNumber.checked = true;
            this.showPageNumber.checked = true;
            this.hyperlink.checked = true;
        };
        TocProperties.prototype.wireEvents = function () {
            this.cancelBtn.element.addEventListener('click', this.onCloseClickHook);
            this.updateBtn.element.addEventListener('click', this.onInsertToClickHook);
            this.closeButton.addEventListener('click', this.onCloseClickHook);
        };
        TocProperties.prototype.onCloseClick = function () {
            this.onClose();
        };
        TocProperties.prototype.onClose = function () {
            if (this.container.showPropertiesPane
                && this.container.previousContext !== 'TableOfContents') {
                this.container.showPropertiesPaneOnSelection();
            }
            else {
                this.showTocPane(false);
                if (this.toolbar) {
                    this.toolbar.enableDisablePropertyPaneButton(false);
                }
                this.container.showPropertiesPane = false;
            }
        };
        TocProperties.prototype.tocHeaderDiv = function (container) {
            var closeButtonFloat;
            var closeButtonMargin;
            if (!this.isRtl) {
                closeButtonFloat = 'float:right;';
                closeButtonMargin = 'margin-right:7px;';
            }
            else {
                closeButtonFloat = 'float:left;';
                closeButtonMargin = 'margin-left:7px;';
            }
            this.headerDiv = ej2_base_1.createElement('div', {
                id: this.elementId + 'toc_id',
                styles: 'display: block;'
            });
            container.appendChild(this.headerDiv);
            this.element.appendChild(container);
            this.title = ej2_base_1.createElement('label', {
                className: 'e-de-ctnr-prop-label'
            });
            this.title.textContent = this.localObj.getConstant('Table of Contents');
            this.headerDiv.appendChild(this.title);
            this.closeButton = ej2_base_1.createElement('span', {
                className: 'e-de-ctnr-close e-icons',
                styles: 'cursor: pointer;display:inline-block;color: #4A4A4A;' + closeButtonFloat + closeButtonMargin
            });
            this.headerDiv.appendChild(this.closeButton);
        };
        TocProperties.prototype.initTemplates = function (container) {
            this.template1(container);
        };
        TocProperties.prototype.template1 = function (container) {
            this.template1Div = ej2_base_1.createElement('div', {
                className: 'e-de-toc-template1'
            });
            if (this.isRtl) {
                this.template1Div.classList.add('e-de-rtl');
            }
            container.appendChild(this.template1Div);
            this.templateContent1 = ej2_base_1.createElement('div', {
                className: 'e-de-toc-template1-content1'
            });
            this.templateContent1.textContent = this.localObj.getConstant('HEADING - - - - 1');
            this.template1Div.appendChild(this.templateContent1);
            this.templateContent2 = ej2_base_1.createElement('div', {
                className: 'e-de-toc-template1-content2'
            });
            this.templateContent2.textContent = this.localObj.getConstant('HEADING - - - - 2');
            this.template1Div.appendChild(this.templateContent2);
            this.templateContent3 = ej2_base_1.createElement('div', {
                className: 'e-de-toc-template1-content3'
            });
            this.templateContent3.textContent = this.localObj.getConstant('HEADING - - - - 3');
            this.template1Div.appendChild(this.templateContent3);
        };
        TocProperties.prototype.tocOptionsDiv = function (container) {
            this.optionsDiv = ej2_base_1.createElement('div');
            container.appendChild(this.optionsDiv);
            this.element.appendChild(container);
            if (this.isRtl) {
                this.optionsDiv.classList.add('e-de-rtl');
            }
            this.label = ej2_base_1.createElement('label', { className: 'e-de-ctnr-prop-label' });
            this.label.textContent = this.localObj.getConstant('Options');
            this.optionsDiv.appendChild(this.label);
        };
        TocProperties.prototype.createDropDownButton = function (id, parentDiv, iconCss, content, selectedIndex) {
            var buttonElement = ej2_base_1.createElement('input', { id: id });
            parentDiv.appendChild(buttonElement);
            var dropDownBtn = new ej2_dropdowns_1.DropDownList({ index: selectedIndex, dataSource: content, popupHeight: '150px', cssClass: 'e-de-prop-font-button', placeholder: this.localObj.getConstant('Levels') }, buttonElement);
            return dropDownBtn;
        };
        TocProperties.prototype.contentStylesDropdown = function (container) {
            var _this = this;
            var contentStyleElementMargin;
            if (!this.isRtl) {
                contentStyleElementMargin = 'margin-left:5.5px;';
            }
            else {
                contentStyleElementMargin = 'margin-right:5.5px;';
            }
            this.contentStyleElement = ej2_base_1.createElement('div', { id: 'contentstyle_div' });
            this.contentStyleElement.setAttribute('title', this.localObj.getConstant('Number of heading or outline levels to be shown in table of contents'));
            container.appendChild(this.contentStyleElement);
            var labelMargin;
            if (!this.isRtl) {
                labelMargin = 'margin-right:8px;';
            }
            else {
                labelMargin = 'margin-left:8px';
            }
            this.dropDownLabel = ej2_base_1.createElement('label', { className: 'e-de-prop-sub-label', styles: 'display:block' });
            this.dropDownLabel.textContent = this.localObj.getConstant('Levels');
            this.contentStyleElement.appendChild(this.dropDownLabel);
            container.appendChild(this.contentStyleElement);
            var dataSource = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
            this.borderLevelStyle = this.createDropDownButton(this.elementId + '_borderLevelDiv', this.contentStyleElement, '', dataSource, 2);
            this.borderLevelStyle.change = function (args) {
                _this.borderLevelStyle.value = args.item.value;
            };
            container.appendChild(this.contentStyleElement);
        };
        TocProperties.prototype.checkboxContent = function (container) {
            var checkboxElementMargin;
            if (!this.isRtl) {
                checkboxElementMargin = 'margin-left:5.5px;';
            }
            else {
                checkboxElementMargin = 'margin-right:5.5px;';
            }
            this.checkboxElement = ej2_base_1.createElement('div', { id: 'toc_checkboxDiv', styles: 'margin-bottom:36px;' });
            container.appendChild(this.checkboxElement);
            this.showPageNumberDiv = ej2_base_1.createElement('div', { className: 'e-de-toc-checkbox1' });
            this.showPageNumberDiv.setAttribute('title', this.localObj.getConstant('Show page numbers in table of contents'));
            this.checkboxElement.appendChild(this.showPageNumberDiv);
            this.showpagenumberCheckboxElement = ej2_base_1.createElement('input', { id: 'showpagenumber', styles: 'width:12px;height:12px;margin-bottom:8px', className: 'e-de-prop-sub-label' });
            this.showPageNumberDiv.appendChild(this.showpagenumberCheckboxElement);
            this.showPageNumber = new ej2_buttons_1.CheckBox({
                label: this.localObj.getConstant('Show page numbers'),
                enableRtl: this.isRtl
            });
            this.showPageNumber.appendTo(this.showpagenumberCheckboxElement);
            this.rightAlignDiv = ej2_base_1.createElement('div', { className: 'e-de-toc-checkbox2' });
            this.rightAlignDiv.setAttribute('title', this.localObj.getConstant('Right align page numbers in table of contents'));
            this.checkboxElement.appendChild(this.rightAlignDiv);
            this.rightalignpagenumberCheckboxElement = ej2_base_1.createElement('input', { id: 'rightalignpagenumber', styles: 'width:12px;height:12px', className: 'e-de-prop-sub-label' });
            this.rightAlignDiv.appendChild(this.rightalignpagenumberCheckboxElement);
            this.rightalignPageNumber = new ej2_buttons_1.CheckBox({
                label: this.localObj.getConstant('Right align page numbers'),
                enableRtl: this.isRtl
            });
            this.rightalignPageNumber.appendTo(this.rightalignpagenumberCheckboxElement);
            this.hyperlinkDiv = ej2_base_1.createElement('div', { className: 'e-de-toc-checkbox3' });
            this.hyperlinkDiv.setAttribute('title', this.localObj.getConstant('Use hyperlinks instead of page numbers'));
            this.checkboxElement.appendChild(this.hyperlinkDiv);
            this.hyperlinkCheckboxElement = ej2_base_1.createElement('input', { id: 'hyperlinkdiv', styles: 'width:12px;height:12px', className: 'e-de-prop-sub-label' });
            this.hyperlinkDiv.appendChild(this.hyperlinkCheckboxElement);
            this.hyperlink = new ej2_buttons_1.CheckBox({
                label: this.localObj.getConstant('Use hyperlinks'),
                enableRtl: this.isRtl
            });
            this.hyperlink.appendTo(this.hyperlinkCheckboxElement);
        };
        TocProperties.prototype.buttonDiv = function (container) {
            var footerElementFloat;
            if (!this.isRtl) {
                footerElementFloat = 'float:right';
            }
            else {
                footerElementFloat = 'float:left';
            }
            this.footerElement = ej2_base_1.createElement('div', { id: 'footerDiv', styles: footerElementFloat });
            container.appendChild(this.footerElement);
            this.updatebuttoncontentStyleElement = ej2_base_1.createElement('button', {
                id: 'footerupdatebuttonDiv',
                attrs: { type: 'button' }
            });
            this.footerElement.appendChild(this.updatebuttoncontentStyleElement);
            this.updateBtn = new ej2_buttons_1.Button({
                content: this.localObj.getConstant('Update'), cssClass: 'btn-update', isPrimary: true
            });
            this.updateBtn.appendTo(this.updatebuttoncontentStyleElement);
            this.cancelbuttoncontentStyleElement = ej2_base_1.createElement('button', {
                id: 'footercancelbuttonDiv',
                attrs: { type: 'button' }
            });
            this.footerElement.appendChild(this.cancelbuttoncontentStyleElement);
            this.cancelBtn = new ej2_buttons_1.Button({
                content: this.localObj.getConstant('Cancel'), cssClass: this.isRtl ? 'e-de-btn-cancel-rtl' : 'e-de-btn-cancel'
            });
            this.cancelbuttoncontentStyleElement.setAttribute('aria-label', this.cancelBtn.content);
            this.cancelBtn.appendTo(this.cancelbuttoncontentStyleElement);
        };
        TocProperties.prototype.enableDisableInsertButton = function (enable) {
            if (this.prevContext === 'Text') {
                this.updateBtn.disabled = enable;
            }
            else {
                this.updateBtn.disabled = false;
            }
        };
        TocProperties.prototype.showTocPane = function (isShow, previousContextType) {
            if (!isShow && this.element.style.display === 'none' || (isShow && this.element.style.display === 'block')) {
                Eif (this.updateBtn) {
                    this.enableDisableInsertButton(false);
                }
                return;
            }
            this.element.style.display = isShow ? 'block' : 'none';
            this.updateBtn.content = this.documentEditor.selectionModule.contextType === 'TableOfContents' ? this.localObj.getConstant('Update') : this.localObj.getConstant('Insert');
            this.updateBtn.element.setAttribute('aria-label', this.updateBtn.content);
            this.prevContext = this.documentEditor.selectionModule.contextType;
            Iif (this.documentEditor.selectionModule.contextType === 'TableOfContents') {
                var tocField = this.documentEditor.selectionModule.getTocFieldInternal();
                var code = this.documentEditor.selectionModule.getFieldCode(tocField);
                if (code.toLocaleLowerCase().indexOf('toc') !== -1 && !ej2_base_1.isNullOrUndefined(this.documentEditor.editorModule)) {
                    var tocSettings = this.documentEditor.editorModule.getTocSettings(code, tocField);
                    this.borderLevelStyle.value = tocSettings.endLevel.toString();
                }
            }
            else {
                this.borderLevelStyle.value = "3";
            }
            this.enableDisableInsertButton(this.documentEditor.selectionModule.isPlainContentControl());
            this.documentEditor.resize();
            Iif (isShow) {
                this.updateBtn.element.focus();
            }
        };
        TocProperties.prototype.onInsertToc = function () {
            var tocSettings = {
                startLevel: 1,
                endLevel: parseInt(this.borderLevelStyle.value, 0),
                includeHyperlink: this.hyperlink.checked,
                includeOutlineLevels: true,
                includePageNumber: this.showPageNumber.checked,
                rightAlign: this.rightalignPageNumber.checked
            };
            if (tocSettings.rightAlign) {
                tocSettings.tabLeader = 'Dot';
            }
            this.documentEditor.editorModule.insertTableOfContents(tocSettings);
            this.documentEditor.focusIn();
        };
        TocProperties.prototype.destroy = function () {
            this.container = undefined;
            this.removeHTMLDOM();
            this.unWireEvents();
            Eif (this.showPageNumber) {
                this.showPageNumber.destroy();
                this.showPageNumber = undefined;
            }
            Eif (this.rightalignPageNumber) {
                this.rightalignPageNumber.destroy();
                this.rightalignPageNumber = undefined;
            }
            Iif (this.borderBtn) {
                this.borderBtn.destroy();
                this.borderBtn = undefined;
            }
            Eif (this.borderLevelStyle) {
                this.borderLevelStyle.destroy();
                this.borderLevelStyle = undefined;
            }
            Eif (this.hyperlink) {
                this.hyperlink.destroy();
            }
            this.hyperlink = undefined;
            Eif (this.updateBtn) {
                this.updateBtn.destroy();
            }
            this.updateBtn = undefined;
            Eif (this.cancelBtn) {
                this.cancelBtn.destroy();
            }
            this.cancelBtn = undefined;
            this.localObj = undefined;
            this.isRtl = undefined;
            Eif (this.element) {
                this.element.innerHTML = '';
                this.element = undefined;
            }
        };
        TocProperties.prototype.unWireEvents = function () {
            this.cancelBtn.element.removeEventListener('click', this.onCloseClickHook);
            this.updateBtn.element.removeEventListener('click', this.onInsertToClickHook);
            this.closeButton.removeEventListener('click', this.onCloseClickHook);
            this.onCloseClickHook = undefined;
            this.onInsertToClickHook = undefined;
        };
        TocProperties.prototype.removeHTMLDOM = function () {
            this.template1Div.remove();
            this.headerDiv.remove();
            this.closeButton.remove();
            this.title.remove();
            this.templateContent1.remove();
            this.templateContent2.remove();
            this.templateContent3.remove();
            this.optionsDiv.remove();
            this.label.remove();
            this.contentStyleElement.remove();
            this.checkboxElement.remove();
            this.showPageNumberDiv.remove();
            this.showpagenumberCheckboxElement.remove();
            this.rightAlignDiv.remove();
            this.rightalignpagenumberCheckboxElement.remove();
            this.hyperlinkDiv.remove();
            this.hyperlinkCheckboxElement.remove();
            this.footerElement.remove();
            this.updatebuttoncontentStyleElement.remove();
            this.cancelbuttoncontentStyleElement.remove();
        };
        return TocProperties;
    }());
    exports.TocProperties = TocProperties;
});