Skip to content

Commit

Permalink
Merge branch 'release/4.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyTim committed Jun 21, 2024
2 parents d29247b + c1dceea commit 2a52dbb
Show file tree
Hide file tree
Showing 20 changed files with 563 additions and 375 deletions.
58 changes: 35 additions & 23 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/spin-wheel-esm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/spin-wheel-iife.js

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions examples/multiple/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,30 @@ window.onload = () => {
window.wheel2 = new Wheel(container2, props2);

const btnSpin = document.querySelector('button');

let modifier = 0;

window.addEventListener('click', (e) => {

// Listen for click event on spin button:
if (e.target === btnSpin) {
const duration = 2600;
const winningItemRotaion1 = getRandomInt(90, 360) + modifier;
const winningItemRotaion2 = getRandomInt(90, 360) + modifier;
wheel1.spinTo(winningItemRotaion1, duration);
wheel2.spinTo(winningItemRotaion1 + WHEEL_2_INITIAL_ROTATION, duration);
modifier += 270;
const {duration, winningItemRotaion} = calcSpinToValues();
wheel1.spinTo(winningItemRotaion, duration);
wheel2.spinTo(winningItemRotaion + WHEEL_2_INITIAL_ROTATION, duration);
}

});

function calcSpinToValues() {
const duration = 2600;
const winningItemRotaion = getRandomInt(360, 360 * 1.75) + modifier;
modifier += 360 * 1.75;
return {duration, winningItemRotaion};
}

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}

};
9 changes: 5 additions & 4 deletions examples/playground/js/initEventListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ function initTextboxArray(g) {
}

function exportWheelAsJson() {
const obj = {};
for (const [key, value] of Object.entries(wheelPropInits)) {
obj[key] = window.wheel[key];
const json = {};
for (const g of inputGroups) {
const key = g.dataset.name;
json[key] = window.wheel[key];
}
downloadTextFile(JSON.stringify(obj, null, 2), 'spin-wheel-settings.json', 'text/json');
downloadTextFile(JSON.stringify(json, null, 2), 'spin-wheel-settings.json', 'text/json');
}

function roundUp(num = 0, decimalPlaces = 2) {
Expand Down
14 changes: 14 additions & 0 deletions examples/themes/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,24 @@ body {
gap: 10px;
}

.gui-wrapper > div {
display: flex;
flex-direction:row;
gap: 10px;
align-items: center;
}

select {
padding: 2px;
}

label {
margin-right: 5px;
}

button {
padding: 10px 20px;
cursor: pointer;
margin-right: 10px;
max-width: 100px;
}
7 changes: 5 additions & 2 deletions examples/themes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

<body>
<div class="gui-wrapper">
<p>Click-drag (or flick) to spin the wheel.</p>
<p><label>Theme:</label><select></select></p>
<p>Click-drag (or touch-flick) to spin the wheel.</p>
<div>
<button>Spin</button>
<p><label>Theme:</label><select></select></p>
</div>
</div>

<div class="wheel-wrapper"></div>
Expand Down
34 changes: 28 additions & 6 deletions examples/themes/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import {loadFonts} from '../../../scripts/util.js';
import {props} from './props.js';

window.onload = async () => {
await loadFonts(props.map(i => i.itemLabelFont));
init();
};

function init() {
await loadFonts(props.map(i => i.itemLabelFont));

const wheel = new Wheel(document.querySelector('.wheel-wrapper'));

const dropdown = document.querySelector('select');

// Initalise dropdown with the names of each example:
Expand All @@ -35,4 +31,30 @@ function init() {
// Save object globally for easy debugging.
window.wheel = wheel;

}
const btnSpin = document.querySelector('button');
let modifier = 0;

window.addEventListener('click', (e) => {

// Listen for click event on spin button:
if (e.target === btnSpin) {
const {duration, winningItemRotaion} = calcSpinToValues();
wheel.spinTo(winningItemRotaion, duration);
}

});

function calcSpinToValues() {
const duration = 3000;
const winningItemRotaion = getRandomInt(360, 360 * 1.75) + modifier;
modifier += 360 * 1.75;
return {duration, winningItemRotaion};
}

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}

};
8 changes: 6 additions & 2 deletions examples/vue3/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
</script>

<template>
<button @click="count++">Items: {{ count }}</button>
<SpinWheel :num-items="count"></SpinWheel>
<div class="body-wrapper">
<div class="gui-wrapper">
<button @click="count++">Items: {{ count }}</button>
</div>
<SpinWheel :num-items="count"></SpinWheel>
</div>
</template>

<style scoped>
Expand Down
7 changes: 1 addition & 6 deletions examples/vue3/src/components/SpinWheel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@
</script>

<template>
<div ref="wheelContainer"></div>
<div class="wheel-wrapper" ref="wheelContainer"></div>
</template>

<style scoped>
div {
width: 60vw;
height: 60vh;
margin: auto;
}
</style>
51 changes: 50 additions & 1 deletion examples/vue3/src/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
html, body {
* {
margin: 0;
padding: 0;
font-family: 'Lucida Grande', sans-serif;
font-size: 15px;
-webkit-tap-highlight-color: transparent;
user-select: none; /* Prevent selecting ui text when dragging */
}

html, body {
height: 100%;
}

.body-wrapper {
height: 100%;

/* Prevent pull-down-to-refresh gesture */
overscroll-behavior-y: contain;

/* Prevent iOS rubber-band effect */
position: fixed;
width: 100%;

/* Prevent browser from handling touch events */
touch-action: none;

display: grid;
grid-template-rows: auto 1fr;
justify-items: stretch;
align-items: stretch;
}

.wheel-wrapper {
overflow: hidden;
height: 100%;
width: 100%;
}

.gui-wrapper {
padding: 10px;
background-color: #f3f3f3;
display: flex;
flex-direction: column;
gap: 10px;
}

button {
padding: 10px 20px;
cursor: pointer;
margin-right: 10px;
max-width: 150px;
}
Loading

0 comments on commit 2a52dbb

Please sign in to comment.