Compare commits

..

1 commit

Author SHA1 Message Date
42aa1f980c add testing files 2024-09-13 00:10:38 -07:00
7 changed files with 1643 additions and 203 deletions

View file

@ -1,4 +1,4 @@
# notepad # notepad
a notepad webapp made in one html file a notepad webapp made in one html file
visit at [rintyuu.dev/notepad](https://rintyuu.dev/notepad) visit at [dev, uk/notepad](https://rintyuu.dev/notepad)

302
custom-background.html Normal file
View file

@ -0,0 +1,302 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title>
<style>
body {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.window {
position: absolute;
border: 1px solid #ccc;
background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.title-bar {
background-color: #f0f0f0;
padding: 5px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
}
.title-bar div {
margin-left: 8px;
}
.close-btn {
cursor: pointer;
margin-left: 5px;
}
.minimize-btn {
cursor: pointer;
margin-left: 5px;
}
.text-area {
width: 300px;
height: 200px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100px;
z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content button {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
border: none;
background: none;
width: 100%;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.top-left {
top: 5px;
left: 5px;
}
</style>
</head>
<body>
<button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" onclick="showHelp()">Help</button>
<label class="top-left" for="background-upload">Change Background</label>
<input type="file" id="background-upload" accept="image/png" onchange="changeBackground()">
<script>
let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() {
const notepadWindow = document.createElement('div');
notepadWindow.className = 'window';
notepadWindow.style.left = '50px';
notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const fileDropdown = document.createElement('div');
fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
newButton.textContent = 'New...';
newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.onclick = function() {
saveText(notepadWindow);
};
const openButton = document.createElement('button');
openButton.textContent = 'Open';
openButton.onclick = function() {
openFile(notepadWindow);
};
const embedButton = document.createElement('button');
embedButton.textContent = 'Embed HTML';
embedButton.onclick = function() {
embedHTML(notepadWindow);
};
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(embedButton);
fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement('div');
titleText.textContent = 'Notepad';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
const minimizeButton = document.createElement('button');
minimizeButton.className = 'minimize-btn';
minimizeButton.innerHTML = '-';
minimizeButton.onclick = function() {
toggleMinimize(notepadWindow);
};
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
titleBar.appendChild(fileDropdown);
titleBar.appendChild(titleText);
titleBar.appendChild(minimizeButton);
titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement('textarea');
textArea.className = 'text-area';
notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea);
document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow);
// Bring the window to front when clicked
notepadWindow.onclick = function() {
bringToFront(notepadWindow);
};
}
function toggleMinimize(notepadWindow) {
const content = notepadWindow.querySelectorAll('.text-area, div[embedded-content]');
content.forEach((item) => {
if (item.style.display === 'none') {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
function embedHTML(notepadWindow) {
const embedCode = prompt('Paste your embed HTML code here:');
if (embedCode) {
const textArea = notepadWindow.querySelector('.text-area');
textArea.style.display = 'none'; // Hide the text area
let embedContainer = notepadWindow.querySelector('[embedded-content]');
if (!embedContainer) {
embedContainer = document.createElement('div');
embedContainer.setAttribute('embedded-content', '');
notepadWindow.appendChild(embedContainer); // Create and append new embed container
}
embedContainer.innerHTML = embedCode; // Embed the HTML content
}
}
// Function to make an element draggable
function makeDraggable(dragHandle, element) {
let offsetX, offsetY;
dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener('mousemove', dragElement);
document.addEventListener('mouseup', stopDragging);
});
function dragElement(event) {
element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = (event.clientY - offsetY) + 'px';
}
function stopDragging() {
document.removeEventListener('mousemove', dragElement);
document.removeEventListener('mouseup', stopDragging);
}
}
// Function to bring a window to the front
function bringToFront(window) {
window.style.zIndex = zIndexCounter++;
}
// Function to change the background image
function changeBackground() {
const fileInput = document.getElementById('background-upload');
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
document.body.style.backgroundImage = `url(${e.target.result})`;
};
if (file) {
reader.readAsDataURL(file);
}
}
function showHelp() {
const helpWindow = document.createElement('div');
helpWindow.className = 'window';
helpWindow.style.left = '100px';
helpWindow.style.top = '100px';
helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.textContent = 'Help';
titleBar.draggable = true;
const closeButton = document.createElement('button');
closeButton.className = 'close-btn';
closeButton.innerHTML = 'X';
closeButton.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow);
};
titleBar.appendChild(closeButton);
const helpContent = document.createElement('div');
helpContent.innerHTML = '<p>This is a simple Notepad application.</p>';
helpWindow.appendChild(titleBar);
helpWindow.appendChild(helpContent);
document.body.appendChild(helpWindow);
makeDraggable(titleBar, helpWindow);
helpWindow.onclick = function() {
bringToFront(helpWindow);
};
}
</script>
</body>
</html>

265
embed-revision.html Normal file
View file

@ -0,0 +1,265 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title>
<style>
.window {
position: absolute;
border: 1px solid #ccc;
background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.title-bar {
background-color: #f0f0f0;
padding: 5px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
}
.title-bar div {
margin-left: 8px; /* Padding between title and buttons */
}
.close-btn {
cursor: pointer;
margin-left: 5px;
}
.minimize-btn {
cursor: pointer;
margin-left: 5px;
}
.text-area {
width: 300px;
height: 200px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100px;
z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content button {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
border: none;
background: none;
width: 100%;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.top-left {
top: 5px;
left: 5px;
}
</style>
</head>
<body>
<button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" onclick="showHelp()">Help</button>
<script>
let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() {
const notepadWindow = document.createElement('div');
notepadWindow.className = 'window';
notepadWindow.style.left = '50px';
notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const fileDropdown = document.createElement('div');
fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
newButton.textContent = 'New...';
newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.onclick = function() {
saveText(notepadWindow);
};
const openButton = document.createElement('button');
openButton.textContent = 'Open';
openButton.onclick = function() {
openFile(notepadWindow);
};
const embedButton = document.createElement('button');
embedButton.textContent = 'Embed HTML';
embedButton.onclick = function() {
embedHTML(notepadWindow);
};
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(embedButton);
fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement('div');
titleText.textContent = 'Notepad';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
const minimizeButton = document.createElement('button');
minimizeButton.className = 'minimize-btn';
minimizeButton.innerHTML = '-';
minimizeButton.onclick = function() {
toggleMinimize(notepadWindow);
};
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
titleBar.appendChild(fileDropdown);
titleBar.appendChild(titleText);
titleBar.appendChild(minimizeButton);
titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement('textarea');
textArea.className = 'text-area';
notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea);
document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow);
}
function toggleMinimize(notepadWindow) {
const content = notepadWindow.querySelectorAll('.text-area, div[embedded-content]');
content.forEach((item) => {
if (item.style.display === 'none') {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
function embedHTML(notepadWindow) {
const embedCode = prompt('Paste your embed HTML code here:');
if (embedCode) {
const textArea = notepadWindow.querySelector('.text-area');
textArea.style.display = 'none'; // Hide the text area
let embedContainer = notepadWindow.querySelector('[embedded-content]');
if (!embedContainer) {
embedContainer = document.createElement('div');
embedContainer.setAttribute('embedded-content', '');
notepadWindow.appendChild(embedContainer); // Create and append new embed container
}
embedContainer.innerHTML = embedCode; // Embed the HTML content
}
}
// Function to make an element draggable
function makeDraggable(dragHandle, element) {
let offsetX, offsetY;
dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener('mousemove', dragElement);
document.addEventListener('mouseup', stopDragging);
});
function dragElement(event) {
element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = (event.clientY - offsetY) + 'px';
}
function stopDragging() {
document.removeEventListener('mousemove', dragElement);
document.removeEventListener('mouseup', stopDragging);
}
}
function showHelp() {
const helpWindow = document.createElement('div');
helpWindow.className = 'window';
helpWindow.style.left = '100px';
helpWindow.style.top = '100px';
helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.textContent = 'Help';
titleBar.draggable = true;
const closeButton = document.createElement('button');
closeButton.className = 'close-btn';
closeButton.innerHTML = 'X';
closeButton.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow);
};
titleBar.appendChild(closeButton);
const helpContent = document.createElement('div');
helpContent.innerHTML = '<p>This is a simple Notepad application.</p>';
helpWindow.appendChild(titleBar);
helpWindow.appendChild(helpContent);
document.body.appendChild(helpWindow);
makeDraggable(titleBar, helpWindow);
}
</script>
</body>
</html>

View file

@ -1,15 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title> <title>Notepad</title>
<style> <style>
/* Styles for draggable windows */
.window { .window {
position: absolute; position: absolute;
border: 1px solid #ccc; border: 1px solid #ccc;
background-color: #fff; background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); /* Drop shadow */
} }
.title-bar { .title-bar {
background-color: #f0f0f0; background-color: #f0f0f0;
@ -29,12 +30,6 @@
width: 300px; width: 300px;
height: 200px; height: 200px;
} }
.embed-area {
width: 100%;
height: 100%;
border: none;
display: none;
}
.dropdown { .dropdown {
position: relative; position: relative;
display: inline-block; display: inline-block;
@ -45,7 +40,7 @@
background-color: #f9f9f9; background-color: #f9f9f9;
min-width: 100px; min-width: 100px;
z-index: 1; z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); /* Drop shadow */
} }
.dropdown-content button { .dropdown-content button {
color: black; color: black;
@ -61,111 +56,97 @@
.dropdown:hover .dropdown-content { .dropdown:hover .dropdown-content {
display: block; display: block;
} }
</style> .top-left {
</head> /* position: absolute; */
<body> top: 5px;
<button onclick="createNewNotepad()">New...</button> left: 5px;
<button onclick="showHelp()">Help</button> }
</style>
</head>
<body>
<script> <button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" href="#" onclick="showHelp()">Help</button>
<script>
let zIndexCounter = 1; let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() { function createNewNotepad() {
const notepadWindow = document.createElement("div"); const notepadWindow = document.createElement('div');
notepadWindow.className = "window"; notepadWindow.className = 'window';
notepadWindow.style.left = "50px"; notepadWindow.style.left = '50px';
notepadWindow.style.top = "50px"; notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++; notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement("div"); const titleBar = document.createElement('div');
titleBar.className = "title-bar"; titleBar.className = 'title-bar';
titleBar.draggable = true; titleBar.draggable = true;
const fileDropdown = document.createElement("div"); const fileDropdown = document.createElement('div');
fileDropdown.className = "dropdown"; fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement("button"); const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = "File"; fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement("div"); const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = "dropdown-content"; fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
const newButton = document.createElement("button"); newButton.textContent = 'New...';
newButton.textContent = "New...";
newButton.onclick = createNewNotepad; newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
const saveButton = document.createElement("button"); saveButton.textContent = 'Save';
saveButton.textContent = "Save"; saveButton.onclick = function() {
saveButton.onclick = function () {
saveText(notepadWindow); saveText(notepadWindow);
}; };
const openButton = document.createElement('button');
const openButton = document.createElement("button"); openButton.textContent = 'Open';
openButton.textContent = "Open"; openButton.onclick = function() {
openButton.onclick = function () {
openFile(notepadWindow); openFile(notepadWindow);
}; };
const renameButton = document.createElement('button');
const renameButton = document.createElement("button"); renameButton.textContent = 'Rename';
renameButton.textContent = "Rename"; renameButton.onclick = function() {
renameButton.onclick = function () { const newTitle = prompt('Enter new title:');
const newTitle = prompt("Enter new title:");
if (newTitle !== null) { if (newTitle !== null) {
titleText.textContent = newTitle; titleText.textContent = newTitle;
} }
}; };
const closeButton = document.createElement('button');
const embedButton = document.createElement("button"); closeButton.textContent = 'Close';
embedButton.textContent = "Embed"; closeButton.onclick = function() {
embedButton.onclick = function () { if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const embedCode = prompt("Enter embed HTML (e.g., iframe):"); const confirmClose = confirm('Are you sure you want to close this notepad?');
if (embedCode) {
replaceWithEmbed(notepadWindow, embedCode);
}
};
const closeButton = document.createElement("button");
closeButton.textContent = "Close";
closeButton.onclick = function () {
const textArea = notepadWindow.querySelector(".text-area");
if (textArea.value.trim() === "") {
notepadWindow.parentNode.removeChild(notepadWindow);
} else {
const confirmClose = confirm(
"Are you sure you want to close this notepad?"
);
if (confirmClose) { if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow); notepadWindow.parentNode.removeChild(notepadWindow);
} }
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
} }
}; };
fileDropdownContent.appendChild(newButton); fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton); fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton); fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(renameButton); fileDropdownContent.appendChild(renameButton);
fileDropdownContent.appendChild(embedButton);
fileDropdownContent.appendChild(closeButton); fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton); fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent); fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement("div"); const titleText = document.createElement('div');
titleText.textContent = "Notepad"; titleText.textContent = 'Notepad';
titleText.style.textAlign = "center"; titleText.style.textAlign = 'center';
titleText.style.flexGrow = "1"; titleText.style.flexGrow = '1';
const closeButtonTitle = document.createElement("button"); const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = "close-btn"; closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = "X"; closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function () { closeButtonTitle.onclick = function() {
const textArea = notepadWindow.querySelector(".text-area"); if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
if (textArea.value.trim() === "") { const confirmClose = confirm('Are you sure you want to close this notepad?');
notepadWindow.parentNode.removeChild(notepadWindow);
} else {
const confirmClose = confirm(
"Are you sure you want to close this?"
);
if (confirmClose) { if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow); notepadWindow.parentNode.removeChild(notepadWindow);
} }
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
} }
}; };
@ -173,126 +154,110 @@
titleBar.appendChild(titleText); titleBar.appendChild(titleText);
titleBar.appendChild(closeButtonTitle); titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement("textarea"); const textArea = document.createElement('textarea');
textArea.className = "text-area"; textArea.className = 'text-area';
const embedArea = document.createElement("div");
embedArea.className = "embed-area";
notepadWindow.appendChild(titleBar); notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea); notepadWindow.appendChild(textArea);
notepadWindow.appendChild(embedArea);
document.body.appendChild(notepadWindow); document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow); makeDraggable(titleBar, notepadWindow);
} }
function replaceWithEmbed(notepadWindow, embedCode) { // Function to make an element draggable
const textArea = notepadWindow.querySelector(".text-area");
const embedArea = notepadWindow.querySelector(".embed-area");
textArea.style.display = "none";
embedArea.style.display = "block";
embedArea.innerHTML = embedCode;
}
function makeDraggable(dragHandle, element) { function makeDraggable(dragHandle, element) {
let offsetX, offsetY; let offsetX, offsetY;
dragHandle.addEventListener("mousedown", function (event) { dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault(); event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10); offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10); offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener("mousemove", dragElement); document.addEventListener('mousemove', dragElement);
document.addEventListener("mouseup", stopDragging); document.addEventListener('mouseup', stopDragging);
}); });
function dragElement(event) { function dragElement(event) {
element.style.left = event.clientX - offsetX + "px"; element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = event.clientY - offsetY + "px"; element.style.top = (event.clientY - offsetY) + 'px';
} }
function stopDragging() { function stopDragging() {
document.removeEventListener("mousemove", dragElement); document.removeEventListener('mousemove', dragElement);
document.removeEventListener("mouseup", stopDragging); document.removeEventListener('mouseup', stopDragging);
} }
} }
// Function to save text from notepad
function saveText(notepadWindow) { function saveText(notepadWindow) {
const textArea = notepadWindow.querySelector(".text-area"); const textArea = notepadWindow.querySelector('.text-area');
const textToSave = textArea.value; const textToSave = textArea.value;
const blob = new Blob([textToSave], { type: "text/plain" }); const blob = new Blob([textToSave], {type: "text/plain"});
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const titleText = notepadWindow.querySelector( const titleText = notepadWindow.querySelector('.title-bar > div:nth-child(2)').textContent;
".title-bar > div:nth-child(2)" const a = document.createElement('a');
).textContent;
const a = document.createElement("a");
a.href = url; a.href = url;
a.download = titleText + ".txt"; a.download = titleText + '.txt';
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
document.body.removeChild(a); document.body.removeChild(a);
} }
// Function to open text file in notepad
function openFile(notepadWindow) { function openFile(notepadWindow) {
const fileInput = document.createElement("input"); const fileInput = document.createElement('input');
fileInput.type = "file"; fileInput.type = 'file';
fileInput.accept = "text/plain"; fileInput.accept = 'text/plain';
fileInput.addEventListener("change", function () { fileInput.addEventListener('change', function() {
const file = fileInput.files[0]; const file = fileInput.files[0];
const reader = new FileReader(); const reader = new FileReader();
reader.onload = function (event) { reader.onload = function(event) {
const textArea = notepadWindow.querySelector(".text-area"); notepadWindow.querySelector('.text-area').value = event.target.result;
textArea.style.display = "block";
const embedArea = notepadWindow.querySelector(".embed-area");
embedArea.style.display = "none";
textArea.value = event.target.result;
}; };
reader.readAsText(file); reader.readAsText(file);
}); });
fileInput.click(); fileInput.click();
} }
// Function to show help
function showHelp() { function showHelp() {
const helpWindow = document.createElement("div"); const helpWindow = document.createElement('div');
helpWindow.className = "window"; helpWindow.className = 'window';
helpWindow.style.left = "50px"; helpWindow.style.left = '50px';
helpWindow.style.top = "50px"; helpWindow.style.top = '50px';
helpWindow.style.zIndex = zIndexCounter++; helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement("div"); const titleBar = document.createElement('div');
titleBar.className = "title-bar"; titleBar.className = 'title-bar';
titleBar.draggable = true; titleBar.draggable = true;
const titleText = document.createElement("div"); const titleText = document.createElement('div');
titleText.textContent = "Help"; titleText.textContent = 'Help';
titleText.style.textAlign = "center"; titleText.style.textAlign = 'center';
titleText.style.flexGrow = "1"; titleText.style.flexGrow = '1';
const closeButtonTitle = document.createElement("button"); const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = "close-btn"; closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = "X"; closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function () { closeButtonTitle.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow); helpWindow.parentNode.removeChild(helpWindow);
}; };
titleBar.appendChild(titleText); titleBar.appendChild(titleText);
titleBar.appendChild(closeButtonTitle); titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement("textarea"); const textArea = document.createElement('textarea');
textArea.className = "text-area"; textArea.className = 'text-area';
textArea.style.width = "578px"; textArea.style.width = '578px'; // Adjusting width
textArea.style.height = "221px"; textArea.style.height = '221px'; // Adjusting height
textArea.value = textArea.value = 'rintyuu/notepad v0.4\n\n' +
"rintyuu/notepad v0.5\n\n" + 'using this webapp is very straight foward,\n' +
"using this webapp is very straightforward,\n" + ' - click "New Notepad" at the top right to make a new text window\n' +
' - click "New..." at the top right to make a new text window\n' + ' - windows are dragable\n' +
" - windows are draggable\n" + ' - in each window, there is a file context menu\n' +
" - in each window, there is a file context menu\n" + ' - have fun typing\n\n' +
" - have fun typing\n\n" + 'https://git.rintyuu.dev/rintyuu/notepad\n' +
"https://git.rintyuu.dev/rintyuu/notepad\n" + 'contact me at me@rintyuu.uk for suggestions';
"contact me at me@rintyuu.uk for suggestions";
helpWindow.appendChild(titleBar); helpWindow.appendChild(titleBar);
helpWindow.appendChild(textArea); helpWindow.appendChild(textArea);
@ -300,8 +265,7 @@
makeDraggable(titleBar, helpWindow); makeDraggable(titleBar, helpWindow);
} }
</script>
createNewNotepad(); </body>
</script>
</body>
</html> </html>

