New HTML Skeletons · KcsDev1982/sunbelt-plb-samples@d883bf9 · GitHub
Skip to content

Commit d883bf9

Browse files
committed
New HTML Skeletons
Skeleton programs for a program using a HTML UI and a program using a HTML iframe
1 parent fd75fc8 commit d883bf9

8 files changed

Lines changed: 743 additions & 0 deletions

templates/html_if_skeleton.html

Lines changed: 51 additions & 0 deletions

templates/html_if_skeleton.plf

3.54 KB
Binary file not shown.

templates/html_if_skeleton.pls

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
*---------------------------------------------------------------
2+
.
3+
. Program Name: <name>
4+
. Description: <description>
5+
.
6+
. Revision History:
7+
.
8+
. <date> <programmer>
9+
. Original code
10+
.
11+
INCLUDE plbequ.inc
12+
INCLUDE plbmeth.inc
13+
INCLUDE plbstdlib.inc
14+
15+
CIFNDEF $CLI_STATE_CORDOVA
16+
$CLI_STATE_CORDOVA EQU 2
17+
$CLI_STATE_BOOTSTRAP5 EQU 16
18+
CENDIF
19+
20+
// Runtime status variables
21+
isGui BOOLEAN
22+
isWebSrv BOOLEAN
23+
isPlbSrv BOOLEAN
24+
isWebview BOOLEAN
25+
isWebCliApp BOOLEAN
26+
isSmallScreen BOOLEAN
27+
28+
// Global data
29+
mainForm PLFORM html_if_skeleton.plf
30+
Client CLIENT
31+
Runtime RUNTIME
32+
jsonData DIM 200
33+
34+
*................................................................
35+
.
36+
. Code start
37+
.
38+
CALL Main
39+
WINHIDE
40+
LOOP
41+
EVENTWAIT
42+
REPEAT
43+
STOP
44+
45+
*................................................................
46+
.
47+
. Check what type of runtime support we have
48+
.
49+
CheckStatus LFUNCTION
50+
ENTRY
51+
runtimeData DIM 50
52+
runtimeVersion DIM 5
53+
unused DIM 1
54+
plbRuntime DIM 9
55+
WidthData DIM 5
56+
checkWidth FORM 5
57+
58+
GETMODE *GUI=isGui ; Check for character mode runtime
59+
IF (isGui)
60+
CLOCK VERSION,runtimeData ; Check windows console
61+
UNPACK runtimeData,runtimeVersion,unused,plbRuntime
62+
CHOP plbRuntime
63+
64+
IF (NOCASE plbRuntime == "PLBCON")
65+
CLEAR isGui
66+
ENDIF
67+
IF (NOCASE plbRuntime == "PLBWEBSV")
68+
SET isWebSrv
69+
ENDIF
70+
IF (NOCASE plbRuntime == "PLBSERVE")
71+
SET isPlbSrv
72+
ENDIF
73+
ENDIF
74+
75+
IF (isGui)
76+
WINHIDE
77+
78+
Client.Getstate Giving isWebCliApp Using $CLI_STATE_CORDOVA
79+
Client.Getstate Giving isWebview Using $CLI_STATE_BOOTSTRAP5
80+
81+
IF (isWebSrv) ; Check for a small screen (such as iphone)
82+
Client.GetWinInfo Giving WidthData Using 0x2
83+
MOVE WidthData To checkWidth
84+
MOVE (checkWidth <= 700) to isSmallScreen
85+
ENDIF
86+
ENDIF
87+
88+
FUNCTIONEND
89+
90+
*................................................................
91+
.
92+
. Load a supporting HTML file
93+
.
94+
LoadSupportHtml LFUNCTION
95+
htmlCtl HTMLCONTROL ^
96+
fileName DIM 250
97+
ENTRY
98+
htmlFile FILE
99+
htmlBuffer DIM ^
100+
fileSize INTEGER 4
101+
fullFileName DIM 250
102+
seq FORM "-1"
103+
104+
EXCEPTSET NoFile IF IO
105+
OPEN htmlFile,fileName,Read
106+
107+
GETFILE htmlFile,TxtName=fullFileName ; Read the registration file into a buffer
108+
FINDFILE fullFileName,FileSize=fileSize
109+
IF (!fileSize)
110+
INCR fileSize
111+
ENDIF
112+
113+
DMAKE htmlBuffer,fileSize
114+
READ htmlFile,Seq;*ABSON,htmlBuffer
115+
htmlCtl.InnerHtml Using htmlBuffer,$HTML_HAS_EVENTS
116+
CLOSE htmlFile
117+
DFREE htmlBuffer
118+
noFile
119+
FUNCTIONEND
120+
121+
122+
*................................................................
123+
.
124+
. Event handler
125+
.
126+
HctlEvent LFUNCTION
127+
ENTRY
128+
editData DIM 40
129+
result FORM 5
130+
131+
SCAN "submit" in JsonData
132+
IF EQUAL
133+
CALL HctlMsgIframe
134+
ENDIF
135+
136+
FUNCTIONEND
137+
138+
*................................................................
139+
.
140+
. Set up the events on the HTML objects and register the event handler
141+
.
142+
HctlSetupEvents LFUNCTION
143+
ENTRY
144+
EVENTREG htmlHctlMain,$JQueryEvent,HctlEvent,ARG1=JsonData
145+
htmlHctlMain.SetAttr using "submit","data-plbevent","click"
146+
htmlHctlMain.UpdateEvents
147+
Client.FlushMessages
148+
FUNCTIONEND
149+
150+
*................................................................
151+
.
152+
. Send a message to the iframe form the PL/B program
153+
.
154+
HctlMsgIframe LFUNCTION
155+
ENTRY
156+
htmlFrmMain.SetAsClient
157+
Client.jsrun Using "plbSendMsg( 'plbFrame', 1, {}, 'Hello from Main' );"
158+
Client.FlushMessages
159+
FUNCTIONEND
160+
*................................................................
161+
.
162+
. Main - Main program entry point
163+
.
164+
Main LFUNCTION
165+
ENTRY
166+
result FORM 4
167+
168+
CALL CheckStatus
169+
IF (!isGui)
170+
KEYIN "This runtime can't run this program. ",result
171+
STOP
172+
ENDIF
173+
174+
IF (!isWebview)
175+
ALERT STOP,"This program requires WebView support.",result
176+
STOP
177+
ENDIF
178+
179+
IF (isWebCliApp || isSmallScreen) ; On smaller screens change to % positioning for left and width
180+
SETMODE *PERCENTCONVERT=1
181+
ENDIF
182+
183+
Runtime.SetWebTheme Using 8
184+
FORMLOAD mainForm
185+
186+
htmlFrmMain.SetAsClient
187+
Client.SetUTF8Convert Using 0
188+
189+
CALL LoadSupportHtml USING htmlHctlMain,"html_if_skeleton.html"
190+
191+
CALL HctlSetupEvents
192+
193+
FUNCTIONEND

