add testing files
This commit is contained in:
parent
c2af765246
commit
42aa1f980c
5 changed files with 1476 additions and 0 deletions
302
custom-background.html
Normal file
302
custom-background.html
Normal 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
265
embed-revision.html
Normal 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>
|
279
minimize.html
Normal file
279
minimize.html
Normal 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
290
padding+embed.html
Normal 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
340
settings.html
Normal 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>
|
Loading…
Add table
Reference in a new issue