279
minimize.html Normal file
View file

@ -0,0 +1,279 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title>
<style>
/* Styles for draggable windows */
.window {
position: absolute;
border: 1px solid #ccc;
background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); /* Drop shadow */
}
.title-bar {
background-color: #f0f0f0;
padding: 5px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
}
.close-btn, .minimize-btn {
cursor: pointer;
}
.title-bar button {
cursor: pointer;
}
.text-area {
width: 300px;
height: 200px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100px;
z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); /* Drop shadow */
}
.dropdown-content button {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
border: none;
background: none;
width: 100%;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.top-left {
top: 5px;
left: 5px;
}
</style>
</head>
<body>
<button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" href="#" onclick="showHelp()">Help</button>
<script>
let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() {
const notepadWindow = document.createElement('div');
notepadWindow.className = 'window';
notepadWindow.style.left = '50px';
notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const fileDropdown = document.createElement('div');
fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
newButton.textContent = 'New...';
newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.onclick = function() {
saveText(notepadWindow);
};
const openButton = document.createElement('button');
openButton.textContent = 'Open';
openButton.onclick = function() {
openFile(notepadWindow);
};
const renameButton = document.createElement('button');
renameButton.textContent = 'Rename';
renameButton.onclick = function() {
const newTitle = prompt('Enter new title:');
if (newTitle !== null) {
titleText.textContent = newTitle;
}
};
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(renameButton);
fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement('div');
titleText.textContent = 'Notepad';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
// Minimize Button
const minimizeButton = document.createElement('button');
minimizeButton.className = 'minimize-btn';
minimizeButton.textContent = '-';
minimizeButton.onclick = function() {
toggleMinimize(notepadWindow, textArea);
};
// Close Button
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
titleBar.appendChild(fileDropdown);
titleBar.appendChild(titleText);
titleBar.appendChild(minimizeButton);
titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement('textarea');
textArea.className = 'text-area';
notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea);
document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow);
}
// Function to make an element draggable
function makeDraggable(dragHandle, element) {
let offsetX, offsetY;
dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener('mousemove', dragElement);
document.addEventListener('mouseup', stopDragging);
});
function dragElement(event) {
element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = (event.clientY - offsetY) + 'px';
}
function stopDragging() {
document.removeEventListener('mousemove', dragElement);
document.removeEventListener('mouseup', stopDragging);
}
}
// Function to toggle minimize and restore
function toggleMinimize(notepadWindow, textArea) {
if (textArea.style.display === 'none') {
textArea.style.display = 'block'; // Restore window
} else {
textArea.style.display = 'none'; // Minimize window
}
}
// Function to save text from notepad
function saveText(notepadWindow) {
const textArea = notepadWindow.querySelector('.text-area');
const textToSave = textArea.value;
const blob = new Blob([textToSave], {type: "text/plain"});
const url = URL.createObjectURL(blob);
const titleText = notepadWindow.querySelector('.title-bar > div:nth-child(2)').textContent;
const a = document.createElement('a');
a.href = url;
a.download = titleText + '.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// Function to open text file in notepad
function openFile(notepadWindow) {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'text/plain';
fileInput.addEventListener('change', function() {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(event) {
notepadWindow.querySelector('.text-area').value = event.target.result;
};
reader.readAsText(file);
});
fileInput.click();
}
// Function to show help
function showHelp() {
const helpWindow = document.createElement('div');
helpWindow.className = 'window';
helpWindow.style.left = '50px';
helpWindow.style.top = '50px';
helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const titleText = document.createElement('div');
titleText.textContent = 'Help';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow);
};
titleBar.appendChild(titleText);
titleBar.appendChild(closeButtonTitle);
const helpContent = document.createElement('div');
helpContent.textContent = 'To use the Notepad: \n - Click "File" to access options \n - You can drag the window around by the title bar \n - Use the minimize button "-" to minimize and restore the window';
helpContent.style.padding = '10px';
helpWindow.appendChild(titleBar);
helpWindow.appendChild(helpContent);
document.body.appendChild(helpWindow);
makeDraggable(titleBar, helpWindow);
}
</script>
</body>
</html>

