Button click events set, antenna mode set working

This commit is contained in:
Dan
2019-11-27 11:24:33 +00:00
parent 9585ce5851
commit f404890e10
3 changed files with 60 additions and 103 deletions

View File

@@ -113,14 +113,13 @@
</div>
<div id="rc">
<!-- <div id="rc"> -->
<button id="toggleDisplay" class="rounded_btn toggle_display">TOGGLE DISPLAY</button>
<p class="label">FRONT ANTENNA</p>
<div class="antenna_btns_container">
<div class="btns btns_top">
<button id="frontOppMode" class="zone_btn top_left">OPP LK/REL</button>
<button id="frontOppMode" data-action="setAntennaMode" data-value="front" data-mode="2" class="zone_btn top_left">OPP LK/REL</button>
<div class="xmit_wrap">
<div class="xmit_btn xmit_top">
@@ -129,7 +128,7 @@
</div>
</div>
<button id="frontSameMode" class="zone_btn top_right">SAME LK/REL</button>
<button id="frontSameMode" data-action="setAntennaMode" data-value="front" data-mode="1" class="zone_btn top_right">SAME LK/REL</button>
</div>
<div class="breaker"></div>

View File

@@ -88,6 +88,13 @@ const remoteButtons =
}
}
const antennaModes =
{
same: 0,
opp: 1,
both: 2
}
// Hide the radar and remote, this way we can bypass setting a style of 'display: none;' in the HTML file
elements.radar.hide();
elements.remote.hide();
@@ -97,6 +104,13 @@ remoteButtons.toggleDisplay.click( function() {
elements.radar.fadeToggle();
} )
function toggleRemote()
{
elements.remote.toggle();
}
// function toggleLabel( )
// This function is used to send data back through to the LUA side
function sendData( name, data ) {
$.post( "http://" + resourceName + "/" + name, JSON.stringify( data ), function( datab ) {
@@ -106,15 +120,33 @@ function sendData( name, data ) {
} );
}
// This runs when the JS file is loaded, loops through all of the remote buttons and assigns them an onclick function
function remoteInit()
{
elements.remote.find( "button" ).each( function( i, obj ) {
if ( $( this ).attr( "data-action" ) && $( this ).attr( "data-value" ) ) {
$( this ).click( function() {
let action = $( this ).data( "action" );
let value = $( this ).data( "value" );
let mode = $( this ).data( "mode" );
sendData( action, { value, mode } );
} )
}
} );
}
// Close the remote when the user presses the 'Escape' key
document.onkeyup = function ( event ) {
if ( event.keyCode == 27 )
{
sendData( "remote", "close" );
$( "#rc" ).toggle();
sendData( "closeRemote", null );
toggleRemote();
}
}
remoteInit();
// The main event listener, this is what the NUI messages sent by the LUA side arrive at, they are
// then handled properly via a switch/case that runs the relevant code
window.addEventListener( "message", function( event ) {
@@ -123,24 +155,6 @@ window.addEventListener( "message", function( event ) {
if ( item.pathName ) {
resourceName = item.pathName;
} else if ( item.activateRemote ) {
$( "#rc" ).toggle();
} else if ( item.test1 ) {
elements.antennas.front.targetSpeed.html( item.test1 );
} else if ( item.test2 ) {
elements.antennas.front.fast.speed.html( item.test2 );
} else if ( item.test3 ) {
elements.antennas.rear.targetSpeed.html( item.test3 );
} else if ( item.test4 ) {
elements.antennas.rear.fast.speed.html( item.test4 );
}
if ( item.test1 == -1 ) {
elements.antennas.front.targetSpeed.html( "¦¦¦" );
} else if ( item.test2 == -1 ) {
elements.antennas.front.fast.speed.html( "¦¦¦" );
} else if ( item.test3 == -1 ) {
elements.antennas.rear.targetSpeed.html( "¦¦¦" );
} else if ( item.test4 == -1 ) {
elements.antennas.rear.fast.speed.html( "¦¦¦" );
}
toggleRemote();
}
} );