-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
161 lines (125 loc) · 7.57 KB
/
script.js
File metadata and controls
161 lines (125 loc) · 7.57 KB
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
var minWidth = 250;
function alignBorders(identifier, className) {
const currentBorder = document.getElementById(identifier);
const currentColumn = document.getElementsByClassName(className);
const rect = currentColumn[0].getBoundingClientRect();
if (identifier == 'columnline-five') {
const currentColumnOffsetLeft = rect.left + rect.width;
currentBorder.style.left = currentColumnOffsetLeft + 'px';
return;
}
const currentColumnOffsetLeft = rect.left;
currentBorder.style.left = currentColumnOffsetLeft + 'px';
}
window.addEventListener('load', function() {
alignBorders('columnline-one', 'table__first-column');
alignBorders('columnline-two', 'table__second-column');
alignBorders('columnline-three', 'table__third-column');
alignBorders('columnline-four', 'table__fourth-column');
alignBorders('columnline-five', 'table__fourth-column');
});
window.addEventListener('resize', function() {
alignBorders('columnline-one', 'table__first-column');
alignBorders('columnline-two', 'table__second-column');
alignBorders('columnline-three', 'table__third-column');
alignBorders('columnline-four', 'table__fourth-column');
alignBorders('columnline-five', 'table__fourth-column');
});
function hideColumnContents(className) {
const allCellsInClass = document.getElementsByClassName(className);
for (const element of allCellsInClass) {
const contentIsVisible = element.style.visibility == '' || element.style.visibility == 'visible';
if (contentIsVisible) {
element.style.visibility = 'hidden';
}
else {
element.style.visibility = 'visible';
}
}
}
function adjustWidthOfColumns(firstColumnToBeAdjusted, secondColumnToBeAdjusted, headerOfFirstColumnToBeAdjusted, headerOfSecondColumnToBeAdjusted, firstColumnToBeAdjustedWidth, secondColumnToBeAdjustedWidth) {
for (const element of firstColumnToBeAdjusted) {
element.style.width = firstColumnToBeAdjustedWidth + 'px';
}
headerOfFirstColumnToBeAdjusted.style.width = firstColumnToBeAdjustedWidth + 'px';
for (const element of secondColumnToBeAdjusted) {
element.style.width = secondColumnToBeAdjustedWidth + 'px';
}
headerOfSecondColumnToBeAdjusted.style.width = secondColumnToBeAdjustedWidth + 'px';
}
function moveTableColums(event, currentColumnline, firstColumnToBeAdjusted, secondColumnToBeAdjusted, firstHeaderToBeAdjusted, seconHeaderToBeAdjusted, firstColumnToNotBeAdjusted, secondColumnToNotBeAdjusted, firstHeaderToNotBeAdjusted, secondHeaderToNotBeAdjusted) {
var oldCurrentColumnlinePosition = currentColumnline.offsetLeft;
var firstColumnToBeAdjustedWidth = firstHeaderToBeAdjusted.offsetWidth;
var secondColumnToBeAdjustedWidth = seconHeaderToBeAdjusted.offsetWidth;
var firstColumnToNotBeAdjustedWidth = firstHeaderToNotBeAdjusted.offsetWidth;
var secondColumnToNotBeAdjustedWidth = secondHeaderToNotBeAdjusted.offsetWidth;
var oldmousePosition = event.clientX;
function onMouseMove(event) {
const newColumnlineLeft = event.clientX;
const newColumnlineLeftIsInMinWidth = newColumnlineLeft >= firstHeaderToBeAdjusted.offsetLeft + minWidth && newColumnlineLeft <= seconHeaderToBeAdjusted.offsetLeft + seconHeaderToBeAdjusted.offsetWidth - minWidth;
if (newColumnlineLeftIsInMinWidth) {
currentColumnline.style.left = newColumnlineLeft + 'px';
}
else {
document.removeEventListener('mousemove', onMouseMove);
const diffCurrentColumnline = oldCurrentColumnlinePosition - currentColumnline.offsetLeft;
let diffIsNegative = diffCurrentColumnline < 0;
if (diffIsNegative) {
firstColumnToBeAdjustedWidth = currentColumnline.offsetLeft;
secondColumnToBeAdjustedWidth = minWidth;
adjustWidthOfColumns(firstColumnToBeAdjusted, secondColumnToBeAdjusted, firstHeaderToBeAdjusted, seconHeaderToBeAdjusted, firstColumnToBeAdjustedWidth, secondColumnToBeAdjustedWidth);
adjustWidthOfColumns(firstColumnToNotBeAdjusted, secondColumnToNotBeAdjusted, firstHeaderToNotBeAdjusted, secondHeaderToNotBeAdjusted, firstColumnToNotBeAdjustedWidth, secondColumnToNotBeAdjustedWidth);
return;
}
if (!diffIsNegative) {
firstColumnToBeAdjustedWidth = minWidth;
secondColumnToBeAdjustedWidth = secondColumnToBeAdjustedWidth + diffCurrentColumnline;
adjustWidthOfColumns(firstColumnToBeAdjusted, secondColumnToBeAdjusted, firstHeaderToBeAdjusted, seconHeaderToBeAdjusted, firstColumnToBeAdjustedWidth, secondColumnToBeAdjustedWidth);
adjustWidthOfColumns(firstColumnToNotBeAdjusted, secondColumnToNotBeAdjusted, firstHeaderToNotBeAdjusted, secondHeaderToNotBeAdjusted, firstColumnToNotBeAdjustedWidth, secondColumnToNotBeAdjustedWidth);
return;
}
}
}
document.addEventListener('mousemove', onMouseMove);
currentColumnline.onmouseup = function(event) {
document.removeEventListener('mousemove', onMouseMove);
const diffMousePosition = oldmousePosition - event.clientX;
let diffIsNegative = diffMousePosition < 0;
if (diffIsNegative) {
firstColumnToBeAdjustedWidth = firstColumnToBeAdjustedWidth - diffMousePosition;
secondColumnToBeAdjustedWidth = secondColumnToBeAdjustedWidth + diffMousePosition;
adjustWidthOfColumns(firstColumnToBeAdjusted, secondColumnToBeAdjusted, firstHeaderToBeAdjusted, seconHeaderToBeAdjusted, firstColumnToBeAdjustedWidth, secondColumnToBeAdjustedWidth);
adjustWidthOfColumns(firstColumnToNotBeAdjusted, secondColumnToNotBeAdjusted, firstHeaderToNotBeAdjusted, secondHeaderToNotBeAdjusted, firstColumnToNotBeAdjustedWidth, secondColumnToNotBeAdjustedWidth);
return;
}
if (!diffIsNegative) {
firstColumnToBeAdjustedWidth = firstColumnToBeAdjustedWidth - diffMousePosition;
secondColumnToBeAdjustedWidth = secondColumnToBeAdjustedWidth + diffMousePosition;
adjustWidthOfColumns(firstColumnToBeAdjusted, secondColumnToBeAdjusted, firstHeaderToBeAdjusted, seconHeaderToBeAdjusted, firstColumnToBeAdjustedWidth, secondColumnToBeAdjustedWidth);
adjustWidthOfColumns(firstColumnToNotBeAdjusted, secondColumnToNotBeAdjusted, firstHeaderToNotBeAdjusted, secondHeaderToNotBeAdjusted, firstColumnToNotBeAdjustedWidth, secondColumnToNotBeAdjustedWidth);
return;
}
}
}
document.addEventListener('DOMContentLoaded', function() {
var columnOne = document.getElementsByClassName('table__first-column');
var columnTwo = document.getElementsByClassName('table__second-column');
var columnThree = document.getElementsByClassName('table__third-column');
var columnFour = document.getElementsByClassName('table__fourth-column');
var headerOne = document.getElementById('table__first-header');
var headerTwo = document.getElementById('table__second-header');
var headerThree = document.getElementById('table__third-header');
var headerFour = document.getElementById('table__fourth-header');
const columnlineTwo = document.getElementById('columnline-two');
const columnlineThree = document.getElementById('columnline-three');
const columnlineFour = document.getElementById('columnline-four');
columnlineTwo.onmousedown = function(event) {
moveTableColums(event, columnlineTwo, columnOne, columnTwo, headerOne, headerTwo, columnThree, columnFour, headerThree, headerFour);
}
columnlineThree.onmousedown = function(event) {
moveTableColums(event, columnlineThree, columnTwo, columnThree, headerTwo, headerThree, columnOne, columnFour, headerOne, headerFour);
}
columnlineFour.onmousedown = function(event) {
moveTableColums(event, columnlineFour, columnThree , columnFour, headerThree, headerFour, columnOne, columnTwo, headerOne, headerTwo);
}
});