MCPcopy
hub / github.com/1j01/jspaint / file_load_from_url

Function file_load_from_url

src/functions.js:1111–1145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1109/** @type {OSGUI$Window} */
1110let $file_load_from_url_window;
1111function 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.

Callers 1

menus.jsFile · 0.90

Calls 10

$DialogWindowFunction · 0.90
localizeFunction · 0.85
get_urisFunction · 0.85
change_url_paramFunction · 0.85
show_error_messageFunction · 0.85
titleMethod · 0.80
centerMethod · 0.80
closeMethod · 0.65
$ButtonMethod · 0.65
focusMethod · 0.65

Tested by

no test coverage detected