Skip to content

Commit

Permalink
Added colorPicker input(for any color)
Browse files Browse the repository at this point in the history
- Added clear canvas tool
  • Loading branch information
souravtecken committed Mar 26, 2020
1 parent b8bcf63 commit 2f4b682
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
10 changes: 10 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ canvas {

#colorPalette {
padding: 0 !important;
}

.colorOption .rainbow {
background-image: linear-gradient( red,orange,yellow,green,blue,indigo,violet);
}

#colorPicker {
border: none;
background-color: transparent;
outline: none;
}
11 changes: 6 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

<body>
<div id="toolBarContainer" class="ui mini left fixed vertical menu">
<div class="toolButtonBox">
<div id="pencilTool" class="toolButtonBox">
<button class="toolButton">
<i class="pencil icon"></i>
</button>
</div>
<div class="toolButtonBox">
<div id="brushTool" class="toolButtonBox">
<button class="toolButton">
<i class="paint brush icon"></i>
</button>
</div>
<div class="ui left pointing dropdown link toolButtonBox">
<div id="colorPaletteTool" class="ui left pointing dropdown link toolButtonBox">
<div class="menu">
<div id="colorPalette" class="item">
<table class="ui very basic collapsing celled table">
Expand Down Expand Up @@ -53,6 +53,7 @@
</tr>
<tr>
<td class="colorOption"><div class="ui black empty circular big label"></div></td>
<td class="colorOption"><div class="ui rainbow empty circular big label"><input id="colorPicker" type="color"/></div></td>
</tr>
</tbody>
</table>
Expand All @@ -63,12 +64,12 @@
</button>
</div>

<div class="toolButtonBox">
<div id="eraserTool" class="toolButtonBox">
<button class="toolButton">
<i class="eraser icon"></i>
</button>
</div>
<div class="toolButtonBox">
<div id="clearTool" class="toolButtonBox">
<button class="toolButton">
<i class="trash icon"></i>
</button>
Expand Down
24 changes: 21 additions & 3 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,34 @@ function initToolBox(){
.dropdown();
}

$(".colorOption").click((event) => {
$('.colorOption').click((event) => {
event.stopPropagation(); // To prevent dropdown from closing
const child = event.target.querySelector('div');
const colorPicker = event.target.querySelector('input');
if (colorPicker !== null){
$(colorPicker).click();
return;
}
let color;
if(child === null)
color = window.getComputedStyle(event.target, null).getPropertyValue("background-color");
color = window.getComputedStyle(event.target, null).getPropertyValue('background-color');
else
color = window.getComputedStyle(event.target.querySelector('div'), null).getPropertyValue("background-color");
color = window.getComputedStyle(event.target.querySelector('div'), null).getPropertyValue('background-color');
setStrokeColor(ctx, color);
setFillColor(ctx, color);
$('#colorPaletteTool button').css('color', color);
});

$('#colorPicker').on('input', ((event) => {
const color = event.target.value;
setStrokeColor(ctx, color);
setFillColor(ctx, color);
$('#colorPaletteTool button').css('color', color);
}))

$('#clearTool').click((event) => {
initCanvas(ctx);
})

initCanvas(ctx);
initToolBox();

0 comments on commit 2f4b682

Please sign in to comment.