Add a grid toggle feature
This commit is contained in:
parent
8b3dd05a45
commit
0a042915a5
45
canvas.js
45
canvas.js
@ -8,6 +8,21 @@ var customColorToolbar=false;
|
|||||||
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded",()=>{
|
document.addEventListener("DOMContentLoaded",()=>{
|
||||||
|
|
||||||
|
class Coordinate{
|
||||||
|
constructor(box) {
|
||||||
|
var idParse=box.id.split("_");
|
||||||
|
this.x = idParse[1];
|
||||||
|
this.y = idParse[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PixelCoordinate extends Coordinate{
|
||||||
|
constructor(x,y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function insertAfter(newNode, existingNode) {
|
function insertAfter(newNode, existingNode) {
|
||||||
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
|
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
|
||||||
}
|
}
|
||||||
@ -37,6 +52,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
var MouseStateUp = (e)=>{
|
var MouseStateUp = (e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
mouseState = -1;
|
mouseState = -1;
|
||||||
|
toolbar.style.visibility = "visible";
|
||||||
}
|
}
|
||||||
var MouseStateDown = (e)=>{
|
var MouseStateDown = (e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -48,6 +64,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
e.target.style.background="white";
|
e.target.style.background="white";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
toolbar.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
var colorPixelBasedOnID = (x,y,color)=>{
|
var colorPixelBasedOnID = (x,y,color)=>{
|
||||||
@ -57,6 +74,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
|
|
||||||
var generateTable = (columns,rows)=>{
|
var generateTable = (columns,rows)=>{
|
||||||
var table = document.createElement("table");
|
var table = document.createElement("table");
|
||||||
|
table.style.border="1px gray dashed";
|
||||||
for (var i=0;i<rows;i++) {
|
for (var i=0;i<rows;i++) {
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
for (var j=0;j<columns;j++) {
|
for (var j=0;j<columns;j++) {
|
||||||
@ -147,6 +165,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
for (var i=0;i<COLS;i++){
|
for (var i=0;i<COLS;i++){
|
||||||
var col = document.createElement("th");
|
var col = document.createElement("th");
|
||||||
col.style.background="white";
|
col.style.background="white";
|
||||||
|
col.style.border=document.querySelector("table").style.border;
|
||||||
col.id="pos_"+i+"_"+(Number(ROWS)+Number(newcells));
|
col.id="pos_"+i+"_"+(Number(ROWS)+Number(newcells));
|
||||||
newrow.appendChild(col);
|
newrow.appendChild(col);
|
||||||
}
|
}
|
||||||
@ -173,6 +192,7 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
var row = table.getElementsByTagName("tr")[i]
|
var row = table.getElementsByTagName("tr")[i]
|
||||||
var col = document.createElement("th");
|
var col = document.createElement("th");
|
||||||
col.style.background="white";
|
col.style.background="white";
|
||||||
|
col.style.border=document.querySelector("table").style.border;
|
||||||
col.id="pos_"+COLS+"_"+i;
|
col.id="pos_"+COLS+"_"+i;
|
||||||
row.appendChild(col);
|
row.appendChild(col);
|
||||||
}
|
}
|
||||||
@ -288,6 +308,31 @@ document.addEventListener("DOMContentLoaded",()=>{
|
|||||||
saveButton.addEventListener("click",SaveData)
|
saveButton.addEventListener("click",SaveData)
|
||||||
toolbar.appendChild(loadButton);
|
toolbar.appendChild(loadButton);
|
||||||
toolbar.appendChild(saveButton);
|
toolbar.appendChild(saveButton);
|
||||||
|
var toggleGridButton = document.createElement("img");
|
||||||
|
toggleGridButton.src = "gridtoggle.png";
|
||||||
|
toggleGridButton.classList.add("tinybutton");
|
||||||
|
toggleGridButton.addEventListener("click",()=>{
|
||||||
|
var elements = document.querySelectorAll("table,tr,th")
|
||||||
|
if (document.querySelector("body > div.container > div > table").style.border.includes("1px")) {
|
||||||
|
for (var item of elements) {
|
||||||
|
item.style.border = "0px";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var item of elements) {
|
||||||
|
item.style.border = "1px gray dashed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
toolbar.appendChild(toggleGridButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns a coordinate class.
|
||||||
|
var getCoordinates = (box)=>{
|
||||||
|
return new Coordinate(box);
|
||||||
|
}
|
||||||
|
|
||||||
|
var floodFill = (startx,starty)=>{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generateTable(ROWS,COLS);
|
generateTable(ROWS,COLS);
|
||||||
|
BIN
filltool.png
Normal file
BIN
filltool.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
gridtoggle.png
Normal file
BIN
gridtoggle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
17
style.css
17
style.css
@ -1,4 +1,4 @@
|
|||||||
table,td,th{
|
table,tr,th{
|
||||||
border:1px gray dashed;
|
border:1px gray dashed;
|
||||||
border-spacing:0px;
|
border-spacing:0px;
|
||||||
gap:0px;
|
gap:0px;
|
||||||
@ -12,6 +12,9 @@ th{
|
|||||||
.container{
|
.container{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
.toolbar{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
.canvas{
|
.canvas{
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
background-color: #EEEEFF;
|
background-color: #EEEEFF;
|
||||||
@ -53,3 +56,15 @@ th{
|
|||||||
border:2px black solid;
|
border:2px black solid;
|
||||||
margin-left:1px;
|
margin-left:1px;
|
||||||
}
|
}
|
||||||
|
.tinybutton{
|
||||||
|
margin-top:-24px;
|
||||||
|
position:relative;
|
||||||
|
top: 6px;
|
||||||
|
height: 24px;
|
||||||
|
width: 24px;
|
||||||
|
background-color: #bbb;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: inline-block;
|
||||||
|
border:2px black solid;
|
||||||
|
margin-left:1px;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user