|
13 | 13 | See the License for the specific language governing permissions and |
14 | 14 | limitations under the License. |
15 | 15 | --> |
16 | | -<!DOCTYPE html> |
| 16 | +<!doctype html> |
17 | 17 | <html lang="en"> |
18 | | -<head> |
| 18 | + <head> |
19 | 19 | <title>Example Widget</title> |
20 | 20 |
|
21 | 21 | <!-- |
|
42 | 42 |
|
43 | 43 | <!-- CSS is just for aesthetics and not important to the example --> |
44 | 44 | <link href="index.css" rel="stylesheet" /> |
45 | | -</head> |
46 | | -<body> |
| 45 | + </head> |
| 46 | + <body> |
47 | 47 | <!-- The widget will be loaded into this container --> |
48 | 48 | <div id="container">Loading...</div> |
49 | 49 |
|
|
55 | 55 |
|
56 | 56 | <!-- The actual widget functionality --> |
57 | 57 | <script type="text/javascript"> |
58 | | - try { |
| 58 | + try { |
59 | 59 | const qs = parseFragment(); |
60 | | - const widgetId = assertParam(qs, 'widgetId'); |
61 | | - const userId = assertParam(qs, 'userId'); |
| 60 | + const widgetId = assertParam(qs, "widgetId"); |
| 61 | + const userId = assertParam(qs, "userId"); |
62 | 62 | // Allow all origins |
63 | | - const targetOrigin = '*'; |
| 63 | + const targetOrigin = "*"; |
64 | 64 | let isSticky = false; |
65 | 65 |
|
66 | 66 | // Set up the widget API as soon as possible to avoid problems with the client |
67 | 67 | const widgetApi = new mxwidgets.WidgetApi(widgetId, targetOrigin); |
68 | 68 | widgetApi.requestCapability(mxwidgets.MatrixCapabilities.AlwaysOnScreen); |
69 | 69 |
|
70 | | - widgetApi.on("ready", function() { |
71 | | - // Fill in the basic widget details now that we're allowed to operate. |
72 | | - document.getElementById("container").innerHTML = "Hello <span id='userId'></span>!<br /><br />" |
73 | | - + "Currently stuck on screen: <span id='stickyState'></span><br /><br />" |
74 | | - + "<button onclick='toggleSticky()'>Toggle sticky state</button>"; |
| 70 | + widgetApi.on("ready", function () { |
| 71 | + // Fill in the basic widget details now that we're allowed to operate. |
| 72 | + document.getElementById("container").innerHTML = |
| 73 | + "Hello <span id='userId'></span>!<br /><br />" + |
| 74 | + "Currently stuck on screen: <span id='stickyState'></span><br /><br />" + |
| 75 | + "<button onclick='toggleSticky()'>Toggle sticky state</button>"; |
75 | 76 |
|
76 | | - // Fill in the user ID using innerText to avoid XSS |
77 | | - document.getElementById("userId").innerText = userId; |
| 77 | + // Fill in the user ID using innerText to avoid XSS |
| 78 | + document.getElementById("userId").innerText = userId; |
78 | 79 |
|
79 | | - // Update the UI and ensure that we end up not sticky to start |
80 | | - sendStickyState(); |
| 80 | + // Update the UI and ensure that we end up not sticky to start |
| 81 | + sendStickyState(); |
81 | 82 | }); |
82 | 83 |
|
83 | 84 | // Start the widget as soon as possible too, otherwise the client might time us out. |
84 | 85 | widgetApi.start(); |
85 | 86 |
|
86 | 87 | function toggleSticky() { |
87 | | - // called by the button when clicked - toggle the sticky state |
88 | | - isSticky = !isSticky; |
89 | | - sendStickyState(); |
| 88 | + // called by the button when clicked - toggle the sticky state |
| 89 | + isSticky = !isSticky; |
| 90 | + sendStickyState(); |
90 | 91 | } |
91 | 92 |
|
92 | 93 | function updateStickyState() { |
93 | | - document.getElementById("stickyState").innerText = isSticky.toString(); |
| 94 | + document.getElementById("stickyState").innerText = isSticky.toString(); |
94 | 95 | } |
95 | 96 |
|
96 | 97 | function sendStickyState() { |
97 | | - updateStickyState(); // update first to make the UI go faster than the request |
98 | | - widgetApi.setAlwaysOnScreen(isSticky).then(function(r) { |
99 | | - console.log("[Widget] Client responded with: ", r); |
100 | | - }).catch(function(e) { |
101 | | - handleError(e); |
| 98 | + updateStickyState(); // update first to make the UI go faster than the request |
| 99 | + widgetApi |
| 100 | + .setAlwaysOnScreen(isSticky) |
| 101 | + .then(function (r) { |
| 102 | + console.log("[Widget] Client responded with: ", r); |
| 103 | + }) |
| 104 | + .catch(function (e) { |
| 105 | + handleError(e); |
102 | 106 | }); |
103 | 107 | } |
104 | | - } catch (e) { |
| 108 | + } catch (e) { |
105 | 109 | handleError(e); |
106 | | - } |
| 110 | + } |
107 | 111 | </script> |
108 | | -</body> |
| 112 | + </body> |
109 | 113 | </html> |
0 commit comments