-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellSelector.js
141 lines (122 loc) · 3.73 KB
/
CellSelector.js
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
function absCell(cell) {
abs = parseInt(
$(cell)
.parent()
.attr('id')
);
return abs;
}
function ordCell(cell) {
return parseInt($(cell).attr('id'));
}
function valCell(cell) {
return parseInt($(cell).text());
}
function allCellsSelector() {
allCells = $(`.cells`);
return allCells;
}
function allEmptyCellsSelector() {
let emptyCells = $(`.cells`).filter((index, elt) => {
return elt.textContent === '';
});
return emptyCells;
}
function upCellSelector(Cell) {
let originCell = Cell;
let ordOriginCell = ordCell(originCell);
let absOriginCell = absCell(originCell);
let ordUpCell = ordOriginCell - 1;
let upCell = $(`#${absOriginCell}col #${ordUpCell}row`);
return upCell;
}
function downCellSelector(Cell) {
let originCell = Cell;
let ordOriginCell = ordCell(originCell);
let absOriginCell = absCell(originCell);
let ordDownCell = ordOriginCell + 1;
let downCell = $(`#${absOriginCell}col #${ordDownCell}row`);
return downCell;
}
function rightCellSelector(Cell) {
let originCell = Cell;
let ordOriginCell = ordCell(originCell);
let absOriginCell = absCell(originCell);
let absRighCell = absOriginCell + 1;
let rightCell = $(`#${absRighCell}col #${ordOriginCell}row`);
return rightCell;
}
function leftCellSelector(Cell) {
let originCell = Cell;
let ordOriginCell = ordCell(originCell);
let absOriginCell = absCell(originCell);
let absLeftCell = absOriginCell - 1;
let leftCell = $(`#${absLeftCell}col #${ordOriginCell}row`);
return leftCell;
}
function selectEmptyCellinLine(ord) {
let i = ord;
let cellsNonEmpty = $(`#${i}row.cells`).filter((index, elt) => {
return elt.textContent !== '';
});
return cellsNonEmpty;
}
function selectEmptyCellinColumn(abscisse) {
let i = abscisse;
let cellsNonEmpty = $(`#${i}col > .cells`).filter((index, elt) => {
return elt.textContent !== '';
});
return cellsNonEmpty;
}
function firstEmptyCellUp(cell) {
let activeCell = cell;
upCell = upCellSelector(activeCell);
var textUpCell = upCell.text();
let ordUpCell = ordCell(upCell);
while (textUpCell === '' && ordUpCell > 0) {
activeCell = upCellSelector(activeCell);
upCell = upCellSelector(activeCell);
ordUpCell = ordCell(upCell);
textUpCell = upCell.text();
} // end while
return activeCell;
} // end of firstEmptyCell function
function firstEmptyCellDown(cell) {
let activeCell = cell;
downCell = downCellSelector(activeCell);
var textDownCell = downCell.text();
let ordDownCell = ordCell(downCell);
while (textDownCell === '' && ordDownCell < 3) {
activeCell = downCellSelector(activeCell);
downCell = downCellSelector(activeCell);
ordDownCell = ordCell(downCell);
textDownCell = downCell.text();
} // end while
return activeCell;
} // end of firstEmptyCell function
function firstEmptyCellLeft(cell) {
let activeCell = cell;
leftCell = leftCellSelector(activeCell);
var textLeftCell = leftCell.text();
let absLeftCell = absCell(leftCell);
while (textLeftCell === '' && absLeftCell > 0) {
activeCell = leftCellSelector(activeCell);
leftCell = leftCellSelector(activeCell);
absLeftCell = absCell(leftCell);
textLeftCell = leftCell.text();
} // end while
return activeCell;
} // end of firstEmptyCell function
function firstEmptyCellRight(cell) {
let activeCell = cell;
rightCell = rightCellSelector(activeCell);
var textRightCell = rightCell.text();
let absRightCell = absCell(rightCell);
while (textRightCell === '' && absRightCell < 3) {
activeCell = rightCellSelector(activeCell);
rightCell = rightCellSelector(activeCell);
absRightCell = absCell(rightCell);
textRightCell = rightCell.text();
} // end while
return activeCell;
} // end of firstEmptyCellDown function