all files / document-editor-container/properties-pane/ header-footer-pane.js

66.31% Statements 185/279
22.22% Branches 16/72
39.39% Functions 13/33
66.31% Lines 185/279
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   60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60×     180×                     78× 78×           60× 60× 60×   77×           77× 77×         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× 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×   600× 60×     540×   600× 600×   60× 60× 60× 60× 60× 60×                                                                                                                                                                                                                                                                                       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× 59× 59×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-inputs"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_inputs_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HeaderFooterProperties = (function () {
        function HeaderFooterProperties(container, isRtl) {
            this.isHeaderTopApply = false;
            this.isFooterTopApply = false;
            this.HeaderTopApplyClickHook = this.headerTopApply.bind(this);
            this.FooterTopApplyClickHook = this.footerTopapply.bind(this);
            this.OnHeaderValueKeyDownHook = this.onHeaderValue.bind(this);
            this.OnFooterValueKeyDownHook = this.onFooterValue.bind(this);
            this.ChangeHeaderBlurHook = this.changeHeaderBlur.bind(this);
            this.ChangeFooterBlurHook = this.changeFooterBlur.bind(this);
            this.container = container;
            this.isRtl = isRtl;
            this.initHeaderFooterPane();
            this.wireEvents();
        }
        Object.defineProperty(HeaderFooterProperties.prototype, "documentEditor", {
            get: function () {
                return this.container.documentEditor;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(HeaderFooterProperties.prototype, "toolbar", {
            get: function () {
                return this.container.toolbarModule;
            },
            enumerable: true,
            configurable: true
        });
        HeaderFooterProperties.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'], []);
            }
        };
        HeaderFooterProperties.prototype.initHeaderFooterPane = function () {
            this.initializeHeaderFooter();
            this.element.style.display = 'none';
            this.container.propertiesPaneContainer.appendChild(this.element);
        };
        HeaderFooterProperties.prototype.showHeaderFooterPane = function (isShow) {
            Iif (isShow) {
                if (this.toolbar) {
                    this.toolbar.enableDisablePropertyPaneButton(false);
                }
                this.onSelectionChange();
            }
            Eif (!isShow && this.element.style.display === 'none' || (isShow && this.element.style.display === 'block')) {
                return;
            }
            this.element.style.display = isShow ? 'block' : 'none';
            this.documentEditor.resize();
        };
        HeaderFooterProperties.prototype.initializeHeaderFooter = function () {
            var _this = this;
            this.localObj = new ej2_base_1.L10n('documenteditorcontainer', this.container.defaultLocale, this.container.locale);
            this.elementId = 'header_footer_properties';
            this.element = ej2_base_1.createElement('div', { id: this.documentEditor.element.id + this.elementId, className: 'e-de-prop-pane' });
            this.headerDiv = this.createDivTemplate('_header_footer', this.element, 'padding-bottom:0');
            ej2_base_1.classList(this.headerDiv, ['e-de-cntr-pane-padding'], []);
            this.headerLabel = ej2_base_1.createElement('label', { className: 'e-de-prop-header-label' });
            this.headerLabel.innerHTML = this.localObj.getConstant('Header And Footer');
            var closeButtonFloat;
            if (!this.isRtl) {
                closeButtonFloat = 'float:right;';
            }
            else {
                closeButtonFloat = 'float:left;';
            }
            this.closeIcon = ej2_base_1.createElement('span', {
                id: '_header_footer_close',
                className: 'e-de-ctnr-close e-de-close-icon e-icons',
                styles: 'display:inline-block;cursor:pointer;' + closeButtonFloat
            });
            this.closeIcon.addEventListener('click', function () {
                _this.onClose();
            });
            this.headerDiv.appendChild(this.headerLabel);
            this.headerDiv.appendChild(this.closeIcon);
            this.optionsLabelDiv = this.createDivTemplate(this.elementId + '_options', this.element);
            ej2_base_1.classList(this.optionsLabelDiv, ['e-de-cntr-pane-padding', 'e-de-prop-separator-line'], []);
            this.optionsLabel = ej2_base_1.createElement('label', { className: 'e-de-ctnr-prop-label', styles: 'height:20px;' });
            this.optionsLabel.innerHTML = this.localObj.getConstant('Options');
            this.optionsLabelDiv.appendChild(this.optionsLabel);
            this.optionsDiv = this.createDivTemplate(this.elementId + '_optionsDiv', this.optionsLabelDiv);
            this.firstPageDiv = this.createDivTemplate(this.elementId + '_firstPageDiv', this.optionsDiv);
            ej2_base_1.classList(this.firstPageDiv, ['e-de-hdr-ftr-frst-div'], []);
            var firstPage = ej2_base_1.createElement('input', { id: 'firstPage', className: 'e-de-prop-sub-label' });
            this.firstPageDiv.appendChild(firstPage);
            this.firstPage = new ej2_buttons_1.CheckBox({ label: this.localObj.getConstant('Different First Page'), change: this.changeFirstPageOptions.bind(this), cssClass: 'e-de-prop-sub-label', enableRtl: this.isRtl });
            this.firstPage.appendTo(firstPage);
            this.firstPageDiv.children[0].setAttribute('title', this.localObj.getConstant('Different header and footer for first page'));
            this.oddOrEvenDiv = this.createDivTemplate(this.elementId + '_oddOrEvenDiv', this.optionsDiv);
            ej2_base_1.classList(this.oddOrEvenDiv, ['e-de-hdr-ftr-frst-div'], []);
            var oddOrEven = ej2_base_1.createElement('input', { id: 'oddOrEven', className: 'e-de-sub-prop-label' });
            this.oddOrEvenDiv.appendChild(oddOrEven);
            this.oddOrEven = new ej2_buttons_1.CheckBox({ label: this.localObj.getConstant('Different Odd And Even Pages'), change: this.changeoddOrEvenOptions.bind(this), cssClass: 'e-de-prop-sub-label', enableRtl: this.isRtl });
            this.oddOrEven.appendTo(oddOrEven);
            this.oddOrEvenDiv.children[0].setAttribute('title', this.localObj.getConstant('Different header and footer for odd and even pages'));
            this.linkToPreviousDiv = this.createDivTemplate(this.elementId + '_linkToPreviousDiv', this.optionsDiv);
            var linkToPrevious = ej2_base_1.createElement('input', { id: 'linkToPrevious', className: 'e-de-sub-prop-label' });
            this.linkToPreviousDiv.appendChild(linkToPrevious);
            this.linkToPrevious = new ej2_buttons_1.CheckBox({ label: this.localObj.getConstant('Link to Previous'), change: this.changeLinkToPreviousOptions.bind(this), cssClass: 'e-de-prop-sub-label', enableRtl: this.isRtl, checked: true });
            this.linkToPrevious.appendTo(linkToPrevious);
            this.linkToPreviousDiv.children[0].setAttribute('title', this.localObj.getConstant('Link to the previous Title'));
            this.positionLabelDiv = this.createDivTemplate(this.elementId + '_positionLabelDiv', this.element);
            ej2_base_1.classList(this.positionLabelDiv, ['e-de-cntr-pane-padding', 'e-de-prop-separator-line'], []);
            this.positionLabel = ej2_base_1.createElement('label', { className: 'e-de-ctnr-prop-label', styles: 'height:20px;' });
            this.positionLabel.innerHTML = this.localObj.getConstant('Position');
            this.positionLabelDiv.appendChild(this.positionLabel);
            this.positionDiv = this.createDivTemplate(this.elementId + '_positionDiv', this.positionLabelDiv);
            this.headerTopDiv = this.createDivTemplate(this.elementId + '_headerTopDiv', this.positionDiv);
            ej2_base_1.classList(this.headerTopDiv, ['e-de-hdr-ftr-top-div'], []);
            this.headerTopLabel = ej2_base_1.createElement('label', { className: 'e-de-prop-sub-label', styles: 'display:block' });
            this.headerTopLabel.innerHTML = this.localObj.getConstant('Header from Top');
            this.headerTopDiv.appendChild(this.headerTopLabel);
            var headerFromTop = ej2_base_1.createElement('input', { id: this.documentEditor.element.id + '_headerFromTop', className: 'e-de-prop-sub-label' });
            headerFromTop.setAttribute('aria-label', this.localObj.getConstant('Header from Top'));
            this.headerTopDiv.appendChild(headerFromTop);
            this.headerFromTop = new ej2_inputs_1.NumericTextBox({
                value: 36, cssClass: 'e-de-prop-header-numeric',
                showSpinButton: false, format: 'n0', decimals: 2, max: 1584, min: 0, enableRtl: this.isRtl
            });
            this.headerFromTop.appendTo(headerFromTop);
            this.headerFromTop.element.parentElement.setAttribute('title', this.localObj.getConstant('Distance from top of the page to top of the header'));
            this.footerBottomDiv = this.createDivTemplate(this.elementId + '_footerBottomDiv', this.positionDiv);
            this.footerBottomLabel = ej2_base_1.createElement('label', { className: 'e-de-prop-sub-label', styles: 'display:block' });
            this.footerBottomLabel.innerHTML = this.localObj.getConstant('Footer from Bottom');
            this.footerBottomDiv.appendChild(this.footerBottomLabel);
            var footerFromTop = ej2_base_1.createElement('input', { id: this.documentEditor.element.id + '_footerFromTop', className: 'e-de-prop-sub-label' });
            footerFromTop.setAttribute('aria-label', this.localObj.getConstant('Footer from Bottom'));
            this.footerBottomDiv.appendChild(footerFromTop);
            this.footerFromTop = new ej2_inputs_1.NumericTextBox({
                value: 36, cssClass: 'e-de-prop-header-numeric',
                showSpinButton: false, format: 'n0', decimals: 2, max: 1584, min: 0, enableRtl: this.isRtl
            });
            this.footerFromTop.appendTo(footerFromTop);
            this.footerFromTop.element.parentElement.setAttribute('title', this.localObj.getConstant('Distance from bottom of the page to bottom of the footer'));
        };
        HeaderFooterProperties.prototype.createDivTemplate = function (id, parentDiv, style) {
            if (style) {
                this.divElement = ej2_base_1.createElement('div', { id: id, styles: style });
            }
            else {
                this.divElement = ej2_base_1.createElement('div', { id: id });
            }
            parentDiv.appendChild(this.divElement);
            return this.divElement;
        };
        HeaderFooterProperties.prototype.wireEvents = function () {
            this.headerFromTop.element.addEventListener('click', this.HeaderTopApplyClickHook);
            this.footerFromTop.element.addEventListener('click', this.FooterTopApplyClickHook);
            this.headerFromTop.element.addEventListener('keydown', this.OnHeaderValueKeyDownHook);
            this.footerFromTop.element.addEventListener('keydown', this.OnFooterValueKeyDownHook);
            this.headerFromTop.element.addEventListener('blur', this.ChangeHeaderBlurHook);
            this.footerFromTop.element.addEventListener('blur', this.ChangeFooterBlurHook);
        };
        HeaderFooterProperties.prototype.headerTopApply = function () {
            this.isHeaderTopApply = true;
        };
        HeaderFooterProperties.prototype.footerTopapply = function () {
            this.isFooterTopApply = true;
        };
        HeaderFooterProperties.prototype.changeHeaderBlur = function () {
            this.changeHeaderValue();
            this.isHeaderTopApply = false;
        };
        HeaderFooterProperties.prototype.changeFooterBlur = function () {
            this.changeFooterValue();
            this.isFooterTopApply = false;
        };
        HeaderFooterProperties.prototype.onClose = function () {
            this.container.showHeaderProperties = true;
            this.container.documentEditor.selectionModule.closeHeaderFooter();
        };
        HeaderFooterProperties.prototype.changeFirstPageOptions = function () {
            var _this = this;
            if (!this.documentEditor.isReadOnly) {
                this.documentEditor.selectionModule.sectionFormat.differentFirstPage = this.firstPage.checked;
                setTimeout(function () {
                    _this.documentEditor.focusIn();
                }, 10);
            }
        };
        HeaderFooterProperties.prototype.changeoddOrEvenOptions = function () {
            var _this = this;
            if (!this.documentEditor.isReadOnly) {
                this.documentEditor.selectionModule.sectionFormat.differentOddAndEvenPages = this.oddOrEven.checked;
                setTimeout(function () {
                    _this.documentEditor.focusIn();
                }, 10);
            }
        };
        HeaderFooterProperties.prototype.changeLinkToPreviousOptions = function () {
            var _this = this;
            if (!this.documentEditor.isReadOnly) {
                var headerFooterType = (this.documentEditor.selectionModule.start.paragraph.containerWidget).headerFooterType;
                var value = this.linkToPrevious.checked;
                switch (headerFooterType) {
                    case 'OddHeader':
                        this.documentEditor.selectionModule.sectionFormat.oddPageHeader.linkToPrevious = value;
                        break;
                    case 'OddFooter':
                        this.documentEditor.selectionModule.sectionFormat.oddPageFooter.linkToPrevious = value;
                        break;
                    case 'EvenHeader':
                        this.documentEditor.selectionModule.sectionFormat.evenPageHeader.linkToPrevious = value;
                        break;
                    case 'EvenFooter':
                        this.documentEditor.selectionModule.sectionFormat.evenPageFooter.linkToPrevious = value;
                        break;
                    case 'FirstPageHeader':
                        this.documentEditor.selectionModule.sectionFormat.firstPageHeader.linkToPrevious = value;
                        break;
                    case 'FirstPageFooter':
                        this.documentEditor.selectionModule.sectionFormat.firstPageFooter.linkToPrevious = value;
                        break;
                }
                setTimeout(function () {
                    _this.documentEditor.focusIn();
                }, 10);
            }
        };
        HeaderFooterProperties.prototype.changeHeaderValue = function () {
            if (!this.isHeaderTopApply) {
                return;
            }
            if (!this.documentEditor.isReadOnly) {
                var headerTop = this.headerFromTop.value;
                if (headerTop > this.headerFromTop.max) {
                    headerTop = this.headerFromTop.max;
                }
                this.documentEditor.selectionModule.sectionFormat.headerDistance = headerTop;
            }
        };
        HeaderFooterProperties.prototype.onHeaderValue = function (e) {
            var _this = this;
            if (e.keyCode === 13) {
                setTimeout(function () {
                    _this.changeHeaderValue();
                    _this.isHeaderTopApply = false;
                }, 30);
            }
        };
        HeaderFooterProperties.prototype.onFooterValue = function (e) {
            var _this = this;
            if (e.keyCode === 13) {
                setTimeout(function () {
                    _this.changeFooterValue();
                    _this.isFooterTopApply = false;
                }, 30);
            }
        };
        HeaderFooterProperties.prototype.changeFooterValue = function () {
            if (!this.isFooterTopApply) {
                return;
            }
            if (!this.documentEditor.isReadOnly) {
                var footerTop = this.footerFromTop.value;
                if (footerTop > this.footerFromTop.max) {
                    footerTop = this.footerFromTop.max;
                }
                this.documentEditor.selectionModule.sectionFormat.footerDistance = footerTop;
            }
        };
        HeaderFooterProperties.prototype.onSelectionChange = function () {
            this.headerFromTop.value = this.documentEditor.selectionModule.sectionFormat.headerDistance;
            this.footerFromTop.value = this.documentEditor.selectionModule.sectionFormat.footerDistance;
            if (this.documentEditor.selectionModule.sectionFormat.differentFirstPage) {
                this.firstPage.checked = true;
            }
            else {
                this.firstPage.checked = false;
            }
            if (this.documentEditor.selectionModule.sectionFormat.differentOddAndEvenPages) {
                this.oddOrEven.checked = true;
            }
            else {
                this.oddOrEven.checked = false;
            }
            if (this.documentEditor.selectionModule.start.paragraph.bodyWidget.sectionIndex === 0) {
                this.linkToPrevious.disabled = true;
            }
            else {
                this.linkToPrevious.disabled = false;
                var headerFooterType = (this.documentEditor.selectionModule.start.paragraph.containerWidget).headerFooterType;
                switch (headerFooterType) {
                    case 'OddHeader':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.oddPageHeader.linkToPrevious;
                        break;
                    case 'OddFooter':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.oddPageFooter.linkToPrevious;
                        break;
                    case 'EvenHeader':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.evenPageHeader.linkToPrevious;
                        break;
                    case 'EvenFooter':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.evenPageFooter.linkToPrevious;
                        break;
                    case 'FirstPageHeader':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.firstPageHeader.linkToPrevious;
                        break;
                    case 'FirstPageFooter':
                        this.linkToPrevious.checked = this.documentEditor.selectionModule.sectionFormat.firstPageFooter.linkToPrevious;
                        break;
                }
            }
        };
        HeaderFooterProperties.prototype.destroy = function () {
            this.unWireEvents();
            this.removeHTMLDOM();
            Eif (this.element) {
                this.element.innerHTML = '';
                Eif (this.element.parentElement) {
                    this.element.parentElement.removeChild(this.element);
                }
            }
            this.element = undefined;
            Eif (this.firstPage) {
                this.firstPage.destroy();
            }
            this.firstPage = undefined;
            Eif (this.oddOrEven) {
                this.oddOrEven.destroy();
            }
            this.oddOrEven = undefined;
            Eif (this.linkToPrevious) {
                this.linkToPrevious.destroy();
            }
            this.linkToPrevious = undefined;
            Eif (this.headerFromTop) {
                this.headerFromTop.destroy();
                this.headerFromTop = undefined;
            }
            Eif (this.footerFromTop) {
                this.footerFromTop.destroy();
                this.footerFromTop = undefined;
            }
            this.container = undefined;
            this.localObj = undefined;
            this.elementId = undefined;
        };
        HeaderFooterProperties.prototype.unWireEvents = function () {
            this.headerFromTop.element.removeEventListener('click', this.HeaderTopApplyClickHook);
            this.footerFromTop.element.removeEventListener('click', this.FooterTopApplyClickHook);
            this.headerFromTop.element.removeEventListener('keydown', this.OnHeaderValueKeyDownHook);
            this.footerFromTop.element.removeEventListener('keydown', this.OnFooterValueKeyDownHook);
            this.headerFromTop.element.removeEventListener('blur', this.ChangeHeaderBlurHook);
            this.footerFromTop.element.removeEventListener('blur', this.ChangeFooterBlurHook);
            this.HeaderTopApplyClickHook = undefined;
            this.FooterTopApplyClickHook = undefined;
            this.OnHeaderValueKeyDownHook = undefined;
            this.OnFooterValueKeyDownHook = undefined;
            this.ChangeHeaderBlurHook = undefined;
            this.ChangeFooterBlurHook = undefined;
        };
        HeaderFooterProperties.prototype.removeHTMLDOM = function () {
            this.headerDiv.remove();
            this.headerLabel.remove();
            this.closeIcon.remove();
            this.optionsLabelDiv.remove();
            this.optionsLabel.remove();
            this.optionsDiv.remove();
            this.firstPageDiv.remove();
            this.oddOrEvenDiv.remove();
            this.linkToPreviousDiv.remove();
            this.positionLabelDiv.remove();
            this.positionLabel.remove();
            this.positionDiv.remove();
            this.headerTopDiv.remove();
            this.headerTopLabel.remove();
            this.footerBottomDiv.remove();
            this.footerBottomLabel.remove();
            this.divElement.remove();
        };
        return HeaderFooterProperties;
    }());
    exports.HeaderFooterProperties = HeaderFooterProperties;
});