()
| 1109 | /** @type {OSGUI$Window} */ |
| 1110 | let $file_load_from_url_window; |
| 1111 | function file_load_from_url() { |
| 1112 | if ($file_load_from_url_window) { |
| 1113 | $file_load_from_url_window.close(); |
| 1114 | } |
| 1115 | const $w = $DialogWindow().addClass("horizontal-buttons"); |
| 1116 | $file_load_from_url_window = $w; |
| 1117 | $w.title("Load from URL"); |
| 1118 | // @TODO: URL validation (input has to be in a form (and we don't want the form to submit)) |
| 1119 | $w.$main.html(` |
| 1120 | <div style="padding: 10px;"> |
| 1121 | <label style="display: block; margin-bottom: 5px;" for="url-input">Paste or type the web address of an image:</label> |
| 1122 | <input type="url" required value="" id="url-input" class="inset-deep" style="width: 300px;"/></label> |
| 1123 | </div> |
| 1124 | `); |
| 1125 | const $input = $w.$main.find("#url-input"); |
| 1126 | // $w.$Button("Load", () => { |
| 1127 | $w.$Button(localize("Open"), () => { |
| 1128 | const uris = get_uris(String($input.val())); |
| 1129 | if (uris.length > 0) { |
| 1130 | // @TODO: retry loading if same URL entered |
| 1131 | // actually, make it change the hash only after loading successfully |
| 1132 | // (but still load from the hash when necessary) |
| 1133 | // make sure it doesn't overwrite the old session before switching |
| 1134 | $w.close(); |
| 1135 | change_url_param("load", uris[0]); |
| 1136 | } else { |
| 1137 | show_error_message("Invalid URL. It must include a protocol (https:// or http://)"); |
| 1138 | } |
| 1139 | }, { type: "submit" }); |
| 1140 | $w.$Button(localize("Cancel"), () => { |
| 1141 | $w.close(); |
| 1142 | }); |
| 1143 | $w.center(); |
| 1144 | $input[0].focus(); |
| 1145 | } |
| 1146 | |
| 1147 | // Native FS API / File Access API allows you to overwrite files, but people are not used to it. |
| 1148 | // So we ask them to confirm it the first time. |
no test coverage detected