all files / document-editor/implementation/editor/ locked-region-alert.js

78.1% Statements 107/137
61.96% Branches 57/92
80.95% Functions 17/21
78.1% Lines 107/137
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 1951×   1× 1× 1× 4× 4× 4× 4×   1× 9×     9× 9× 9× 9× 9× 9× 9×   1×           1× 21×     21×   1× 4× 4× 4× 4× 4×     1×   21×         1×                             1× 9× 5×   4× 4×         4×     4× 4× 4× 4×       4× 4× 4× 4× 4× 4× 4× 4× 4× 4× 4×         4×   1× 34×     34× 34× 34× 34× 34× 34× 34×             34× 34× 34×   34× 34×   1× 34× 34×     34× 34×   1× 9× 9×     9× 9×   1× 4× 4×     4× 4×     1×     1× 28× 28×       1× 9× 9× 9× 9× 9× 9×   9× 9× 9×     1× 9× 9× 9× 4×     1× 13× 9× 9×     1×         1×   1×    
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var LockedRegionAlert = (function () {
        function LockedRegionAlert(owner) {
            this.displayDuration = 5000;
            this.onScrollHandler = this.onViewerScroll.bind(this);
            this.onCloseClickHandler = this.onCloseClick.bind(this);
            this.owner = owner;
        }
        LockedRegionAlert.prototype.show = function () {
            Iif (!this.owner || !this.owner.element) {
                return;
            }
            this.ensureBanner();
            this.anchorBelowRulers();
            this.wireScroll();
            this.updateLocalizedText();
            this.banner.hidden = false;
            ej2_base_1.updateCSSText(this.banner, 'display:flex');
            this.restartTimer();
        };
        LockedRegionAlert.prototype.refreshLocale = function () {
            if (!this.isShown) {
                return;
            }
            this.updateLocalizedText();
        };
        LockedRegionAlert.prototype.refreshLayout = function () {
            Iif (!this.isShown) {
                return;
            }
            this.anchorBelowRulers();
        };
        LockedRegionAlert.prototype.hide = function () {
            this.clearTimer();
            this.unwireScroll();
            Eif (this.banner) {
                this.banner.hidden = true;
                ej2_base_1.updateCSSText(this.banner, 'display:none');
            }
        };
        Object.defineProperty(LockedRegionAlert.prototype, "isShown", {
            get: function () {
                return !!this.banner && !this.banner.hidden && this.banner.style.display !== 'none';
            },
            enumerable: true,
            configurable: true
        });
        LockedRegionAlert.prototype.destroy = function () {
            this.clearTimer();
            this.unwireScroll();
            if (this.closeButton) {
                this.closeButton.removeEventListener('click', this.onCloseClickHandler);
                this.closeButton = undefined;
            }
            this.closeIcon = undefined;
            if (this.banner && this.banner.parentNode) {
                this.banner.parentNode.removeChild(this.banner);
            }
            this.banner = undefined;
            this.messageElement = undefined;
            this.owner = undefined;
        };
        LockedRegionAlert.prototype.ensureBanner = function () {
            if (this.banner) {
                return;
            }
            var hostId = this.owner.element.id || 'documenteditor';
            this.banner = ej2_base_1.createElement('div', {
                id: hostId + '_lockedRegionAlert',
                className: 'e-de-locked-alert',
                attrs: { role: 'alert' }
            });
            ej2_base_1.updateCSSText(this.banner, 'display:none;align-items:center;box-sizing:border-box;gap:8px;height:42px;min-height:40px;max-height:45px;'
                + 'padding:0 8px 0 16px;'
                + 'font-size:14px;line-height:20px;font-weight:400;position:absolute;z-index:2;border-bottom-width:1px;border-bottom-style:solid;');
            this.banner.hidden = true;
            this.messageElement = ej2_base_1.createElement('span', { className: 'e-de-locked-alert-text' });
            ej2_base_1.updateCSSText(this.messageElement, 'flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;');
            this.closeButton = ej2_base_1.createElement('button', {
                className: 'e-de-op-close-button e-de-close-icon e-de-op-icon-btn e-btn e-flat e-icon-btn',
                attrs: { type: 'button' }
            });
            ej2_base_1.updateCSSText(this.closeButton, 'position:relative;left:auto;top:auto;flex:0 0 auto;width:28px;height:28px;min-width:28px;padding:0;margin:0;');
            this.closeIcon = ej2_base_1.createElement('span', { className: 'e-de-op-close-icon e-de-close-icon e-btn-icon e-icons' });
            ej2_base_1.updateCSSText(this.closeIcon, 'display:inline-block;width:16px;height:16px;font-size:16px;line-height:16px;');
            this.closeButton.appendChild(this.closeIcon);
            this.closeButton.addEventListener('click', this.onCloseClickHandler);
            this.banner.appendChild(this.messageElement);
            this.banner.appendChild(this.closeButton);
            var viewerContainer = this.owner.documentHelper && this.owner.documentHelper.viewerContainer;
            var pageContainer = this.owner.documentHelper && this.owner.documentHelper.pageContainer;
            Eif (viewerContainer) {
                viewerContainer.appendChild(this.banner);
            }
            else {
                this.owner.element.insertBefore(this.banner, this.owner.element.firstChild);
            }
            this.anchorBelowRulers();
        };
        LockedRegionAlert.prototype.anchorBelowRulers = function () {
            Iif (!this.banner || !this.owner || !this.owner.element) {
                return;
            }
            var hostId = this.owner.element.id || 'documenteditor';
            var viewer = this.owner.documentHelper && this.owner.documentHelper.viewerContainer;
            var horizontalRuler = this.owner.element.querySelector('#' + hostId + '_hRulerBottom');
            var verticalRuler = this.owner.element.querySelector('#' + hostId + '_vRulerBottom');
            var top = horizontalRuler ? horizontalRuler.offsetHeight : 0;
            var left = 0;
            Iif (verticalRuler && viewer && this.isRulerShown(verticalRuler)) {
                var viewerBox = viewer.getBoundingClientRect();
                var rulerBox = verticalRuler.getBoundingClientRect();
                if (rulerBox.width > 0 && rulerBox.right > viewerBox.left) {
                    left = Math.max(0, Math.round(rulerBox.right - viewerBox.left));
                }
            }
            var contentWidth = viewer ? viewer.clientWidth : 0;
            var width = contentWidth > left ? contentWidth - left : 0;
            ej2_base_1.updateCSSText(this.banner, 'position:absolute;top:' + top + 'px;left:' + left + 'px;z-index:2;'
                + 'margin-left:' + (viewer ? viewer.scrollLeft : 0) + 'px;');
            ej2_base_1.updateCSSText(this.banner, 'width:' + (width ? width + 'px' : 'calc(100% - ' + left + 'px)'));
            this.pinToVisibleArea();
        };
        LockedRegionAlert.prototype.pinToVisibleArea = function () {
            var viewer = this.owner && this.owner.documentHelper && this.owner.documentHelper.viewerContainer;
            Iif (!this.banner || !viewer || this.banner.style.position !== 'absolute') {
                return;
            }
            var top = parseFloat(this.banner.style.top) || 0;
            ej2_base_1.updateCSSText(this.banner, 'margin-top:' + viewer.scrollTop + 'px;margin-left:' + viewer.scrollLeft + 'px;top:' + top + 'px;');
        };
        LockedRegionAlert.prototype.wireScroll = function () {
            var viewer = this.owner && this.owner.documentHelper && this.owner.documentHelper.viewerContainer;
            Iif (!viewer) {
                return;
            }
            viewer.removeEventListener('scroll', this.onScrollHandler);
            viewer.addEventListener('scroll', this.onScrollHandler);
        };
        LockedRegionAlert.prototype.unwireScroll = function () {
            var viewer = this.owner && this.owner.documentHelper && this.owner.documentHelper.viewerContainer;
            Iif (viewer) {
                viewer.removeEventListener('scroll', this.onScrollHandler);
            }
            Eif (this.banner) {
                ej2_base_1.updateCSSText(this.banner, 'margin-top:0px');
            }
        };
        LockedRegionAlert.prototype.onViewerScroll = function () {
            this.pinToVisibleArea();
        };
        LockedRegionAlert.prototype.isRulerShown = function (ruler) {
            Eif (!this.owner.documentEditorSettings || !this.owner.documentEditorSettings.showRuler) {
                return false;
            }
            return ruler.style.display !== 'none' && ruler.offsetWidth > 0 && ruler.offsetHeight > 0;
        };
        LockedRegionAlert.prototype.updateLocalizedText = function () {
            var locale = new ej2_base_1.L10n('documenteditor', this.owner.defaultLocale);
            locale.setLocale(this.owner.locale);
            var message = locale.getConstant('You can\'t make this change because the selection is locked');
            var closeLabel = locale.getConstant('Close');
            Eif (this.messageElement) {
                this.messageElement.textContent = message;
            }
            Eif (this.closeButton) {
                this.closeButton.setAttribute('aria-label', closeLabel);
                this.closeButton.setAttribute('title', closeLabel);
            }
        };
        LockedRegionAlert.prototype.restartTimer = function () {
            var _this = this;
            this.clearTimer();
            this.hideTimer = window.setTimeout(function () {
                _this.hide();
            }, this.displayDuration);
        };
        LockedRegionAlert.prototype.clearTimer = function () {
            if (this.hideTimer) {
                window.clearTimeout(this.hideTimer);
                this.hideTimer = undefined;
            }
        };
        LockedRegionAlert.prototype.onCloseClick = function (event) {
            event.preventDefault();
            event.stopPropagation();
            this.hide();
        };
        return LockedRegionAlert;
    }());
    exports.LockedRegionAlert = LockedRegionAlert;
});