Skip to content

Commit 104c359

Browse files
committed
More manual minification etc.
1 parent 363b0f6 commit 104c359

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

changelog

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ keypadder (0.3.0) stable; urgency=low
66
* Docs: Update for new features
77
* Docs: Enhance example/keypad.toml to use new features, add PokerTH map
88
* Bugfix: Don't truncate mnemonics shown via --dumpkeys
9+
* Internal: Reduce size of HTML/JavaScript for main page
910

1011
[mgrojo]
1112
* Feature: Add big Maths symbols example config
1213

13-
-- SMerrony <[email protected]> Fri, 24 Feb 2023 10:00:00 +0200
14+
-- SMerrony <[email protected]> Sat, 11 Mar 2023 10:00:00 +0200
1415

1516
keypadder (0.2.0) stable; urgency=low
1617

src/frontend.adb

+15-18
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ package body Frontend is
1616
function Request_CB (Request : AWS.Status.Data) return AWS.Response.Data is
1717
URI : constant String := AWS.Status.URI (Request);
1818
Parms : AWS.Parameters.List;
19-
Current_Tab_Ix : Positive;
2019
begin
2120
if URI = "/" then
2221
return AWS.Response.Build ("text/html", Build_Main_Page (1));
2322
elsif URI = "/buttonpress" then
2423
Parms := AWS.Status.Parameters (Request);
25-
Decode_And_Send_Key (To_String (AWS.Parameters.Get (Parms, 1).Value),
26-
To_String (AWS.Parameters.Get (Parms, 2).Value), Current_Tab_Ix);
24+
Send_Key (To_String (AWS.Parameters.Get (Parms, 1).Value), To_String (AWS.Parameters.Get (Parms, 2).Value));
2725
return AWS.Response.Build ("text/html", "OK");
2826
elsif URI = "/shutdown" then
2927
Shutting_Down := True;
@@ -42,22 +40,23 @@ package body Frontend is
4240
".kp-selector {position:absolute; height:12mm; top:1px; right:2px; font-size:10mm;} " &
4341
".kp-pad {align-content:stretch;} " &
4442
".kp-btn {margin:0; font-size:calc(4vw + 4vh + 2vmin); border-radius:4mm; background-color:black; padding:2mm; color:white;}" &
45-
"</style><meta charset=""UTF-8""><title>Keypadder</title></head>" & ASCII.LF &
46-
"<body>";
43+
"</style><meta charset=""UTF-8""><title>Keypadder</title></head>" &
44+
"<body>" & ASCII.LF;
4745
Trailer_HTML : constant String :=
4846
"<script>" &
4947
"function selTab(){var selector=document.getElementById('kpselect');openTab(selector.options[selector.selectedIndex].value);}" &
50-
"function openTab(tabName) { " &
51-
"var i; var x = document.getElementsByClassName('kp-pad');" &
52-
"for (i=0; i<x.length; i++) { x[i].style.display = 'none';}" &
53-
"document.getElementById(tabName).style.display = 'block'; } " &
54-
"function aget(tab, id) { " & -- Get via AJAX
48+
49+
"function openTab(tabName){var x=document.getElementsByClassName('kp-pad');" &
50+
"for (let i=0; i<x.length; i++) {x[i].style.display='none';}" &
51+
"document.getElementById(tabName).style.display='block';} " &
52+
53+
"function aget(tab, id) {" & -- Get via AJAX
5554
"var form = new FormData(document.getElementById(""kpForm"")); " &
56-
"form.append(""tab"", tab); form.append(""id"", id); " &
55+
"form.append(""tab"", tab); form.append(""id"", id); " &
5756
"var data = new URLSearchParams(form).toString(); " &
5857
"var xhr = new XMLHttpRequest(); " &
5958
"xhr.open(""GET"", ""buttonpress?"" + data); " &
60-
"xhr.send(); return false; }" &
59+
"xhr.send(); return false;}" &
6160
"</script></form></body></html>";
6261
Main_HTML : Unbounded_String := Null_Unbounded_String;
6362
Tmp_Style : Unbounded_String := Null_Unbounded_String;
@@ -127,17 +126,15 @@ package body Frontend is
127126
return To_String (Main_HTML);
128127
end Build_Main_Page;
129128

130-
procedure Decode_And_Send_Key (T, I : String; Tab : out Positive) is
131-
Tab_Ix : constant Positive := Positive'Value (T); -- (Key_ID (Index (Key_ID, "t") + 1 .. Index (Key_ID, "i") - 1));
132-
Key_Ix : constant Positive := Positive'Value (I); -- (Key_ID (Index (Key_ID, "i") + 1 .. Key_ID'Last));
129+
procedure Send_Key (T, I : String) is
130+
Tab_Ix : constant Positive := Positive'Value (T);
131+
Key_Ix : constant Positive := Positive'Value (I);
133132
begin
134-
-- Put_Line ("Decoded Tab:" & Tab_Ix'Image & " and Index:" & Key_Ix'Image);
135-
Tab := Tab_Ix;
136133
Injector.Injector_Task.Send (Conf.Tabs (Tab_Ix).Keys (Key_Ix).Send_Events);
137134
exception
138135
when Error : others =>
139136
Put_Line ("Error in Decode_And_Send_Key: ");
140137
Put_Line (Exception_Information (Error));
141-
end Decode_And_Send_Key;
138+
end Send_Key;
142139

143140
end Frontend;

src/frontend.ads

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ package Frontend is
1111
function Request_CB (Request : AWS.Status.Data) return AWS.Response.Data;
1212
-- Main handler for HTTP requests.
1313

14+
private
15+
1416
function Build_Main_Page (Active_Tab : Positive) return String;
1517
-- Transform the configuration into our web page.
1618
-- Must be called after our configuration is loaded.
1719

18-
private
19-
20-
procedure Decode_And_Send_Key (T, I : String; Tab : out Positive);
21-
-- Find the key from the ID string and send the
22-
-- associated data via the Injector.
23-
-- The ID arrives in the form "key_t1i8" which indcates
24-
-- Tab #1, Key #8.
20+
procedure Send_Key (T, I : String);
21+
-- Send the associated keypress data via the Injector.
2522

2623
end Frontend;

0 commit comments

Comments
 (0)