templates/html_if_skeleton1.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>HTML Iframe Sample</title>
7+
<style>
8+
/*************************************************************
9+
Custom Styles
10+
**************************************************************/
11+
</style>
12+
</head>
13+
14+
<body>
15+
<!-- Main HTML content -->
16+
<div class="container mt-5">
17+
<h2>Sample Iframe</h2>
18+
<div class="mb-3">
19+
<div id='plbMessage'>Hello from iframe</div>
20+
</div>
21+
</div>
22+
23+
<!-- Custom Code -->
24+
<script type="text/javascript">
25+
/*
26+
* Handle message requests
27+
*/
28+
window.addEventListener('message', (event) => {
29+
var rMsg;
30+
const msgData = event.data.slice(0,10);
31+
if ( msgData == '{"plbmsg":' ) {
32+
try {
33+
rMsg = JSON.parse(event.data);
34+
}
35+
catch (exception) {
36+
console.log(exception);
37+
return;
38+
}
39+
alert( "iframe msg: " + event.data );
40+
switch (rMsg.plbmsg) {
41+
case 1:
42+
document.getElementById('plbMessage').innerText = rMsg.arg2;
43+
break;
44+
}
45+
}
46+
});
47+
48+
</script>
49+
</body>
50+
</html>

templates/html_ui_skeleton.html

Lines changed: 37 additions & 0 deletions

templates/html_ui_skeleton.plf

3.54 KB
Binary file not shown.

0 commit comments

Comments
 (0)