|
7 | 7 | <meta charset="utf-8"> |
8 | 8 |
|
9 | 9 | <script> |
10 | | - // PEB page settings: |
11 | | - var pebSettings = {}; // 'pebSettings' object name is hard-coded. |
12 | | - pebSettings.autoStartScripts = ['clock_one', 'clock_two']; |
13 | | - pebSettings.cutLabel = '- Cut -'; |
14 | | - pebSettings.copyLabel = '- Copy -'; |
15 | | - pebSettings.pasteLabel = '- Paste -'; |
16 | | - pebSettings.selectAllLabel = '- Select All -'; |
17 | | - pebSettings.okLabel = 'OK'; |
18 | | - pebSettings.cancelLabel = 'CANCEL'; |
19 | | - pebSettings.yesLabel = 'YES'; |
20 | | - pebSettings.noLabel = 'NO'; |
21 | | - pebSettings.closeConfirmation = |
22 | | - 'Text was entered in a form and it is going to be lost!\n' + |
23 | | - 'Are you sure you want to close the application?'; |
24 | | - |
25 | | - // Settings objects for the Perl scripts: |
26 | | - var perl_input = {}; |
27 | | - perl_input.scriptRelativePath = 'perl-scripts/input.pl'; |
28 | | - perl_input.inputData = function() { |
29 | | - var data = document.getElementById('perl-input-box').value; |
30 | | - $('#perl-input').trigger('reset'); |
31 | | - return data; |
| 10 | + // PEB page settings: |
| 11 | + var pebSettings = {}; // 'pebSettings' object name is hard-coded. |
| 12 | + pebSettings.autoStartScripts = ['interactive_one', 'interactive_two']; |
| 13 | + pebSettings.cutLabel = '- Cut -'; |
| 14 | + pebSettings.copyLabel = '- Copy -'; |
| 15 | + pebSettings.pasteLabel = '- Paste -'; |
| 16 | + pebSettings.selectAllLabel = '- Select All -'; |
| 17 | + pebSettings.okLabel = 'OK'; |
| 18 | + pebSettings.cancelLabel = 'CANCEL'; |
| 19 | + pebSettings.yesLabel = 'YES'; |
| 20 | + pebSettings.noLabel = 'NO'; |
| 21 | + pebSettings.closeConfirmation = |
| 22 | + 'Text was entered in a form and it is going to be lost!\n' + |
| 23 | + 'Are you sure you want to close the application?'; |
| 24 | + |
| 25 | + // Settings objects for Perl scripts |
| 26 | + // Interactive script: |
| 27 | + var messenger_one = {}; |
| 28 | + messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl'; |
| 29 | + messenger_one.inputData = function() { |
| 30 | + var message = {}; |
| 31 | + if(("tempfile" in messenger_one)) { |
| 32 | + message.tempfile = messenger_one.tempfile; |
| 33 | + } |
| 34 | + message.user_input = document.getElementById("interactive-one-input").value; |
| 35 | + $('#form-one').trigger('reset'); |
| 36 | + return JSON.stringify(message); |
32 | 37 | } |
33 | | - perl_input.stdoutFunction = function (stdout) { |
34 | | - var target = document.getElementById('user-data-perl-output'); |
35 | | - target.innerText = 'Last user input: ' + stdout; |
| 38 | + |
| 39 | + var messenger_two = {}; |
| 40 | + messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl'; |
| 41 | + messenger_two.inputData = function() { |
| 42 | + var message = {}; |
| 43 | + if(("tempfile" in messenger_two)) { |
| 44 | + message.tempfile = messenger_two.tempfile; |
| 45 | + } |
| 46 | + message.user_input = document.getElementById("interactive-two-input").value; |
| 47 | + $('#form-two').trigger('reset'); |
| 48 | + return JSON.stringify(message); |
36 | 49 | } |
37 | 50 |
|
38 | | - var clock_one = {}; |
39 | | - clock_one.scriptRelativePath = 'perl-scripts/clock.pl'; |
40 | | - clock_one.inputData = function() { |
41 | | - return "unix-epoch"; |
| 51 | + var interactive_one = {}; |
| 52 | + interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl'; |
| 53 | + interactive_one.inputData = function() { |
| 54 | + var input = {}; |
| 55 | + input.mode = "unix-epoch"; |
| 56 | + return JSON.stringify(input); |
42 | 57 | } |
43 | | - clock_one.stdoutFunction = function (stdout) { |
44 | | - var target = document.getElementById('clock-one-output'); |
45 | | - target.innerHTML = stdout; |
| 58 | + interactive_one.stdoutFunction = function (stdout) { |
| 59 | + var target = document.getElementById('instance-one-output'); |
| 60 | + var output = JSON.parse(stdout); |
| 61 | + var html; |
| 62 | + messenger_one.tempfile = output.tempfile; |
| 63 | + if(("user_input" in output)) { |
| 64 | + if (output.user_input != undefined) { |
| 65 | + html = output.time + '<br>' + output.user_input; |
| 66 | + } else { |
| 67 | + html = output.time; |
| 68 | + } |
| 69 | + target.innerHTML = html; |
| 70 | + }; |
46 | 71 | } |
47 | 72 |
|
48 | | - var clock_two = {}; |
49 | | - clock_two.scriptRelativePath = 'perl-scripts/clock.pl'; |
50 | | - clock_two.inputData = function() { |
51 | | - return "local-time"; |
| 73 | + var interactive_two = {}; |
| 74 | + interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl'; |
| 75 | + interactive_two.inputData = function() { |
| 76 | + var input = {}; |
| 77 | + input.mode = "local-time"; |
| 78 | + return JSON.stringify(input); |
52 | 79 | } |
53 | | - clock_two.stdoutFunction = function (stdout) { |
54 | | - var target = document.getElementById('clock-two-output'); |
55 | | - target.innerHTML = stdout; |
| 80 | + interactive_two.stdoutFunction = function (stdout) { |
| 81 | + var target = document.getElementById('instance-two-output'); |
| 82 | + var output = JSON.parse(stdout); |
| 83 | + var html; |
| 84 | + messenger_two.tempfile = output.tempfile; |
| 85 | + if(("user_input" in output)) { |
| 86 | + if (output.user_input != undefined) { |
| 87 | + html = output.time + '<br>' + output.user_input; |
| 88 | + } else { |
| 89 | + html = output.time; |
| 90 | + } |
| 91 | + target.innerHTML = html; |
| 92 | + }; |
56 | 93 | } |
57 | 94 |
|
| 95 | + // Other PEB tests: |
58 | 96 | var open_file = {}; |
59 | 97 | open_file.scriptRelativePath = 'perl-scripts/open-files.pl'; |
60 | 98 | open_file.stdoutFunction = function (stdout) { |
|
189 | 227 | font-size: 20px; |
190 | 228 | } |
191 | 229 |
|
192 | | - .output { |
| 230 | + .interactive-output { |
193 | 231 | font-size: 20px; |
| 232 | + margin-bottom: 20px; |
194 | 233 | } |
195 | 234 | </style> |
196 | 235 | </head> |
|
246 | 285 | </ul> |
247 | 286 | </li> |
248 | 287 |
|
249 | | - <li><a href="javascript:location.reload();">Reload</a></li> |
250 | | - |
251 | 288 | <li><a href="https://www.google.com/">Google</a></li> |
252 | 289 |
|
253 | 290 | <li class="dropdown"> |
@@ -277,40 +314,52 @@ <h2>Perl Executing Browser</h2> |
277 | 314 | </div> |
278 | 315 | </div> |
279 | 316 |
|
280 | | - <div class="row"> |
281 | | - |
282 | | - </div> |
| 317 | + <h3>Interactive Script Demo</h3> |
283 | 318 |
|
284 | 319 | <div class="row"> |
285 | 320 | <div class="col-xs-12 form-group"> |
286 | | - <form action="perl_input.script" id="perl-input"> |
| 321 | + <form action="messenger_one.script" id="form-one"> |
287 | 322 | <div class="input-group"> |
288 | | - <input type="text" id="perl-input-box" class="form-control" |
289 | | - placeholder="Press Enter to send data to Perl script"> |
| 323 | + <input type="text" id="interactive-one-input" name="input" class="form-control" |
| 324 | + placeholder="Press Enter to send data to the first interactive script instance"> |
290 | 325 |
|
291 | 326 | <span class="input-group-addon btn btn-primary" |
292 | | - onclick="javascript:$('#perl-input').trigger('reset');"> |
| 327 | + onclick="javascript:$('#form-one').trigger('reset');"> |
293 | 328 | Reset |
294 | 329 | </span> |
295 | 330 |
|
296 | 331 | <span class="input-group-addon btn btn-primary" |
297 | | - onclick="javascript:$('#perl-input').trigger('submit');"> |
| 332 | + onclick="javascript:$('#form-one').trigger('submit');"> |
298 | 333 | Send |
299 | 334 | </span> |
300 | 335 | </div> |
301 | 336 | </form> |
302 | 337 | </div> |
303 | 338 |
|
304 | | - <div id="user-data-perl-output" class="output">Last user input: none</div> |
| 339 | + <div id="instance-one-output" class="interactive-output"> </div> |
305 | 340 | </div> |
306 | 341 |
|
307 | 342 | <div class="row"> |
308 | | - |
309 | | - </div> |
| 343 | + <div class="col-xs-12 form-group"> |
| 344 | + <form action="messenger_two.script" id="form-two"> |
| 345 | + <div class="input-group"> |
| 346 | + <input type="text" id="interactive-two-input" name="input" class="form-control" |
| 347 | + placeholder="Press Enter to send data to the second interactive script instance"> |
310 | 348 |
|
311 | | - <div class="row"> |
312 | | - <div id="clock-one-output" class="output"> </div> |
313 | | - <div id="clock-two-output" class="output"> </div> |
| 349 | + <span class="input-group-addon btn btn-primary" |
| 350 | + onclick="javascript:$('#form-two').trigger('reset');"> |
| 351 | + Reset |
| 352 | + </span> |
| 353 | + |
| 354 | + <span class="input-group-addon btn btn-primary" |
| 355 | + onclick="javascript:$('#form-two').trigger('submit');"> |
| 356 | + Send |
| 357 | + </span> |
| 358 | + </div> |
| 359 | + </form> |
| 360 | + </div> |
| 361 | + |
| 362 | + <div id="instance-two-output" class="interactive-output"> </div> |
314 | 363 | </div> |
315 | 364 | </div> |
316 | 365 | </body> |
|
0 commit comments