f29643ebc712fcafd7fee3fc2c5cb1bf1fe1ecb5a26a3a8597347778519783044884522f685adc77e3545b22898aa1262bba0fa7a3fd126402806344d7a7f6 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {
  2. outerHeight,
  3. outerWidth,
  4. setOverlayPosition,
  5. resetCssTransform
  6. } from './../../../../helpers/dom/element';
  7. import Overlay from './_base';
  8. /**
  9. * @class TopLeftCornerOverlay
  10. */
  11. class TopLeftCornerOverlay extends Overlay {
  12. /**
  13. * @param {Walkontable} wotInstance
  14. */
  15. constructor(wotInstance) {
  16. super(wotInstance);
  17. this.clone = this.makeClone(Overlay.CLONE_TOP_LEFT_CORNER);
  18. }
  19. /**
  20. * Checks if overlay should be fully rendered
  21. *
  22. * @returns {Boolean}
  23. */
  24. shouldBeRendered() {
  25. return !!((this.wot.getSetting('fixedRowsTop') || this.wot.getSetting('columnHeaders').length) &&
  26. (this.wot.getSetting('fixedColumnsLeft') || this.wot.getSetting('rowHeaders').length));
  27. }
  28. /**
  29. * Updates the corner overlay position
  30. */
  31. resetFixedPosition() {
  32. this.updateTrimmingContainer();
  33. if (!this.wot.wtTable.holder.parentNode) {
  34. // removed from DOM
  35. return;
  36. }
  37. let overlayRoot = this.clone.wtTable.holder.parentNode;
  38. let tableHeight = outerHeight(this.clone.wtTable.TABLE);
  39. let tableWidth = outerWidth(this.clone.wtTable.TABLE);
  40. let preventOverflow = this.wot.getSetting('preventOverflow');
  41. if (this.trimmingContainer === window) {
  42. let box = this.wot.wtTable.hider.getBoundingClientRect();
  43. let top = Math.ceil(box.top);
  44. let left = Math.ceil(box.left);
  45. let bottom = Math.ceil(box.bottom);
  46. let right = Math.ceil(box.right);
  47. let finalLeft = '0';
  48. let finalTop = '0';
  49. if (!preventOverflow || preventOverflow === 'vertical') {
  50. if (left < 0 && (right - overlayRoot.offsetWidth) > 0) {
  51. finalLeft = `${-left}px`;
  52. }
  53. }
  54. if (!preventOverflow || preventOverflow === 'horizontal') {
  55. if (top < 0 && (bottom - overlayRoot.offsetHeight) > 0) {
  56. finalTop = `${-top}px`;
  57. }
  58. }
  59. setOverlayPosition(overlayRoot, finalLeft, finalTop);
  60. } else {
  61. resetCssTransform(overlayRoot);
  62. }
  63. overlayRoot.style.height = `${tableHeight === 0 ? tableHeight : tableHeight + 4}px`;
  64. overlayRoot.style.width = `${tableWidth === 0 ? tableWidth : tableWidth + 4}px`;
  65. }
  66. }
  67. Overlay.registerOverlay(Overlay.CLONE_TOP_LEFT_CORNER, TopLeftCornerOverlay);
  68. export default TopLeftCornerOverlay;