62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
var QBRadialMenu = null;
|
|
|
|
$(document).ready(function(){
|
|
|
|
window.addEventListener('message', function(event){
|
|
var eventData = event.data;
|
|
|
|
if (eventData.action == "ui") {
|
|
if (eventData.radial) {
|
|
createMenu(eventData.items)
|
|
QBRadialMenu.open();
|
|
} else {
|
|
QBRadialMenu.close();
|
|
}
|
|
}
|
|
|
|
if (eventData.action == "setPlayers") {
|
|
createMenu(eventData.items)
|
|
}
|
|
});
|
|
});
|
|
|
|
function createMenu(items) {
|
|
QBRadialMenu = new RadialMenu({
|
|
parent : document.body,
|
|
size : 375,
|
|
menuItems : items,
|
|
onClick : function(item) {
|
|
if (item.shouldClose) {
|
|
QBRadialMenu.close();
|
|
}
|
|
|
|
if (item.event !== null) {
|
|
if (item.data !== null) {
|
|
$.post('https://rlo_radialmenu/selectItem', JSON.stringify({
|
|
itemData: item,
|
|
data: item.data
|
|
}))
|
|
} else {
|
|
$.post('https://rlo_radialmenu/selectItem', JSON.stringify({
|
|
itemData: item
|
|
}))
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
const CancelMenu = () => {
|
|
$.post(`https://rlo_radialmenu/cancel`)
|
|
}
|
|
|
|
$(document).on('keydown', function(e) {
|
|
switch(e.key) {
|
|
case "Escape":
|
|
CancelMenu();
|
|
QBRadialMenu.close();
|
|
break;
|
|
}
|
|
}); |