Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
978b15cb1e | ||
|
|
72477a5692 | ||
|
|
f71ac358a8 | ||
|
|
e9c44c3a11 | ||
|
|
940c95e015 | ||
|
|
57a5c06712 | ||
| 9c3071e2d1 | |||
| 7804d9208e | |||
| 4fcb90e380 | |||
|
|
c4b8f36815 | ||
|
|
944168eacb | ||
|
|
662ec518d4 | ||
|
|
2d243c2fbc | ||
|
|
939b3fb4f1 | ||
|
|
a106a7a79a | ||
|
|
a947b25605 | ||
|
|
f6c215363a | ||
|
|
07a2505e08 | ||
|
|
8a24c35485 | ||
|
|
5908a09e75 |
10
README.md
10
README.md
@@ -1,8 +1,8 @@
|
|||||||
# Randomizer Application
|
# Randomizer Application
|
||||||
How to install:
|
How to use:
|
||||||
1. Download the zip file
|
1. Visit the Github pages page for the app: https://oskar-mikael.github.io/randomize-app/
|
||||||
2. Extract the folder and place it where you want it
|
2. Start adding items and randomize
|
||||||
3. Open *index.html* in your browser
|
|
||||||
4. Start using the app
|
Feel free to come with suggestions for new features
|
||||||
|
|
||||||
For quick access, save the website as a bookmark in you browser to quickly open it.
|
For quick access, save the website as a bookmark in you browser to quickly open it.
|
||||||
|
|||||||
44
index.html
44
index.html
@@ -6,6 +6,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Titillium+Web&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Titillium+Web&display=swap" rel="stylesheet">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.js"
|
||||||
|
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
|
||||||
<link rel="icon" type="img/png" href="favicon.png">
|
<link rel="icon" type="img/png" href="favicon.png">
|
||||||
<title>Randomize App</title>
|
<title>Randomize App</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -17,7 +19,7 @@
|
|||||||
Randomizer app
|
Randomizer app
|
||||||
</h1>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div id="grid">
|
<div id="grid">
|
||||||
|
|
||||||
<div class="box1">
|
<div class="box1">
|
||||||
@@ -26,7 +28,16 @@
|
|||||||
</h2>
|
</h2>
|
||||||
<input id="input" autocomplete="off"><br>
|
<input id="input" autocomplete="off"><br>
|
||||||
<p id="inputError"></p>
|
<p id="inputError"></p>
|
||||||
<button type="submit" id="add">Add item</button>
|
<form>
|
||||||
|
<button type="submit" id="add">Add item</button>
|
||||||
|
</form>
|
||||||
|
<h3 style="margin-top: 2rem;margin-bottom: 1rem;">
|
||||||
|
Presets
|
||||||
|
</h3>
|
||||||
|
<div style="block">
|
||||||
|
<button type="submit" id="presetFootball">Football </button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box2">
|
<div class="box2">
|
||||||
@@ -40,13 +51,38 @@
|
|||||||
Result:
|
Result:
|
||||||
</h2>
|
</h2>
|
||||||
<h3 id="result"></h3>
|
<h3 id="result"></h3>
|
||||||
<button id="submit">Randomize</button>
|
<form>
|
||||||
|
<select id="selectNumber" class="dropdown">
|
||||||
|
<option value="1">
|
||||||
|
Pick 1
|
||||||
|
</option>
|
||||||
|
<option value="2">
|
||||||
|
Pick 2
|
||||||
|
</option>
|
||||||
|
<option value="3">
|
||||||
|
Pick 3
|
||||||
|
</option>
|
||||||
|
<option value="4">
|
||||||
|
Pick 4
|
||||||
|
</option>
|
||||||
|
<option value="5">
|
||||||
|
Pick 5
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
<button type="submit" id="submit">Randomize</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="reset">Reset</button>
|
<button id="reset">Reset</button>
|
||||||
|
|
||||||
|
<div style="text-align: left; font-size:1rem;position:fixed;bottom:0">
|
||||||
|
© 2023 Oskar Boström
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
112
script.js
112
script.js
@@ -1,47 +1,101 @@
|
|||||||
let items = []
|
let items = []
|
||||||
let result = ""
|
let result = ""
|
||||||
let input = document.querySelector("#input");
|
let input = $('#input');
|
||||||
|
|
||||||
|
|
||||||
input.addEventListener('keyup', function (event) {
|
|
||||||
if (event.keyCode === 13) {
|
|
||||||
event.preventDefault();
|
|
||||||
document.querySelector("#add").click();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$('form').on('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
document.querySelector("#add").addEventListener('click', addItem);
|
|
||||||
document.querySelector("#submit").addEventListener('click', displayResult);
|
$(input).on('keypress', function (e) {
|
||||||
document.querySelector("#reset").addEventListener('click', reset);
|
if (e.which == 13) {
|
||||||
|
addItem();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add').on('click', function () {
|
||||||
|
addItem()
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#reset').on('click', function () {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#submit').on('click', function () {
|
||||||
|
displayResult()
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', 'img.delete', function () {
|
||||||
|
let deletedItem = $(this).closest('li')
|
||||||
|
let itemValue = $(this).closest('li').text()
|
||||||
|
let index = items.indexOf(itemValue);
|
||||||
|
if (index != -1) {
|
||||||
|
items.splice(index, 1);
|
||||||
|
}
|
||||||
|
deletedItem.remove();
|
||||||
|
console.log(itemValue)
|
||||||
|
});
|
||||||
|
|
||||||
|
$('button#presetFootball').click(function () {
|
||||||
|
let ul = $('#itemlist');
|
||||||
|
console.log(ul)
|
||||||
|
items = [];
|
||||||
|
items.push('Oskar', 'Emil', 'Kim', 'Mads', 'Mads C', 'Michal',)
|
||||||
|
// let ul = $('#itemlist');
|
||||||
|
items.forEach(function (item) {
|
||||||
|
let li = document.createElement('li');
|
||||||
|
let img = document.createElement('img')
|
||||||
|
li.append(item);
|
||||||
|
ul.append(li);
|
||||||
|
li.append(img);
|
||||||
|
$(img).addClass('delete')
|
||||||
|
$(img).attr('src', 'close.png');
|
||||||
|
$(input).css('border', '1px solid black');
|
||||||
|
$(input).val('');
|
||||||
|
$('#inputError').html("")
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function addItem() {
|
function addItem() {
|
||||||
if (input.value.length < 1) {
|
if (input.val().length < 1) {
|
||||||
document.querySelector("#inputError").innerHTML = "Add an item please";
|
$('#inputError').html("Add an item please");
|
||||||
} else {
|
} else {
|
||||||
items.push(document.querySelector("#input").value)
|
items.push($(input).val());
|
||||||
let ul = document.querySelector("#itemlist");
|
let ul = $('#itemlist');
|
||||||
let li = document.createElement('li');
|
let li = document.createElement('li');
|
||||||
li.appendChild(document.createTextNode(input.value));
|
let img = document.createElement('img')
|
||||||
ul.appendChild(li)
|
li.append($(input).val());
|
||||||
document.querySelector("#input").style.border = "2px solid black";
|
ul.append(li);
|
||||||
document.querySelector("#input").value = '';
|
li.append(img);
|
||||||
document.querySelector("#inputError").innerHTML = "";
|
$(img).addClass('delete')
|
||||||
|
$(img).attr('src', 'close.png');
|
||||||
|
$(input).css('border', '1px solid black');
|
||||||
|
$(input).val('');
|
||||||
|
$('#inputError').html("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function displayResult() {
|
function displayResult() {
|
||||||
if (items.length < 1) {
|
if (items.length < 1) {
|
||||||
document.querySelector("#result").innerHTML = "Error: Add atleast 1 item"
|
$('#result').html('Error: Add atleast 1 item')
|
||||||
document.querySelector("#input").style.border = "2px solid red"
|
$(input).css('border', '2px solid red');
|
||||||
} else {
|
return;
|
||||||
result = items[Math.floor(Math.random() * items.length)];
|
|
||||||
document.querySelector("#result").innerHTML = result
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
let selectNumber = $('#selectNumber').val()
|
||||||
window.location.reload();
|
const shuffled = items.sort(() => 0.5 - Math.random());
|
||||||
|
result = shuffled.slice(0, selectNumber)
|
||||||
|
|
||||||
|
let resultText = '';
|
||||||
|
result.forEach(function (item) {
|
||||||
|
resultText += item + ', ';
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#result').html(resultText.slice(0, -2))
|
||||||
|
$('#result').hide().fadeIn(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
style.css
33
style.css
@@ -22,13 +22,14 @@ button {
|
|||||||
padding: 1rem 1.5rem;
|
padding: 1rem 1.5rem;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
background-color: burlywood;
|
background-color: burlywood;
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
ol {
|
ol {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin-bottom: 5rem;
|
margin-bottom: 5rem;
|
||||||
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
ol>li {
|
ol>li {
|
||||||
@@ -43,4 +44,34 @@ ol>li {
|
|||||||
|
|
||||||
#reset {
|
#reset {
|
||||||
margin-top: 5rem;
|
margin-top: 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete {
|
||||||
|
margin-left: 2rem;
|
||||||
|
width: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete:hover {
|
||||||
|
color: rgb(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
height: 50px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
color: #555;
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
background-image: none;
|
||||||
|
border: 1px solid rgb(41, 18, 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width:768px) {
|
||||||
|
#grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user