Transpiled version (3428L) is out of date.
1 | sclass HTMLSuggestor { |
2 | S makeData = "{}"; |
3 | S ajaxURL = ""; |
4 | int delay = 1000; |
5 | S installTriggers = ""; |
6 | S onGotResult = ""; |
7 | bool verbose; |
8 | |
9 | S html() { |
10 | if (empty(ajaxURL)) fail("Need ajaxURL"); |
11 | |
12 | ret hscript(replaceDollarVars([[ |
13 | var sugVerbose = $verbose; |
14 | var sugLoading = false, sugTriggerAgain = false; |
15 | |
16 | function sugTrigger() { |
17 | //if (sugVerbose) console.log("sugTrigger"); |
18 | if (sugLoading) { sugTriggerAgain = true; return; } |
19 | |
20 | // get form data as JSON |
21 | |
22 | var data = $makeData; |
23 | |
24 | const url = $calcURL; |
25 | if (sugVerbose) { |
26 | const urlWithParams = url + "?" + new URLSearchParams(data); |
27 | console.log("Loading " + urlWithParams); |
28 | } |
29 | sugLoading = true; |
30 | $.post(url, data, |
31 | function(result) { |
32 | if (sugVerbose) console.log("Suggestor result: " + result); |
33 | const answer = !result ? "" : JSON.parse(result).answer; |
34 | $onGotResult |
35 | if (answer) { |
36 | $("#liveResult .sectionContents").html(answer); |
37 | $("#liveResult").show(); |
38 | } else |
39 | $("#liveResult").hide(); |
40 | //$("#suggestorResult").html(answer ? "Suggestor says: " + answer : ""); |
41 | } |
42 | ).always(function() { |
43 | if (sugVerbose) console.log("sug loading done"); |
44 | setTimeout(function() { |
45 | sugLoading = false; |
46 | if (sugTriggerAgain) { sugTriggerAgain = false; sugTrigger(); } |
47 | }, $delay); |
48 | }); |
49 | } |
50 | |
51 | $(document).ready(function() { |
52 | $installTriggers |
53 | sugTrigger(); |
54 | }); |
55 | ]], +verbose, +delay, +makeData, calcURL := jsQuote(ajaxURL), +installTriggers, +onGotResult)); |
56 | } |
57 | } |
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031628 |
Snippet name: | HTMLSuggestor |
Eternal ID of this version: | #1031628/12 |
Text MD5: | ed2263f465ea2cfbb99989239eef3389 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-24 17:10:02 |
Source code size: | 1809 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 195 / 505 |
Version history: | 11 change(s) |
Referenced in: | [show references] |