Добавил свои коды
This commit is contained in:
parent
2cbd6bb619
commit
406a51f77d
187
assets/css/list-rooms.css
Normal file
187
assets/css/list-rooms.css
Normal file
@ -0,0 +1,187 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Список Чат-Комнат</title>
|
||||
<link rel="stylesheet" href="form.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 stylebody {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 30px auto; /* Уменьшили верхний отступ */
|
||||
padding: 20px;
|
||||
background-color: #007bff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #fff; /* Белый цвет для заголовка */
|
||||
}
|
||||
|
||||
.room-list {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.room-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
background-color: #fafafa;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.room-item:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
|
||||
.room-name {
|
||||
font-size: 18px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.join-button {
|
||||
padding: 10px 15px;
|
||||
font-size: 16px;
|
||||
color: white;
|
||||
background-color: #007bff;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.join-button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: #fff;
|
||||
margin: 10% auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #888;
|
||||
width: 80%;
|
||||
max-width: 400px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.modal-header, .modal-footer {
|
||||
padding: 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.close {
|
||||
color: #aaa;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.close:hover, .close:focus {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal input {
|
||||
width: 93.5%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.create-room-button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
color: white;
|
||||
background-color: #1609ab;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.create-room-button:hover {
|
||||
background-color: #218838;
|
||||
}="color: white;">Выберите Чат-Комнату</h1>
|
||||
<ul class="room-list">
|
||||
<!-- Здесь будет список комнат -->
|
||||
</ul>
|
||||
<button class="create-room-button" onclick="openCreateRoomModal()">Создать Комнату</button>
|
||||
</div>
|
||||
|
||||
<div id="passwordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close" onclick="closeModal()">×</span>
|
||||
<h2>Введите Пароль</h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="password" id="roomPassword" placeholder="Пароль">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="join-button" onclick="validatePassword()">Подтвердить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Модальное окно для создания комнаты -->
|
||||
<div id="createRoomModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close" onclick="closeCreateRoomModal()">×</span>
|
||||
<h2>Создать Комнату</h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="text" id="newRoomName" placeholder="Название комнаты">
|
||||
<input type="password" id="newRoomPassword" placeholder="Пароль">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="join-button" onclick="createRoom()">Создать</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="list-rooms.js"></script>
|
||||
</body>
|
||||
</html>
|
52
assets/html/list-rooms.html
Normal file
52
assets/html/list-rooms.html
Normal file
@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Список Чат-Комнат</title>
|
||||
<link rel="stylesheet" href="form.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 style="color: white;">Выберите Чат-Комнату</h1>
|
||||
<ul class="room-list">
|
||||
<!-- Здесь будет список комнат -->
|
||||
</ul>
|
||||
<button class="create-room-button" onclick="openCreateRoomModal()">Создать Комнату</button>
|
||||
</div>
|
||||
|
||||
<div id="passwordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close" onclick="closeModal()">×</span>
|
||||
<h2>Введите Пароль</h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="password" id="roomPassword" placeholder="Пароль">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="join-button" onclick="validatePassword()">Подтвердить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Модальное окно для создания комнаты -->
|
||||
<div id="createRoomModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close" onclick="closeCreateRoomModal()">×</span>
|
||||
<h2>Создать Комнату</h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="text" id="newRoomName" placeholder="Название комнаты">
|
||||
<input type="password" id="newRoomPassword" placeholder="Пароль">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="join-button" onclick="createRoom()">Создать</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="list-rooms.js"></script>
|
||||
</body>
|
||||
</html>
|
83
assets/js/list-rooms.js
Normal file
83
assets/js/list-rooms.js
Normal file
@ -0,0 +1,83 @@
|
||||
let rooms = {};
|
||||
|
||||
function openModal(roomName) {
|
||||
currentRoom = roomName;
|
||||
document.getElementById('passwordModal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById('passwordModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function validatePassword() {
|
||||
const enteredPassword = document.getElementById('roomPassword').value;
|
||||
if (enteredPassword === rooms[currentRoom]) {
|
||||
alert('Вы вошли в комнату: ' + currentRoom);
|
||||
closeModal();
|
||||
} else {
|
||||
alert('Неверный пароль. Попробуйте снова.');
|
||||
}
|
||||
}
|
||||
|
||||
function openCreateRoomModal() {
|
||||
document.getElementById('createRoomModal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeCreateRoomModal() {
|
||||
document.getElementById('createRoomModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function createRoom() {
|
||||
const roomName = document.getElementById('newRoomName').value.trim();
|
||||
const roomPassword = document.getElementById('newRoomPassword').value.trim();
|
||||
|
||||
if (roomName === '' || roomPassword === '') {
|
||||
alert('Пожалуйста, заполните все поля.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (rooms[roomName]) {
|
||||
alert('Комната с таким названием уже существует.');
|
||||
return;
|
||||
}
|
||||
|
||||
rooms[roomName] = roomPassword;
|
||||
addRoomToList(roomName);
|
||||
closeCreateRoomModal();
|
||||
}
|
||||
|
||||
function addRoomToList(roomName) {
|
||||
const roomList = document.querySelector('.room-list');
|
||||
|
||||
const existingRoomItem = Array.from(roomList.children).find(item => item.querySelector('.room-name').textContent === roomName);
|
||||
if (existingRoomItem) {
|
||||
existingRoomItem.remove();
|
||||
}
|
||||
|
||||
const roomItem = document.createElement('li');
|
||||
roomItem.classList.add('room-item');
|
||||
|
||||
roomItem.innerHTML = `
|
||||
<span class="room-name">${roomName}</span>
|
||||
<button class="join-button" onclick="openModal('${roomName}')">Войти</button>
|
||||
`;
|
||||
|
||||
roomList.appendChild(roomItem);
|
||||
}
|
||||
|
||||
function initializeRoomList() {
|
||||
Object.keys(rooms).forEach(roomName => {
|
||||
addRoomToList(roomName);
|
||||
});
|
||||
}
|
||||
|
||||
initializeRoomList();
|
||||
|
||||
window.onclick = function(event) {
|
||||
if (event.target === document.getElementById('passwordModal')) {
|
||||
closeModal();
|
||||
}
|
||||
if (event.target === document.getElementById('createRoomModal')) {
|
||||
closeCreateRoomModal();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user