all files / grid/actions/ scroll.js

87.94% Statements 372/423
81.59% Branches 288/353
92.31% Functions 36/39
87.94% Lines 372/423
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 5901×   1× 1× 1× 1736× 1736× 1736× 1736× 1736×   1× 26520×   1× 4483× 4483× 4×   4483×   629× 629× 629× 629× 629× 629× 629× 629× 629× 629× 629×   594×       1× 4645× 4645× 4645× 4645× 32× 30×   32× 32× 2×     4645×     112×   112× 112× 46× 46× 46×   66×       112×   4533× 7×     4526×   4645× 4645× 485×     1× 1271× 1271× 1271× 1271× 1271×   1× 1699× 1699× 1699× 1699× 1699× 1699× 1×     1× 3960×   64× 64× 64× 64×     64×     64×     1× 1271× 1271× 2×   1269×   1× 1737× 1×   1736× 1736× 1736× 1736× 1736×   1× 1637× 3×   1634× 1634× 1634× 1634× 1634× 1634×   1× 1634× 88× 88×   1634× 1634× 12× 12×   12× 12× 12× 12× 12×     12× 12× 12× 12×     1634× 1538×   1634× 1538×   1634× 1634× 1634× 1×     1× 2435×   1× 102× 102×     102× 102× 102× 102× 16×     86×   102× 102× 102× 32×       32×       70×     1× 3386× 3386× 3386× 3386× 203×     203× 203× 13× 11×     2×     203× 28× 28× 28× 28× 28×           28×         203× 203×   75×   203× 13× 13×   203× 203× 203× 187× 187×   16× 16× 16× 1×   16×     16× 16×     1× 39× 39× 39× 39× 17×     17× 17× 17× 12×   5× 5× 5× 1×   5× 5× 5×         1× 122× 122× 122×                                             1× 122× 122×             1×                       1× 19× 1×   18× 18× 18×   10×     8×     1× 11× 11× 4×   4×     4× 4×   7× 4× 4× 4×     1× 148× 148× 115× 115×     33×   148× 148×   1× 2695× 2695× 1650× 1650× 1650× 1650× 1650× 96× 96×   1650× 13× 13× 13× 13× 13× 13× 13× 13×     1650× 1650× 1650× 1650× 1650× 86×   1650× 4×   1650× 1650×   2695× 2695× 2695× 2695× 2695× 2692× 2692× 2692×   2692× 2692× 2692× 101× 101×   2692× 147×   2692× 151× 139×     12×     2692× 2348× 2348× 2348× 2348×     2692× 2607× 2607× 228×       2695×   1× 102× 102× 102× 37×       102× 102× 1×     1× 2973× 2973× 2973× 2973× 2973×   1× 4645×   1× 134× 116×   18× 18× 18× 4×   18× 18× 18× 18×   1× 4× 4× 5× 5× 5× 5× 5× 5× 5× 5×   5× 5× 5× 5× 5×     5× 1× 1× 1× 1× 1×   1× 1× 1×   1× 1×           4× 1× 1× 1×   1×     1× 1×     1×             5×         1× 5× 3×     2×   5× 5× 5×   1× 1635× 1635×     1635× 1635× 1635× 1635× 3×   1635× 1635× 1635× 1635× 1635×   1× 1360×   1×   1×    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/util", "../base/constant", "../base/constant", "../services/width-controller", "../base/string-literals", "../base/constant"], function (require, exports, ej2_base_1, ej2_base_2, ej2_base_3, util_1, constant_1, constant_2, width_controller_1, literals, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Scroll = (function () {
        function Scroll(parent) {
            this.previousValues = { top: 0, left: 0 };
            this.oneTimeReady = true;
            this.parent = parent;
            this.widthService = new width_controller_1.ColumnWidthService(parent);
            this.addEventListener();
        }
        Scroll.prototype.getModuleName = function () {
            return 'scroll';
        };
        Scroll.prototype.setWidth = function (uiupdate) {
            this.parent.element.style.width = ej2_base_3.formatUnit(this.parent.width);
            if (uiupdate) {
                this.widthService.setWidthToColumns();
            }
            if (this.parent.toolbarModule && this.parent.toolbarModule.toolbar &&
                this.parent.toolbarModule.toolbar.element) {
                var tlbrElement = this.parent.toolbarModule.toolbar.element;
                var tlbrLeftElement = tlbrElement.querySelector('.e-toolbar-left');
                var tlbrCenterElement = tlbrElement.querySelector('.e-toolbar-center');
                var tlbrRightElement = tlbrElement.querySelector('.e-toolbar-right');
                var tlbrItems = tlbrElement.querySelector('.e-toolbar-items');
                var tlbrLeftWidth = tlbrLeftElement ? tlbrLeftElement.clientWidth : 0;
                var tlbrCenterWidth = tlbrCenterElement ? tlbrCenterElement.clientWidth : 0;
                var tlbrRightWidth = tlbrRightElement ? tlbrRightElement.clientWidth : 0;
                var tlbrItemsWidth = tlbrItems ? tlbrItems.clientWidth : 0;
                var tlbrWidth = tlbrElement ? tlbrElement.clientWidth : 0;
                if (!this.parent.enableAdaptiveUI || tlbrLeftWidth > tlbrWidth || tlbrCenterWidth > tlbrWidth || tlbrRightWidth > tlbrWidth ||
                    tlbrItemsWidth > tlbrWidth) {
                    this.parent.toolbarModule.toolbar.refreshOverflow();
                }
            }
        };
        Scroll.prototype.setHeight = function () {
            var mHdrHeight = 0;
            var content = this.parent.getContent().querySelector('.' + literals.content);
            var height = this.parent.height;
            if (this.parent.enableColumnVirtualization && this.parent.isFrozenGrid()) {
                if (this.parent.height !== 'auto' && this.parent.height.toString().indexOf('%') < 0) {
                    height = parseInt(height, 10) - Scroll.getScrollBarWidth();
                }
                var movableScrollbarElement = this.parent.getContent().querySelector('.e-movablescrollbar');
                if (this.parent.height.toString().indexOf('%') > 0 && !ej2_base_3.isNullOrUndefined(movableScrollbarElement)) {
                    height = 'calc(' + height + ' - ' + movableScrollbarElement.scrollHeight + 'px)';
                }
            }
            if (!this.parent.enableVirtualization && this.parent.frozenRows && this.parent.height !== 'auto' &&
                this.parent.height !== '100%' && !ej2_base_3.isNullOrUndefined(this.parent.height) &&
                this.parent.height.toString().toLowerCase().indexOf('vh') === -1) {
                var tbody = this.parent.getHeaderContent()
                    .querySelector(literals.tbody + ':not(.e-masked-tbody)');
                mHdrHeight = tbody ? tbody.offsetHeight : 0;
                if (tbody && mHdrHeight) {
                    var add = tbody.getElementsByClassName(literals.addedRow).length;
                    var height_1 = add * this.parent.getRowHeight();
                    mHdrHeight -= height_1;
                }
                else Iif (!this.parent.isInitialLoad && this.parent.loadingIndicator.indicatorType === 'Shimmer'
                    && this.parent.getHeaderContent().querySelector('.e-masked-table')) {
                    height = parseInt(height, 10) - (this.parent.frozenRows * this.parent.getRowHeight());
                }
                content.style.height = ej2_base_3.formatUnit(parseInt(height, 10) - mHdrHeight);
            }
            else if (this.parent.height && this.parent.height.toString().toLowerCase().indexOf('vh') !== -1) {
                content.style.height = '100%';
            }
            else {
                content.style.height = ej2_base_3.formatUnit(height);
            }
            this.ensureOverflow(content);
            if (this.parent.isFrozenGrid()) {
                this.refresh();
            }
        };
        Scroll.prototype.setPadding = function () {
            var content = this.parent.getHeaderContent();
            var scrollWidth = Scroll.getScrollBarWidth() - this.getThreshold();
            var cssProps = this.getCssProperties();
            content.querySelector('.' + literals.headerContent).style[cssProps.border] = scrollWidth > 0 ? '1px' : '0px';
            content.style[cssProps.padding] = scrollWidth > 0 ? scrollWidth + 'px' : '0px';
        };
        Scroll.prototype.removePadding = function (rtl) {
            var cssProps = this.getCssProperties(rtl);
            var hDiv = this.parent.getHeaderContent().querySelector('.' + literals.headerContent);
            hDiv.style[cssProps.border] = '';
            hDiv.parentElement.style[cssProps.padding] = '';
            var footerDiv = this.parent.getFooterContent();
            if (footerDiv && footerDiv.classList.contains('e-footerpadding')) {
                footerDiv.classList.remove('e-footerpadding');
            }
        };
        Scroll.prototype.refresh = function () {
            if (this.parent.height === '100%' || (typeof this.parent.height === 'string' &&
                this.parent.height.toLowerCase().indexOf('vh') !== -1)) {
                var content = this.parent.getContent();
                this.parent.element.style.height = this.parent.height;
                var height = this.widthService.getSiblingsHeight(content);
                Iif (this.parent.frozenRows) {
                    height += 2;
                }
                Iif (this.parent.groupSettings && this.parent.groupSettings.columns.length === this.parent.columns.length) {
                    height += 1;
                }
                content.style.height = 'calc(100% - ' + height + 'px)';
            }
        };
        Scroll.prototype.getThreshold = function () {
            var appName = ej2_base_1.Browser.info.name;
            if (appName === 'mozilla') {
                return 0.5;
            }
            return 1 + (1 - window.devicePixelRatio);
        };
        Scroll.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(constant_1.onEmpty, this.wireEvents, this);
            this.parent.on(constant_1.contentReady, this.wireEvents, this);
            this.parent.on(constant_1.uiUpdate, this.onPropertyChanged, this);
            this.parent.on(constant_1.textWrapRefresh, this.wireEvents, this);
            this.parent.on(constant_1.headerRefreshed, this.setScrollLeft, this);
        };
        Scroll.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(constant_1.onEmpty, this.wireEvents);
            this.parent.off(constant_1.contentReady, this.wireEvents);
            this.parent.off(constant_1.uiUpdate, this.onPropertyChanged);
            this.parent.off(constant_1.textWrapRefresh, this.wireEvents);
            this.parent.off(constant_1.headerRefreshed, this.setScrollLeft);
            this.unwireEvents();
        };
        Scroll.prototype.unwireEvents = function () {
            if (this.parent.frozenRows && this.header) {
                ej2_base_1.EventHandler.remove(this.header, 'touchstart pointerdown', this.setPageXY);
                ej2_base_1.EventHandler.remove(this.header, 'touchmove pointermove', this.onTouchScroll);
            }
            var mScrollBar = this.parent.getContent() ? this.parent.getContent().querySelector('.e-movablescrollbar') : null;
            if (this.parent.isFrozenGrid() && this.parent.enableColumnVirtualization) {
                Eif (mScrollBar) {
                    ej2_base_1.EventHandler.remove(mScrollBar, 'scroll', this.onCustomScrollbarScroll);
                }
                Eif (this.content) {
                    ej2_base_1.EventHandler.remove(this.content, 'scroll', this.onCustomScrollbarScroll);
                    ej2_base_1.EventHandler.remove(this.content, 'touchstart pointerdown', this.setPageXY);
                    Eif (!(/macintosh|ipad/.test(ej2_base_1.Browser.userAgent.toLowerCase()) && ej2_base_1.Browser.isDevice)) {
                        ej2_base_1.EventHandler.remove(this.content, 'touchmove pointermove', this.onTouchScroll);
                    }
                }
                Eif (this.header) {
                    ej2_base_1.EventHandler.remove(this.header, 'scroll', this.onCustomScrollbarScroll);
                    ej2_base_1.EventHandler.remove(this.header, 'touchstart pointerdown', this.setPageXY);
                    ej2_base_1.EventHandler.remove(this.header, 'touchmove pointermove', this.onTouchScroll);
                }
            }
            if (this.content) {
                ej2_base_1.EventHandler.remove(this.content, 'scroll', this.contentScrollHandler);
            }
            if (this.header) {
                ej2_base_1.EventHandler.remove(this.header, 'scroll', this.headerScrollHandler);
            }
            this.contentScrollHandler = null;
            this.headerScrollHandler = null;
            if (this.parent.aggregates.length && this.parent.getFooterContent()) {
                ej2_base_1.EventHandler.remove(this.parent.getFooterContent().firstChild, 'scroll', this.onContentScroll);
            }
        };
        Scroll.prototype.setScrollLeft = function () {
            this.parent.getHeaderContent().querySelector('.' + literals.headerContent).scrollLeft = this.previousValues.left;
        };
        Scroll.prototype.updateFrozenShadow = function (content) {
            var gridContent = this.parent.getContent().firstElementChild;
            Iif (ej2_base_3.isNullOrUndefined(gridContent) && ej2_base_3.isNullOrUndefined(gridContent)) {
                return;
            }
            var target = content ? content : gridContent;
            var scrollLeft = this.parent.enableRtl ? Math.abs(target.scrollLeft) : target.scrollLeft;
            var isStartOfScroll = scrollLeft <= 1;
            if (this.parent.getVisibleFrozenLeftCount() && !isStartOfScroll) {
                ej2_base_2.addClass([this.parent.element], 'e-left-shadow');
            }
            else {
                ej2_base_2.removeClass([this.parent.element], 'e-left-shadow');
            }
            var scrollRight = this.parent.enableRtl ? Math.abs(target.scrollLeft) : target.scrollLeft;
            var isEndOfScroll = Math.round(scrollRight + target.clientWidth) >= target.scrollWidth - 1;
            if (this.parent.getVisibleFrozenRightCount()) {
                Iif (isEndOfScroll) {
                    ej2_base_2.removeClass([this.parent.element], 'e-right-shadow');
                }
                else {
                    ej2_base_2.addClass([this.parent.element], 'e-right-shadow');
                }
            }
            else {
                ej2_base_2.removeClass([this.parent.element], 'e-right-shadow');
            }
        };
        Scroll.prototype.onContentScroll = function (scrollTarget) {
            var _this = this;
            var element = scrollTarget;
            var isHeader = element.classList.contains(literals.headerContent);
            return function (e) {
                Iif (_this.content.querySelector(literals.tbody) === null || _this.parent.isPreventScrollEvent) {
                    return;
                }
                var target = e.target;
                if (_this.parent.frozenRows) {
                    if (_this.content.scrollTop > 0 && _this.parent.frozenRows) {
                        ej2_base_2.addClass([_this.parent.element], 'e-top-shadow');
                    }
                    else {
                        ej2_base_2.removeClass([_this.parent.element], 'e-top-shadow');
                    }
                }
                if (_this.parent.element.querySelectorAll('.e-leftfreeze,.e-fixedfreeze,.e-rightfreeze').length) {
                    var errorFreeze = _this.parent.getContent().querySelectorAll('.e-freezeerror:not([style*="display: none"])');
                    var errorFixed = _this.parent.getContent().querySelectorAll('.e-fixederror:not([style*="display: none"])');
                    _this.updateFrozenShadow(target);
                    var rows = [].slice.call(_this.parent.getContent().querySelectorAll('.e-row:not(.e-hiddenrow)'));
                    Iif (((rows.length === 1 && errorFreeze.length) ||
                        (_this.parent.element.querySelector('.e-freeze-autofill:not([style*="display: none"])')) ||
                        errorFixed.length) && target.scrollLeft !== _this.previousValues.left) {
                        target.scrollLeft = _this.previousValues.left;
                        return;
                    }
                    Iif (rows.length !== 1 && (errorFreeze.length || errorFixed.length) && target.scrollTop !== _this.previousValues.top) {
                        target.scrollTop = _this.previousValues.top;
                        return;
                    }
                }
                var left = target.scrollLeft;
                if (!ej2_base_3.isNullOrUndefined(_this.parent.infiniteScrollModule) && _this.parent.enableInfiniteScrolling && (!_this.parent.isEdit
                    || (_this.parent.editSettings.showAddNewRow && !_this.parent.element.querySelector('.e-editedrow')))) {
                    _this.parent.notify(constant_1.infiniteScrollHandler, { target: e.target, isLeft: _this.previousValues.left !== left });
                }
                if (_this.parent.groupSettings.columns.length && _this.parent.groupSettings.enableLazyLoading) {
                    var isDown = _this.previousValues.top < _this.parent.getContent().firstElementChild.scrollTop;
                    _this.parent.notify(constant_2.lazyLoadScrollHandler, { scrollDown: isDown });
                }
                _this.parent.notify(constant_1.virtualScrollEdit, {});
                var isFooter = target.classList.contains('e-summarycontent');
                if (_this.previousValues.left === left) {
                    _this.previousValues.top = !isHeader ? _this.previousValues.top : target.scrollTop;
                    return;
                }
                _this.parent.notify(constant_1.closeFilterDialog, e);
                element.scrollLeft = left;
                if (_this.parent.aggregates.length && _this.parent.enableColumnVirtualization) {
                    _this.parent.getFooterContent().querySelector('.e-summarycontent').scrollLeft = left;
                }
                Iif (isFooter) {
                    _this.header.scrollLeft = left;
                }
                _this.previousValues.left = left;
                _this.parent.notify(constant_1.scroll, { left: left });
            };
        };
        Scroll.prototype.onCustomScrollbarScroll = function (cont, hdr) {
            var _this = this;
            var content = cont;
            var header = hdr;
            return function (e) {
                Iif (_this.content.querySelector(literals.tbody) === null) {
                    return;
                }
                var target = e.target;
                var left = target.scrollLeft;
                if (_this.previousValues.left === left) {
                    return;
                }
                content.scrollLeft = left;
                header.scrollLeft = left;
                if (_this.parent.aggregates.length && _this.parent.enableColumnVirtualization) {
                    _this.parent.getFooterContent().querySelector('.e-summarycontent').scrollLeft = left;
                }
                _this.previousValues.left = left;
                _this.parent.notify(constant_1.scroll, { left: left });
                Iif (_this.parent.isDestroyed) {
                    return;
                }
            };
        };
        Scroll.prototype.onTouchScroll = function (scrollTarget) {
            var _this = this;
            var element = scrollTarget;
            return function (e) {
                if (e.pointerType === 'mouse') {
                    return;
                }
                var isFrozen = _this.parent.isFrozenGrid();
                var pageXY = _this.getPointXY(e);
                var left = element.scrollLeft + (_this.pageXY.x - pageXY.x);
                var mHdr = _this.parent.getHeaderContent().querySelector('.' + literals.headerContent);
                var mCont = _this.parent.getContent().querySelector('.' + literals.content);
                if (_this.previousValues.left === left || (left < 0 || (mHdr.scrollWidth - mHdr.clientWidth) < left)) {
                    return;
                }
                e.preventDefault();
                mHdr.scrollLeft = left;
                mCont.scrollLeft = left;
                if (isFrozen && _this.parent.enableColumnVirtualization) {
                    var scrollBar = _this.parent.getContent().querySelector('.e-movablescrollbar');
                    scrollBar.scrollLeft = left;
                }
                _this.pageXY.x = pageXY.x;
                _this.previousValues.left = left;
            };
        };
        Scroll.prototype.setPageXY = function () {
            var _this = this;
            return function (e) {
                if (e.pointerType === 'mouse') {
                    return;
                }
                _this.pageXY = _this.getPointXY(e);
            };
        };
        Scroll.prototype.getPointXY = function (e) {
            var pageXY = { x: 0, y: 0 };
            if (e.touches && e.touches.length) {
                pageXY.x = e.touches[0].pageX;
                pageXY.y = e.touches[0].pageY;
            }
            else {
                pageXY.x = e.pageX;
                pageXY.y = e.pageY;
            }
            return pageXY;
        };
        Scroll.prototype.getScrollbleParent = function (node) {
            if (node === null) {
                return null;
            }
            var parent = ej2_base_3.isNullOrUndefined(node.tagName) ? node.scrollingElement : node;
            var overflowY = document.defaultView.getComputedStyle(parent, null).overflowY;
            if (parent.scrollHeight > parent.clientHeight && overflowY !== 'hidden'
                && overflowY !== 'visible' || node.tagName === 'HTML' || node.tagName === 'BODY') {
                return node;
            }
            else {
                return this.getScrollbleParent(node.parentNode);
            }
        };
        Scroll.prototype.addStickyListener = function (isAdd) {
            this.parentElement = this.getScrollbleParent(this.parent.element.parentElement);
            if (isAdd && this.parentElement) {
                this.eventElement = this.parentElement.tagName === 'HTML' || this.parentElement.tagName === 'BODY' ? document :
                    this.parentElement;
                Iif (this.stickyScrollHandler) {
                    ej2_base_1.EventHandler.remove(this.eventElement, 'scroll', this.stickyScrollHandler);
                }
                this.stickyScrollHandler = this.makeStickyHeader();
                ej2_base_1.EventHandler.add(this.eventElement, 'scroll', this.stickyScrollHandler, this);
            }
            else if (this.eventElement) {
                ej2_base_1.EventHandler.remove(this.eventElement, 'scroll', this.stickyScrollHandler);
                this.stickyScrollHandler = null;
                this.eventElement = null;
            }
        };
        Scroll.prototype.resizeFrozenRowBorder = function () {
            var div;
            if (!this.parent.element.querySelector('.e-frozenrow-border')) {
                div = this.parent.createElement('div', { className: 'e-frozenrow-border' });
                this.parent.element.insertBefore(div, this.parent.element.querySelector('.e-gridcontent'));
            }
            else {
                div = this.parent.element.querySelector('.e-frozenrow-border');
            }
            var scrollWidth = this.parent.height !== 'auto' ? Scroll.getScrollBarWidth() : 0;
            div.style.width = (this.parent.element.offsetWidth - scrollWidth) - 0.5 + 'px';
        };
        Scroll.prototype.wireEvents = function () {
            var _this = this;
            if (this.oneTimeReady) {
                var frzCols = this.parent.isFrozenGrid();
                this.content = this.parent.getContent().querySelector('.' + literals.content);
                this.header = this.parent.getHeaderContent().querySelector('.' + literals.headerContent);
                var mScrollBar = this.parent.getContent().querySelector('.e-movablescrollbar');
                if ((this.parent.frozenRows || this.parent.isRowPinned) && this.header && this.content) {
                    ej2_base_1.EventHandler.add(this.header, 'touchstart pointerdown', this.setPageXY(), this);
                    ej2_base_1.EventHandler.add(this.header, 'touchmove pointermove', this.onTouchScroll(this.content), this);
                }
                if (frzCols && mScrollBar && this.parent.enableColumnVirtualization) {
                    ej2_base_1.EventHandler.add(mScrollBar, 'scroll', this.onCustomScrollbarScroll(this.content, this.header), this);
                    ej2_base_1.EventHandler.add(this.content, 'scroll', this.onCustomScrollbarScroll(mScrollBar, this.header), this);
                    ej2_base_1.EventHandler.add(this.header, 'scroll', this.onCustomScrollbarScroll(mScrollBar, this.content), this);
                    ej2_base_1.EventHandler.add(this.header, 'touchstart pointerdown', this.setPageXY(), this);
                    ej2_base_1.EventHandler.add(this.header, 'touchmove pointermove', this.onTouchScroll(this.content), this);
                    ej2_base_1.EventHandler.add(this.content, 'touchstart pointerdown', this.setPageXY(), this);
                    Eif (!(/macintosh|ipad/.test(ej2_base_1.Browser.userAgent.toLowerCase()) && ej2_base_1.Browser.isDevice)) {
                        ej2_base_1.EventHandler.add(this.content, 'touchmove pointermove', this.onTouchScroll(this.header), this);
                    }
                }
                this.contentScrollHandler = this.onContentScroll(this.header);
                this.headerScrollHandler = this.onContentScroll(this.content);
                ej2_base_1.EventHandler.add(this.content, 'scroll', this.contentScrollHandler, this);
                ej2_base_1.EventHandler.add(this.header, 'scroll', this.headerScrollHandler, this);
                if (this.parent.aggregates.length) {
                    ej2_base_1.EventHandler.add(this.parent.getFooterContent().firstChild, 'scroll', this.onContentScroll(this.content), this);
                }
                if (this.parent.enableStickyHeader) {
                    this.addStickyListener(true);
                }
                this.refresh();
                this.oneTimeReady = false;
            }
            var table = this.parent.getContentTable();
            var sLeft;
            var sHeight;
            var clientHeight;
            util_1.getUpdateUsingRaf(function () {
                sLeft = _this.header.scrollLeft;
                sHeight = table.scrollHeight;
                clientHeight = _this.parent.getContent().clientHeight;
            }, function () {
                var args = { cancel: false };
                _this.parent.notify(constant_2.checkScrollReset, args);
                if (sHeight < clientHeight && _this.parent.height !== 'auto') {
                    _this.setLastRowCell();
                    _this.parent.notify(constant_2.lastRowCellBorderUpdated, args);
                }
                if (_this.parent.frozenRows || _this.parent.pinnedTopRowModels.length) {
                    _this.resizeFrozenRowBorder();
                }
                if (_this.parent.element.querySelector('.e-frozenrow-border')) {
                    if ((_this.parent.pinnedTopRowModels.length || _this.parent.frozenRows) && _this.parent.currentViewData.length) {
                        _this.parent.element.querySelector('.e-frozenrow-border').classList.remove('e-frozenrow-empty');
                    }
                    else {
                        _this.parent.element.querySelector('.e-frozenrow-border').classList.add('e-frozenrow-empty');
                    }
                }
                if (!_this.parent.enableVirtualization && !_this.parent.enableInfiniteScrolling) {
                    Eif (!args.cancel) {
                        _this.header.scrollLeft = _this.previousValues.left;
                        _this.content.scrollLeft = _this.previousValues.left;
                        _this.content.scrollTop = _this.previousValues.top;
                    }
                }
                if (!_this.parent.enableColumnVirtualization) {
                    _this.content.scrollLeft = sLeft;
                    if (_this.parent.isFrozenGrid()) {
                        _this.previousValues.left = sLeft;
                    }
                }
            });
            this.parent.isPreventScrollEvent = false;
        };
        Scroll.prototype.setLastRowCell = function () {
            var table = this.parent.getContentTable();
            ej2_base_2.removeClass(table.querySelectorAll('td'), 'e-lastrowcell');
            if (table.querySelector('tr:nth-last-child(2)')) {
                Iif (this.parent.editSettings.showAddNewRow && this.parent.editSettings.newRowPosition === 'Bottom') {
                    ej2_base_2.addClass(table.querySelector('tr:nth-last-child(2)').querySelectorAll('td'), 'e-lastrowcell');
                }
            }
            ej2_base_2.addClass(table.querySelectorAll('tr:last-child td'), 'e-lastrowcell');
            if (this.parent.isSpan) {
                ej2_base_2.addClass(table.querySelectorAll('.e-row-span-lastrowcell'), 'e-lastrowcell');
            }
        };
        Scroll.prototype.getCssProperties = function (rtl) {
            var css = {};
            var enableRtl = ej2_base_3.isNullOrUndefined(rtl) ? this.parent.enableRtl : rtl;
            css.border = enableRtl ? 'borderLeftWidth' : 'borderRightWidth';
            css.padding = enableRtl ? 'paddingLeft' : 'paddingRight';
            return css;
        };
        Scroll.prototype.ensureOverflow = function (content) {
            content.style.overflowY = this.parent.height === 'auto' ? 'auto' : 'scroll';
        };
        Scroll.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            this.setPadding();
            this.oneTimeReady = true;
            if (this.parent.height === 'auto') {
                this.removePadding();
            }
            this.wireEvents();
            this.setHeight();
            var width = 'width';
            this.setWidth(!ej2_base_3.isNullOrUndefined(e.properties["" + width]));
        };
        Scroll.prototype.makeStickyHeader = function () {
            var _this = this;
            return function () {
                Eif (_this.parent.enableStickyHeader && _this.parent.element && _this.parent.getContent() && _this.parentElement) {
                    var contentRect = _this.parent.getContent().getClientRects()[0];
                    Eif (contentRect) {
                        var windowScale = window.devicePixelRatio;
                        var headerEle = _this.parent.getHeaderContent();
                        var toolbarEle = _this.parent.element.querySelector('.e-toolbar');
                        var groupHeaderEle = _this.parent.element.querySelector('.e-groupdroparea');
                        var height = headerEle.offsetHeight + (toolbarEle ? toolbarEle.offsetHeight : 0) +
                            (groupHeaderEle ? groupHeaderEle.offsetHeight : 0);
                        var parentTop = _this.parentElement.getClientRects()[0].top;
                        var top_1 = contentRect.top - (parentTop < 0 ? 0 : parentTop);
                        var left = contentRect.left;
                        var colMenuEle = document.body.querySelector('#' + _this.parent.element.id + '_columnmenu');
                        Iif (windowScale !== 1) {
                            top_1 = Math.ceil(top_1);
                        }
                        if (top_1 < height && contentRect.bottom > 0) {
                            headerEle.classList.add('e-sticky');
                            var elemTop = 0;
                            Eif (groupHeaderEle && _this.parent.groupSettings.showDropArea) {
                                _this.setSticky(groupHeaderEle, elemTop, contentRect.width, left, true);
                                elemTop += groupHeaderEle.getClientRects()[0].height;
                            }
                            Eif (toolbarEle) {
                                _this.setSticky(toolbarEle, elemTop, contentRect.width, left, true);
                                elemTop += toolbarEle.getClientRects()[0].height;
                            }
                            _this.setSticky(headerEle, elemTop, contentRect.width, left, true);
                            Iif (!ej2_base_3.isNullOrUndefined(colMenuEle)) {
                                colMenuEle.style.position = 'fixed';
                                colMenuEle.style.top = height + 'px';
                            }
                        }
                        else {
                            if (headerEle.classList.contains('e-sticky')) {
                                _this.setSticky(headerEle, null, null, null, false);
                                Eif (toolbarEle) {
                                    _this.setSticky(toolbarEle, null, null, null, false);
                                }
                                Iif (groupHeaderEle) {
                                    _this.setSticky(groupHeaderEle, null, null, null, false);
                                }
                                var ccDlg = _this.parent.element.querySelector('.e-ccdlg');
                                Iif (ccDlg) {
                                    ccDlg.classList.remove('e-sticky');
                                }
                                Iif (!ej2_base_3.isNullOrUndefined(colMenuEle)) {
                                    colMenuEle.style.position = 'absolute';
                                    var topStyle = contentRect.top - parentTop;
                                    colMenuEle.style.top = topStyle + 'px';
                                }
                            }
                        }
                        _this.parent.notify(events.stickyScrollComplete, {});
                    }
                }
            };
        };
        Scroll.prototype.setSticky = function (ele, top, width, left, isAdd) {
            if (isAdd) {
                ele.classList.add('e-sticky');
            }
            else {
                ele.classList.remove('e-sticky');
            }
            ele.style.width = width != null ? width + 'px' : '';
            ele.style.top = top != null ? top + 'px' : '';
            ele.style.left = left !== null ? parseInt(ele.style.left, 10) !== left ? left + 'px' : ele.style.left : '';
        };
        Scroll.prototype.destroy = function () {
            var gridElement = this.parent.element;
            Iif (!gridElement || (!gridElement.querySelector('.' + literals.gridHeader) && !gridElement.querySelector('.' + literals.gridContent))) {
                return;
            }
            this.removeEventListener();
            var cont = this.parent.getContent().querySelector('.' + literals.content);
            ej2_base_1.EventHandler.remove(cont, 'scroll', this.onContentScroll);
            if (this.parent.enableStickyHeader) {
                this.addStickyListener(false);
            }
            this.removePadding();
            ej2_base_2.removeClass([this.parent.getHeaderContent().querySelector('.' + literals.headerContent)], literals.headerContent);
            ej2_base_2.removeClass([cont], literals.content);
            cont.style.height = '';
            this.parent.element.style.width = '';
        };
        Scroll.getScrollBarWidth = function () {
            return util_1.getScrollBarWidth();
        };
        return Scroll;
    }());
    exports.Scroll = Scroll;
});