| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import {
- outerHeight,
- outerWidth,
- setOverlayPosition,
- resetCssTransform
- } from './../../../../helpers/dom/element';
- import Overlay from './_base';
- /**
- * @class TopLeftCornerOverlay
- */
- class TopLeftCornerOverlay extends Overlay {
- /**
- * @param {Walkontable} wotInstance
- */
- constructor(wotInstance) {
- super(wotInstance);
- this.clone = this.makeClone(Overlay.CLONE_TOP_LEFT_CORNER);
- }
- /**
- * Checks if overlay should be fully rendered
- *
- * @returns {Boolean}
- */
- shouldBeRendered() {
- return !!((this.wot.getSetting('fixedRowsTop') || this.wot.getSetting('columnHeaders').length) &&
- (this.wot.getSetting('fixedColumnsLeft') || this.wot.getSetting('rowHeaders').length));
- }
- /**
- * Updates the corner overlay position
- */
- resetFixedPosition() {
- this.updateTrimmingContainer();
- if (!this.wot.wtTable.holder.parentNode) {
- // removed from DOM
- return;
- }
- let overlayRoot = this.clone.wtTable.holder.parentNode;
- let tableHeight = outerHeight(this.clone.wtTable.TABLE);
- let tableWidth = outerWidth(this.clone.wtTable.TABLE);
- let preventOverflow = this.wot.getSetting('preventOverflow');
- if (this.trimmingContainer === window) {
- let box = this.wot.wtTable.hider.getBoundingClientRect();
- let top = Math.ceil(box.top);
- let left = Math.ceil(box.left);
- let bottom = Math.ceil(box.bottom);
- let right = Math.ceil(box.right);
- let finalLeft = '0';
- let finalTop = '0';
- if (!preventOverflow || preventOverflow === 'vertical') {
- if (left < 0 && (right - overlayRoot.offsetWidth) > 0) {
- finalLeft = `${-left}px`;
- }
- }
- if (!preventOverflow || preventOverflow === 'horizontal') {
- if (top < 0 && (bottom - overlayRoot.offsetHeight) > 0) {
- finalTop = `${-top}px`;
- }
- }
- setOverlayPosition(overlayRoot, finalLeft, finalTop);
- } else {
- resetCssTransform(overlayRoot);
- }
- overlayRoot.style.height = `${tableHeight === 0 ? tableHeight : tableHeight + 4}px`;
- overlayRoot.style.width = `${tableWidth === 0 ? tableWidth : tableWidth + 4}px`;
- }
- }
- Overlay.registerOverlay(Overlay.CLONE_TOP_LEFT_CORNER, TopLeftCornerOverlay);
- export default TopLeftCornerOverlay;
|