Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Refactor: handle duplication by making setTextFontSize function in wi…
Browse files Browse the repository at this point in the history
…ndow.js
  • Loading branch information
JahunSeo committed May 18, 2018
1 parent 14c3ba3 commit b23ac06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function errorHandling(e, err) {
else message += ": 다시 한 번 시도해주세요.";
} else if (errorCode.startsWith('N2MT')) {
message = "번역 오류";
if (errorCode == "N2MT08") message += ": 문장이 너무 길어요!";
if (errorCode == "N2MT08") message += ": 문장이 너무 길어요!"; // up to 5000 characters.
else message += ": 다시 한 번 시도해주세요.";
}
}
Expand Down
44 changes: 18 additions & 26 deletions views/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@ button.onclick = function() {
// should subdivide error handling.
window.document.getElementById("translated-text").value = result;
}

if (result.length > 60) {
window.document.getElementById("translated-text").style.fontSize = "16px";
} else if (result.length > 45) {
window.document.getElementById("translated-text").style.fontSize = "22px";
} else if (result.length > 30) {
window.document.getElementById("translated-text").style.fontSize = "27px";
} else if (result.length > 15) {
window.document.getElementById("translated-text").style.fontSize = "32px";
} else {
window.document.getElementById("translated-text").style.fontSize = "40px";
}
setTextFontSize(result, "translated-text");
});
};

Expand All @@ -40,20 +29,8 @@ const searchPress = function(e) {
};
const search = window.document.getElementById("text");
search.onkeyup = function(event) {
const text = window.document.getElementById("text").value;

if (text.length > 60) {
window.document.getElementById("text").style.fontSize = "16px";
} else if (text.length > 45) {
window.document.getElementById("text").style.fontSize = "22px";
} else if (text.length > 30) {
window.document.getElementById("text").style.fontSize = "27px";
} else if (text.length > 15) {
window.document.getElementById("text").style.fontSize = "32px";
} else {
window.document.getElementById("text").style.fontSize = "40px";
}

const text = window.document.getElementById("text").value;s
setTextFontSize(text, "text");
return searchPress(event);
};

Expand Down Expand Up @@ -99,3 +76,18 @@ function setSourceText(text) {
window.document.getElementById("translated-text").value = text;
return text;
}

function setTextFontSize(text, elementId) {
if (text.length > 60) {
window.document.getElementById(elementId).style.fontSize = "16px";
} else if (text.length > 45) {
window.document.getElementById(elementId).style.fontSize = "22px";
} else if (text.length > 30) {
window.document.getElementById(elementId).style.fontSize = "27px";
} else if (text.length > 15) {
window.document.getElementById(elementId).style.fontSize = "32px";
} else {
window.document.getElementById(elementId).style.fontSize = "40px";
}
return text.length;
}

0 comments on commit b23ac06

Please sign in to comment.