Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
meghanakr7 committed Jun 30, 2024
0 parents commit a3a46e0
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
28 changes: 28 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Online Notepad</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div class="container">
<h1>Online Notepad</h1>
<div class="toolbar">
<button onclick="formatText('bold')"><i class="fas fa-bold"></i></button>
<button onclick="formatText('italic')"><i class="fas fa-italic"></i></button>
<button onclick="formatText('underline')"><i class="fas fa-underline"></i></button>
<button onclick="formatText('justifyLeft')"><i class="fas fa-align-left"></i></button>
<button onclick="formatText('justifyCenter')"><i class="fas fa-align-center"></i></button>
<button onclick="formatText('justifyRight')"><i class="fas fa-align-right"></i></button>
<button onclick="formatText('insertUnorderedList')"><i class="fas fa-list-ul"></i></button>
<button onclick="formatText('insertOrderedList')"><i class="fas fa-list-ol"></i></button>
<button onclick="insertCheckbox()"><i class="fas fa-check-square"></i></button>
</div>
<div id="notepad" contenteditable="true" placeholder="Start typing..."></div>
</div>
<script src="script.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
document.addEventListener("DOMContentLoaded", (event) => {
const notepad = document.getElementById("notepad");

// Load saved content from localStorage
if (localStorage.getItem("notepadContent")) {
notepad.innerHTML = localStorage.getItem("notepadContent");
}

// Save content to localStorage on input
notepad.addEventListener("input", () => {
localStorage.setItem("notepadContent", notepad.innerHTML);
});
});

// Function to format the selected text
function formatText(command) {
document.execCommand(command, false, null);
}

// Function to insert a checkbox at the caret position
function insertCheckbox() {
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.style.marginRight = "5px";
insertNodeAtCaret(checkbox);
}

// Helper function to insert a node at the caret position
function insertNodeAtCaret(node) {
let sel = window.getSelection();
if (sel.rangeCount) {
let range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(node);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
}
}
13 changes: 13 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
document.addEventListener('DOMContentLoaded', (event) => {
const notepad = document.getElementById('notepad');

// Load saved content from localStorage
if (localStorage.getItem('notepadContent')) {
notepad.value = localStorage.getItem('notepadContent');
}

// Save content to localStorage on input
notepad.addEventListener('input', () => {
localStorage.setItem('notepadContent', notepad.value);
});
});
72 changes: 72 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
body {
font-family: "Helvetica Neue", Arial, sans-serif;
background-color: #f0f4f8;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
width: 80%;
max-width: 900px;
margin: 20px auto;
padding: 20px;
background: #ffffff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 10px;
}

h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
font-size: 2em;
}

.toolbar {
display: flex;
justify-content: center;
margin-bottom: 10px;
}

.toolbar button {
margin: 0 5px;
padding: 10px;
font-size: 16px;
cursor: pointer;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
transition: background-color 0.3s ease;
}

.toolbar button:hover {
background-color: #0056b3;
}

.toolbar button i {
pointer-events: none;
}

#notepad {
width: 100%;
height: 600px;
padding: 20px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
overflow-y: auto;
white-space: pre-wrap;
background-color: #fdfdfd;
color: #333;
}

#notepad:empty:before {
content: attr(placeholder);
color: #999;
}

0 comments on commit a3a46e0

Please sign in to comment.