notepad/settings.html
2024-09-13 00:10:38 -07:00

340 lines
11 KiB
HTML

<!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>