aboutsummaryrefslogtreecommitdiff
path: root/public/js/gogs.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/gogs.js')
-rw-r--r--public/js/gogs.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/public/js/gogs.js b/public/js/gogs.js
index 4eefff5c..6f091cb7 100644
--- a/public/js/gogs.js
+++ b/public/js/gogs.js
@@ -1262,6 +1262,12 @@ $(document).ready(function () {
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
});
+ // Autosize
+ if ($('#description.autosize').length > 0) {
+ autosize($('#description'));
+ showMessageMaxLength(512, 'description', 'descLength');
+ }
+
// AJAX load buttons
$('.ajax-load-button').click(function () {
var $this = $(this);
@@ -1443,3 +1449,42 @@ $(function () {
if ($('.user.signin').length > 0) return;
$('form').areYouSure();
});
+
+ // getByteLen counts bytes in a string's UTF-8 representation.
+function getByteLen(normalVal) {
+ // Force string type
+ normalVal = String(normalVal);
+
+ var byteLen = 0;
+ for (var i = 0; i < normalVal.length; i++) {
+ var c = normalVal.charCodeAt(i);
+ byteLen += c < (1 << 7) ? 1 :
+ c < (1 << 11) ? 2 :
+ c < (1 << 16) ? 3 :
+ c < (1 << 21) ? 4 :
+ c < (1 << 26) ? 5 :
+ c < (1 << 31) ? 6 : Number.NaN;
+ }
+ return byteLen;
+}
+
+function showMessageMaxLength(maxLen, textElemId, counterId) {
+ var $msg = $('#'+textElemId);
+ $('#'+counterId).html(maxLen - getByteLen($msg.val()));
+
+ var onMessageKey = function (e) {
+ var $msg = $(this);
+ var text = $msg.val();
+ var len = getByteLen(text);
+ var remainder = maxLen - len;
+
+ if (len >= maxLen) {
+ $msg.val($msg.val().substr(0, maxLen));
+ remainder = 0;
+ }
+
+ $('#'+counterId).html(remainder);
+ };
+
+ $msg.keyup(onMessageKey).keydown(onMessageKey);
+}