290
padding+embed.html Normal file
View file

@ -0,0 +1,290 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title>
<style>
.window {
position: absolute;
border: 1px solid #ccc;
background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.title-bar {
background-color: #f0f0f0;
padding: 5px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
}
.title-bar div {
margin-left: 8px; /* Padding between title and buttons */
}
.close-btn {
cursor: pointer;
margin-left: 5px;
}
.minimize-btn {
cursor: pointer;
margin-left: 5px;
}
.text-area {
width: 300px;
height: 200px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100px;
z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content button {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
border: none;
background: none;
width: 100%;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.top-left {
top: 5px;
left: 5px;
}
</style>
</head>
<body>
<button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" onclick="showHelp()">Help</button>
<script>
let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() {
const notepadWindow = document.createElement('div');
notepadWindow.className = 'window';
notepadWindow.style.left = '50px';
notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const fileDropdown = document.createElement('div');
fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
newButton.textContent = 'New...';
newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.onclick = function() {
saveText(notepadWindow);
};
const openButton = document.createElement('button');
openButton.textContent = 'Open';
openButton.onclick = function() {
openFile(notepadWindow);
};
const embedButton = document.createElement('button');
embedButton.textContent = 'Embed HTML';
embedButton.onclick = function() {
embedHTML(notepadWindow);
};
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(embedButton);
fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement('div');
titleText.textContent = 'Notepad';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
const minimizeButton = document.createElement('button');
minimizeButton.className = 'minimize-btn';
minimizeButton.innerHTML = '-';
minimizeButton.onclick = function() {
toggleMinimize(notepadWindow);
};
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
titleBar.appendChild(fileDropdown);
titleBar.appendChild(titleText);
titleBar.appendChild(minimizeButton);
titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement('textarea');
textArea.className = 'text-area';
notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea);
document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow);
}
function toggleMinimize(notepadWindow) {
const textArea = notepadWindow.querySelector('.text-area');
if (textArea.style.display === 'none') {
textArea.style.display = 'block';
} else {
textArea.style.display = 'none';
}
}
function embedHTML(notepadWindow) {
const embedCode = prompt('Paste your embed HTML code here:');
if (embedCode) {
const textArea = notepadWindow.querySelector('.text-area');
textArea.style.display = 'none'; // Hide the text area
const embedContainer = document.createElement('div');
embedContainer.innerHTML = embedCode;
notepadWindow.appendChild(embedContainer); // Embed the HTML content
}
}
// Function to make an element draggable
function makeDraggable(dragHandle, element) {
let offsetX, offsetY;
dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener('mousemove', dragElement);
document.addEventListener('mouseup', stopDragging);
});
function dragElement(event) {
element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = (event.clientY - offsetY) + 'px';
}
function stopDragging() {
document.removeEventListener('mousemove', dragElement);
document.removeEventListener('mouseup', stopDragging);
}
}
// Function to save text from notepad
function saveText(notepadWindow) {
const textArea = notepadWindow.querySelector('.text-area');
const textToSave = textArea.value;
const blob = new Blob([textToSave], {type: "text/plain"});
const url = URL.createObjectURL(blob);
const titleText = notepadWindow.querySelector('.title-bar > div:nth-child(2)').textContent;
const a = document.createElement('a');
a.href = url;
a.download = titleText + '.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// Function to open text file in notepad
function openFile(notepadWindow) {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'text/plain';
fileInput.addEventListener('change', function() {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(event) {
notepadWindow.querySelector('.text-area').value = event.target.result;
};
reader.readAsText(file);
});
fileInput.click();
}
// Function to show help
function showHelp() {
const helpWindow = document.createElement('div');
helpWindow.className = 'window';
helpWindow.style.left = '50px';
helpWindow.style.top = '50px';
helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.textContent = 'Help';
titleBar.draggable = true;
const closeButton = document.createElement('button');
closeButton.className = 'close-btn';
closeButton.innerHTML = 'X';
closeButton.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow);
};
titleBar.appendChild(closeButton);
const helpContent = document.createElement('div');
helpContent.innerHTML = '<p>This is a simple Notepad application.</p>';
helpWindow.appendChild(titleBar);
helpWindow.appendChild(helpContent);
document.body.appendChild(helpWindow);
makeDraggable(titleBar, helpWindow);
}
</script>
</body>
</html>

