about summary refs log tree commit diff stats
path: root/js/inknswitch
diff options
context:
space:
mode:
Diffstat (limited to 'js/inknswitch')
-rw-r--r--js/inknswitch/index.html13
-rw-r--r--js/inknswitch/ink.js48
2 files changed, 45 insertions, 16 deletions
diff --git a/js/inknswitch/index.html b/js/inknswitch/index.html
index 91f9ff2..535c41d 100644
--- a/js/inknswitch/index.html
+++ b/js/inknswitch/index.html
@@ -27,9 +27,22 @@
             margin: 0 auto;
             display: block;
         }
+        #toggleButton {
+            border: 1px solid black;
+            background-color: transparent;
+            padding: 0.5em 1em;
+            position: fixed;
+            top: 10px;
+            right: 10px;
+            z-index: 1000;
+        }
+        #toggleButton:hover {
+            cursor: pointer;
+        }
     </style>
 </head>
 <body>
+    <button id="toggleButton">Toggle</button>
     <textarea id="noteArea" rows="10" cols="30" placeholder="This is a modal note taking tool. With it, you can type text that'll be saved to the browser, and you can draw images that'll also be saved to the browser. You are in typing mode right now. To toggle between modes tap cmd or ctrl + d. When in drawing mode, tap c to clear the canvas, tap s to save the contents of the canvas to a png."></textarea>
     <canvas id="drawingArea" width="500" height="500"></canvas>
     <script src="ink.js"></script>
diff --git a/js/inknswitch/ink.js b/js/inknswitch/ink.js
index bd5fb6d..58b923b 100644
--- a/js/inknswitch/ink.js
+++ b/js/inknswitch/ink.js
@@ -1,7 +1,7 @@
 const canvas = document.getElementById('drawingArea');
 const ctx = canvas.getContext('2d');
-const noteArea = document.getElementById('noteArea');
 
+const noteArea = document.getElementById('noteArea');
 noteArea.value = localStorage.getItem('noteContent') || '';
 
 noteArea.style.width = '100vw';
@@ -20,7 +20,7 @@ let drawing = false;
 let prevX = 0;
 let prevY = 0;
 
-canvas.style.pointerEvents = 'none'; // Disable mouse events on the canvas
+canvas.style.pointerEvents = 'none';
 
 const getCursorPosition = (e) => {
     const rect = canvas.getBoundingClientRect();
@@ -62,13 +62,11 @@ const saveCanvasImage = () => {
 };
 
 canvas.addEventListener('mousedown', startDrawing);
-
 canvas.addEventListener('mousemove', (e) => {
     if (drawing) {
         draw(e);
     }
 });
-
 canvas.addEventListener('mouseup', (e) => {
     if (drawing) {
         draw(e);
@@ -86,22 +84,40 @@ if (savedImage) {
     img.src = savedImage;
 }
 
+// Toggle between drawing and note mode
+const toggle = () => {
+    if (canvas.style.pointerEvents === 'none') {
+        // Drawing mode
+        canvas.style.pointerEvents = 'auto';
+        noteArea.style.pointerEvents = 'none';
+        noteArea.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
+        noteArea.style.color = '#bbb';
+        canvas.style.cursor = 'pointer';
+        toggleButton.textContent = 'Write'
+    } else {
+        // Note mode
+        canvas.style.pointerEvents = 'none';
+        noteArea.style.pointerEvents = 'auto';
+        noteArea.style.backgroundColor = 'rgba(255, 255, 255, 0.75)';
+        noteArea.style.color = 'black';
+        toggleButton.textContent = 'Draw'
+    }
+};
+
+const toggleButton = document.getElementById('toggleButton');
+toggleButton.style.pointerEvents = 'auto';
+toggleButton.addEventListener('click', toggleMode);
+toggleButton.addEventListener('touchend', toggleMode);
+
+function toggleMode() {
+    toggle();
+}
+
 document.addEventListener('keydown', (e) => {
     // Cmd or Ctrl and D key to toggle modes
     if ((e.metaKey || e.ctrlKey) && e.key === 'd') {
         e.preventDefault();
-        if (canvas.style.pointerEvents === 'none') {
-            canvas.style.pointerEvents = 'auto';
-            noteArea.style.pointerEvents = 'none';
-            noteArea.style.backgroundColor = 'rgba(255, 255, 255, 0.25)';
-            noteArea.style.color = '#bbb';
-            canvas.style.cursor = 'pointer';
-        } else {
-            canvas.style.pointerEvents = 'none';
-            noteArea.style.pointerEvents = 'auto';
-            noteArea.style.backgroundColor = 'rgba(255, 255, 255, 0.75)';
-            noteArea.style.color = 'black';
-        }
+        toggle();
     }
 
     // C key to clear the canvas
href='#n308'>308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
tik/mu/blame/082persist.cc?h=hlt&id=8d9edfd6223d0f374404067eadc62171f915b76b'>^
fc4a98dc ^

13ba3def ^
35064671 ^
13ba3def ^

5aa38b52 ^





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