-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
177 lines (158 loc) · 7.07 KB
/
index.html
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, maximum-scale=0.9,user-scalable=0" name="viewport">
<title>SketchPad</title>
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" rel="stylesheet">
<link rel="stylesheet" href="./assets/css/raphael.css">
<link href="./assets/css/style.css" rel="stylesheet">
<link rel="stylesheet" href="./assets/css/pen-panel.css">
<script src="https://kit.fontawesome.com/4a4914325b.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<div id="content">
<h1>Sketch Pad</h1>
<div id="editor"></div>
</div>
<div class="draw-nav-container">
<div class="function-button-container">
<button type="button" id="editor_undo"><i class="material-icons">undo</i></button>
<button type="button" id="editor_redo"><i class="material-icons">redo</i></button>
<button type="button" id="editor_clear"><i class="fa fa-times"></i></button>
</div>
<div class="pen-picker-container">
<div id="pen-size-popup">
<div class="d-flex">
<label class="mx-3" for="pen-size-slider" id="pen-size-value">5</label>
<div>
<input type="range" class="form-control" id="pen-size-slider" min="1" max="50" value="5">
</div>
</div>
</div>
<label class="pen-radio-container">
<input class="pen-radio" id="pen-size-btn" type="radio" name="pen" value="pen" />
<span class="checkmark"></span>
<i class="fas fa-pen"></i>
</label>
</div>
<div class="color-picker-container">
<label class="radio-container ">
<input class="color-radio change-pen-color" name="color" type="radio" value="black" />
<span class="bordermark black-color"></span>
<span class="checkmark black-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="white" />
<span class="bordermark white-color"></span>
<span class="checkmark white-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="grey" />
<span class="bordermark grey-color"></span>
<span class="checkmark grey-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="green" />
<span class="bordermark green-color"></span>
<span class="checkmark green-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="red" />
<span class="bordermark red-color"></span>
<span class="checkmark red-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="pink" />
<span class="bordermark pink-color"></span>
<span class="checkmark pink-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="yellow" />
<span class="bordermark yellow-color"></span>
<span class="checkmark yellow-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="blue" />
<span class="bordermark blue-color"></span>
<span class="checkmark blue-color"></span>
</label>
<label class="radio-container">
<input class="color-radio change-pen-color" name="color" type="radio" value="purple" />
<span class="bordermark purple-color"></span>
<span class="checkmark purple-color"></span>
</label>
</div>
</div>
<script src="./assets/libs/jquery-3.6.3.min.js" type="text/javascript"></script>
<script crossorigin="anonymous" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="./assets/libs/json2.min.js"></script>
<script type="text/javascript" src="./assets/libs/raphael.js"></script>
<script type="text/javascript" src="./assets/libs/raphael.sketchpad.js"></script>
<script type="text/javascript">
jQuery.browser = {};
(function () {
jQuery.browser.msie = false;
jQuery.browser.version = 0;
if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
jQuery.browser.msie = true;
jQuery.browser.version = RegExp.$1;
}
})();
var sketchpad = Raphael.sketchpad("editor", {
width: 400,
height: 400,
editing: true
});
// When the sketchpad changes, update the input field.
sketchpad.change(function() {
$("#data").val(sketchpad.json());
});
$("#editor_clear").click(function () {
sketchpad.clear();
});
$("#editor_undo").click(function () {
sketchpad.undo();
});
$("#editor_redo").click(function() {
sketchpad.redo();
});
$('body').on('click', '.change-pen-color', (e) => {
const color = $(e.target).attr('value');
sketchpad.pen().color(color);
});
// generate colors section
const colors = [
{colorName: 'black', fontColor: 'white', bgColor: 'black'},
{colorName: 'grey', fontColor: 'white', bgColor: 'grey'},
{colorName: 'green', fontColor: 'white', bgColor: 'green'},
{colorName: 'blue', fontColor: 'white', bgColor: 'blue'},
{colorName: 'cyan', fontColor: 'white', bgColor: 'cyan'},
{colorName: 'red', fontColor: 'white', bgColor: 'red'},
{colorName: 'pink', fontColor: 'white', bgColor: 'pink'},
{colorName: 'yellow', fontColor: 'black', bgColor: 'yellow'},
]
// pen size popup
let isPopupOpen = false;
const penSizeBtn = document.getElementById('pen-size-btn');
const penSizePopup = document.querySelector('#pen-size-popup');
const penSizeSlider = document.querySelector('#pen-size-slider');
penSizeBtn.addEventListener('click', function() {
if (!isPopupOpen) {
penSizePopup.style.display = 'block';
isPopupOpen = true;
} else {
penSizePopup.style.display = 'none';
isPopupOpen = false;
}
});
penSizeSlider.addEventListener('input', function() {
// Change the pen size based on the value of the slider
const size = penSizeSlider.value
sketchpad.pen().width(size);
document.querySelector('#pen-size-value').innerText = size
});
</script>
</body>
</html>