-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3a46e0
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |