diff --git a/app/modules/project/templates/project/inbox.html b/app/modules/project/templates/project/inbox.html index 2e71266..81acc30 100644 --- a/app/modules/project/templates/project/inbox.html +++ b/app/modules/project/templates/project/inbox.html @@ -45,5 +45,5 @@ {% endif %} - + {% endblock %} diff --git a/app/modules/project/templates/project/index.html b/app/modules/project/templates/project/index.html index 30360e9..7d6203e 100644 --- a/app/modules/project/templates/project/index.html +++ b/app/modules/project/templates/project/index.html @@ -376,5 +376,5 @@ - + {% endblock %} diff --git a/app/modules/project/templates/project/project.html b/app/modules/project/templates/project/project.html index a4b77ea..87b0deb 100644 --- a/app/modules/project/templates/project/project.html +++ b/app/modules/project/templates/project/project.html @@ -379,5 +379,5 @@ - + {% endblock %} diff --git a/app/static/project.js b/app/static/project.js index bcd1a53..b786432 100644 --- a/app/static/project.js +++ b/app/static/project.js @@ -2079,15 +2079,34 @@ } } + // 삽입 전 원본 크기를 확인해, 설명란보다 넓으면 90%로 줄여서 넣는다 + // (그대로 넣으면 크기조절 핸들이 설명란 밖으로 삐져나간다). + function naturalImageSize(file) { + return new Promise(function (resolve) { + const url = URL.createObjectURL(file); + const img = new Image(); + img.onload = function () { URL.revokeObjectURL(url); resolve({ width: img.naturalWidth }); }; + img.onerror = function () { URL.revokeObjectURL(url); resolve(null); }; + img.src = url; + }); + } + async function insertImageFile(file) { if (!taskId) { alert("먼저 저장한 뒤 이미지를 추가할 수 있습니다."); return; } const fd = new FormData(); fd.append("file", file); try { - const res = await fetch("/project/api/tasks/" + taskId + "/attachments", { method: "POST", body: fd }); + const results = await Promise.all([ + naturalImageSize(file), + fetch("/project/api/tasks/" + taskId + "/attachments", { method: "POST", body: fd }), + ]); + const dims = results[0], res = results[1]; if (!res.ok) { let m = res.statusText; try { m = (await res.json()).detail; } catch (_) {} throw new Error(m); } const data = await res.json(); - insertHtmlAtCursor(''); + const boxW = box.clientWidth || 0; + const widthAttr = (dims && dims.width && boxW && dims.width > boxW) + ? ' width="' + Math.round(boxW * 0.9) + '"' : ""; + insertHtmlAtCursor(''); } catch (e) { alert("이미지 업로드 실패: " + e.message); } }