|
19 | 19 | .slider.round {border-radius: 34px} |
20 | 20 | .slider.round:before {border-radius: 50%} |
21 | 21 | input:disabled+.slider {background-color: #aaa} |
| 22 | + |
| 23 | + dialog[open] { |
| 24 | + font-family: verdana; |
| 25 | + font-size: 28px; |
| 26 | + color: white; |
| 27 | + background-color:rgb(200 0 0 / 0.90); |
| 28 | + border: solid rgb(200 0 0 / 0.90) 0px; |
| 29 | + border-radius: 12px; |
| 30 | + /* |
| 31 | + position: absolute; |
| 32 | + left: 50%; |
| 33 | + top: 50%; |
| 34 | + transform: translate(-50%, -50%); |
| 35 | + */ |
| 36 | + } |
| 37 | + |
22 | 38 | </style> |
23 | 39 |
|
24 | 40 | <body> |
25 | 41 |
|
26 | 42 | <br><h1>Example 04 - user interface with style</h1> |
27 | | - |
28 | 43 | <hr /> |
| 44 | + |
| 45 | + <!-- error message --> |
| 46 | + <dialog id="errDialog"></dialog> |
| 47 | + |
29 | 48 | <div class='d1'> |
30 | 49 | <div class='d2'> Led</div> |
31 | 50 | <div class='d3'> |
|
36 | 55 |
|
37 | 56 | <script type='text/javascript'> |
38 | 57 |
|
39 | | - // mechanism that makes REST calls and get their replies |
40 | | - var httpClient = function () { |
41 | | - this.request = function (url, method, callback) { |
42 | | - var httpRequest = new XMLHttpRequest (); |
43 | | - var httpRequestTimeout = null; |
44 | | - |
45 | | - httpRequest.onreadystatechange = function () { |
46 | | - // console.log (httpRequest.readyState); |
47 | | - if (httpRequest.readyState == 1) { // 1 = OPENED, start timing |
48 | | - clearTimeout (httpRequestTimeout); |
49 | | - httpRequestTimeout = setTimeout (function () { |
50 | | - alert ('Server did not reply (in time).'); |
51 | | - // errorMessage ('Server did not reply (in time).'); |
52 | | - }, 5000); |
53 | | - } |
54 | | - if (httpRequest.readyState == 4) { // 4 = DONE, call callback function with responseText |
55 | | - clearTimeout (httpRequestTimeout); |
56 | | - if (httpRequest.status == 200) { |
57 | | - callback (httpRequest.responseText); // 200 = OK |
58 | | - } else { |
59 | | - alert ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); // some other reply status, like 404, 503, ... |
60 | | - // errorMessage ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); |
| 58 | + // mechanism that makes REST calls and get their replies |
| 59 | + var httpClient = function () { |
| 60 | + this.request = function (url, method, callback) { |
| 61 | + var httpRequest = new XMLHttpRequest (); |
| 62 | + var httpRequestTimeout = null; |
| 63 | + |
| 64 | + httpRequest.onreadystatechange = function () { |
| 65 | + // console.log (httpRequest.readyState); |
| 66 | + if (httpRequest.readyState == 1) { // 1 = OPENED, start timing |
| 67 | + clearTimeout (httpRequestTimeout); |
| 68 | + httpRequestTimeout = setTimeout (function () { |
| 69 | + // alert ('Server did not reply (in time).'); |
| 70 | + errorMessage ('Server did not reply (in time).'); |
| 71 | + }, 5000); |
| 72 | + } |
| 73 | + if (httpRequest.readyState == 4) { // 4 = DONE, call callback function with responseText |
| 74 | + clearTimeout (httpRequestTimeout); |
| 75 | + switch (httpRequest.status) { |
| 76 | + case 200: callback (httpRequest.responseText); // 200 = OK |
| 77 | + break; |
| 78 | + case 0: break; |
| 79 | + default: // alert ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); // some other reply status, like 404, 503, ... |
| 80 | + errorMessage ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); |
| 81 | + break; |
| 82 | + } |
61 | 83 | } |
62 | 84 | } |
| 85 | + httpRequest.open (method, url, true); |
| 86 | + httpRequest.send (null); |
63 | 87 | } |
64 | | - httpRequest.open (method, url, true); |
65 | | - httpRequest.send (null); |
66 | 88 | } |
67 | | - } |
68 | 89 |
|
69 | | - var client = new httpClient (); |
| 90 | + var client = new httpClient (); |
70 | 91 |
|
| 92 | + // error message |
| 93 | + var errorMessageTimeout = null; |
| 94 | + function errorMessage (msg) { |
| 95 | + clearTimeout (errorMessageTimeout); |
| 96 | + document.getElementById ('errDialog').textContent = msg; |
| 97 | + document.getElementById ('errDialog').showModal (); |
| 98 | + errorMessageTimeout = setTimeout (function () { |
| 99 | + document.getElementById ('errDialog').close (); |
| 100 | + }, 3000); |
| 101 | + } |
71 | 102 |
|
72 | 103 | // make a REST call and initialize/populate this page |
73 | 104 | var client = new httpClient (); |
|
0 commit comments