diff --git a/src/main/resources/static/cmn/js/agent/init.js b/src/main/resources/static/cmn/js/agent/init.js index 867b946..6c01356 100644 --- a/src/main/resources/static/cmn/js/agent/init.js +++ b/src/main/resources/static/cmn/js/agent/init.js @@ -58,6 +58,7 @@ $(function () { // 내용 $message.val(msg); + updateByteCount($message); if (msgType === 'L' ||msgType === 'M' @@ -112,8 +113,41 @@ $(function () { icon.removeClass('fa-times-circle').addClass('fa-info-circle'); } }); + + + + $('textarea').on('input', function() { + updateByteCount(this); + }); + }); +// function updateByteCount(textarea) { +// console.log('textarea : ', textarea); +// var text = $(textarea).val(); +// var byteLength = new TextEncoder().encode(text).length; +// $(textarea).closest('.form-group').find('.byte-count').text(byteLength + ' bytes'); +// } +function updateByteCount(textarea) { + var text = $(textarea).val(); + var byteLength = calculateByteLength(text); + $(textarea).closest('.form-group').find('.byte-count').text(byteLength + ' bytes'); +} + +function calculateByteLength(text) { + var byteLength = 0; + for (var i = 0; i < text.length; i++) { + var charCode = text.charCodeAt(i); + if (charCode <= 0x007F) { + byteLength += 1; // 1 byte for ASCII characters + } else if (charCode <= 0x07FF) { + byteLength += 2; // 2 bytes for characters from U+0080 to U+07FF + } else { + byteLength += 2; // 2 bytes for characters from U+0800 and above (including Hangul) + } + } + return byteLength; +} function getParentsId($obj){ var $col = $obj.closest('.col-md-6'); // 클릭한 버튼의 가장 가까운 부모 .card 요소 찾기 @@ -132,4 +166,4 @@ function getNowDate(){ var minutes = ('0' + now.getMinutes()).slice(-2); // 분 return year + month + day + '|' + hours + ':' + minutes; -} +} \ No newline at end of file diff --git a/src/main/resources/templates/agent/view.html b/src/main/resources/templates/agent/view.html index 3f729ab..147bc55 100644 --- a/src/main/resources/templates/agent/view.html +++ b/src/main/resources/templates/agent/view.html @@ -15,6 +15,14 @@