340
settings.html Normal file
View file

@ -0,0 +1,340 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notepad</title>
<style>
body {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.window {
position: absolute;
border: 1px solid #ccc;
background-color: #fff;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.title-bar {
background-color: #f0f0f0;
padding: 5px;
cursor: move;
display: flex;
justify-content: space-between;
align-items: center;
}
.title-bar div {
margin-left: 8px;
}
.close-btn {
cursor: pointer;
margin-left: 5px;
}
.minimize-btn {
cursor: pointer;
margin-left: 5px;
}
.text-area {
width: 300px;
height: 200px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100px;
z-index: 1;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content button {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
border: none;
background: none;
width: 100%;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.top-left {
top: 5px;
left: 5px;
position: absolute;
}
</style>
</head>
<body>
<button class="top-left" onclick="createNewNotepad()">New...</button>
<button class="top-left" onclick="showHelp()">Help</button>
<button class="top-left" onclick="showSettings()">Settings</button>
<script>
let zIndexCounter = 1;
// Function to create a new notepad
function createNewNotepad() {
const notepadWindow = document.createElement('div');
notepadWindow.className = 'window';
notepadWindow.style.left = '50px';
notepadWindow.style.top = '50px';
notepadWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.draggable = true;
const fileDropdown = document.createElement('div');
fileDropdown.className = 'dropdown';
const fileDropdownButton = document.createElement('button');
fileDropdownButton.textContent = 'File';
const fileDropdownContent = document.createElement('div');
fileDropdownContent.className = 'dropdown-content';
const newButton = document.createElement('button');
newButton.textContent = 'New...';
newButton.onclick = createNewNotepad;
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.onclick = function() {
saveText(notepadWindow);
};
const openButton = document.createElement('button');
openButton.textContent = 'Open';
openButton.onclick = function() {
openFile(notepadWindow);
};
const embedButton = document.createElement('button');
embedButton.textContent = 'Embed HTML';
embedButton.onclick = function() {
embedHTML(notepadWindow);
};
const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
fileDropdownContent.appendChild(newButton);
fileDropdownContent.appendChild(saveButton);
fileDropdownContent.appendChild(openButton);
fileDropdownContent.appendChild(embedButton);
fileDropdownContent.appendChild(closeButton);
fileDropdown.appendChild(fileDropdownButton);
fileDropdown.appendChild(fileDropdownContent);
const titleText = document.createElement('div');
titleText.textContent = 'Notepad';
titleText.style.textAlign = 'center';
titleText.style.flexGrow = '1';
const minimizeButton = document.createElement('button');
minimizeButton.className = 'minimize-btn';
minimizeButton.innerHTML = '-';
minimizeButton.onclick = function() {
toggleMinimize(notepadWindow);
};
const closeButtonTitle = document.createElement('button');
closeButtonTitle.className = 'close-btn';
closeButtonTitle.innerHTML = 'X';
closeButtonTitle.onclick = function() {
if (notepadWindow.querySelector('.text-area').value.trim() !== '') {
const confirmClose = confirm('Are you sure you want to close this notepad?');
if (confirmClose) {
notepadWindow.parentNode.removeChild(notepadWindow);
}
} else {
notepadWindow.parentNode.removeChild(notepadWindow);
}
};
titleBar.appendChild(fileDropdown);
titleBar.appendChild(titleText);
titleBar.appendChild(minimizeButton);
titleBar.appendChild(closeButtonTitle);
const textArea = document.createElement('textarea');
textArea.className = 'text-area';
notepadWindow.appendChild(titleBar);
notepadWindow.appendChild(textArea);
document.body.appendChild(notepadWindow);
makeDraggable(titleBar, notepadWindow);
// Bring the window to front when clicked
notepadWindow.onclick = function() {
bringToFront(notepadWindow);
};
}
function toggleMinimize(notepadWindow) {
const content = notepadWindow.querySelectorAll('.text-area, div[embedded-content]');
content.forEach((item) => {
if (item.style.display === 'none') {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
function embedHTML(notepadWindow) {
const embedCode = prompt('Paste your embed HTML code here:');
if (embedCode) {
const textArea = notepadWindow.querySelector('.text-area');
textArea.style.display = 'none'; // Hide the text area
let embedContainer = notepadWindow.querySelector('[embedded-content]');
if (!embedContainer) {
embedContainer = document.createElement('div');
embedContainer.setAttribute('embedded-content', '');
notepadWindow.appendChild(embedContainer); // Create and append new embed container
}
embedContainer.innerHTML = embedCode; // Embed the HTML content
}
}
// Function to make an element draggable
function makeDraggable(dragHandle, element) {
let offsetX, offsetY;
dragHandle.addEventListener('mousedown', function(event) {
event.preventDefault();
offsetX = event.clientX - parseInt(element.style.left, 10);
offsetY = event.clientY - parseInt(element.style.top, 10);
document.addEventListener('mousemove', dragElement);
document.addEventListener('mouseup', stopDragging);
});
function dragElement(event) {
element.style.left = (event.clientX - offsetX) + 'px';
element.style.top = (event.clientY - offsetY) + 'px';
}
function stopDragging() {
document.removeEventListener('mousemove', dragElement);
document.removeEventListener('mouseup', stopDragging);
}
}
// Function to bring a window to the front
function bringToFront(window) {
window.style.zIndex = zIndexCounter++;
}
// Function to change the background image
function changeBackground() {
const fileInput = document.getElementById('background-upload');
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
document.body.style.backgroundImage = `url(${e.target.result})`;
};
if (file) {
reader.readAsDataURL(file);
}
}
function showSettings() {
const settingsWindow = document.createElement('div');
settingsWindow.className = 'window';
settingsWindow.style.left = '100px';
settingsWindow.style.top = '100px';
settingsWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.textContent = 'Settings';
titleBar.draggable = true;
const closeButton = document.createElement('button');
closeButton.className = 'close-btn';
closeButton.innerHTML = 'X';
closeButton.onclick = function() {
settingsWindow.parentNode.removeChild(settingsWindow);
};
titleBar.appendChild(closeButton);
const settingsContent = document.createElement('div');
settingsContent.innerHTML = `
<p>Change Background:</p>
<input type="file" id="background-upload" accept="image/png" onchange="changeBackground()">
`;
settingsWindow.appendChild(titleBar);
settingsWindow.appendChild(settingsContent);
document.body.appendChild(settingsWindow);
makeDraggable(titleBar, settingsWindow);
settingsWindow.onclick = function() {
bringToFront(settingsWindow);
};
}
function showHelp() {
const helpWindow = document.createElement('div');
helpWindow.className = 'window';
helpWindow.style.left = '100px';
helpWindow.style.top = '100px';
helpWindow.style.zIndex = zIndexCounter++;
const titleBar = document.createElement('div');
titleBar.className = 'title-bar';
titleBar.textContent = 'Help';
titleBar.draggable = true;
const closeButton = document.createElement('button');
closeButton.className = 'close-btn';
closeButton.innerHTML = 'X';
closeButton.onclick = function() {
helpWindow.parentNode.removeChild(helpWindow);
};
titleBar.appendChild(closeButton);
const helpContent = document.createElement('div');
helpContent.innerHTML = '<p>This is a simple Notepad application.</p>';
helpWindow.appendChild(titleBar);
helpWindow.appendChild(helpContent);
document.body.appendChild(helpWindow);
makeDraggable(titleBar, helpWindow);
helpWindow.onclick = function() {
bringToFront(helpWindow);
};
}
</script>
</body>
</html>