mirror of https://github.com/gogs/gogs.git
repo: minor improve for PR #5219 and support UTF-8 byte count
parent
57897cc8c2
commit
dfd494c113
pkg
bindata
context
public
js
plugins/autosize-4.0.2
routes/repo
templates
2
gogs.go
2
gogs.go
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/gogs/gogs/pkg/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.11.55.0609"
|
||||
const APP_VER = "0.11.56.0611"
|
||||
|
||||
func init() {
|
||||
setting.AppVer = APP_VER
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -68,6 +68,10 @@ func (c *Context) RequireSimpleMDE() {
|
|||
c.Require("SimpleMDE")
|
||||
}
|
||||
|
||||
func (c *Context) RequireAutosize() {
|
||||
c.Require("Autosize")
|
||||
}
|
||||
|
||||
// FormErr sets "Err_xxx" field in template data.
|
||||
func (c *Context) FormErr(names ...string) {
|
||||
for i := range names {
|
||||
|
|
|
@ -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);
|
||||
|
@ -1444,14 +1450,32 @@ $(function () {
|
|||
$('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); //text message
|
||||
$('#'+counterId).html(maxLen - $msg.val().length); //symbols count
|
||||
var $msg = $('#'+textElemId);
|
||||
$('#'+counterId).html(maxLen - getByteLen($msg.val()));
|
||||
|
||||
var onMessageKey = function (e) {
|
||||
var $msg = $(this);
|
||||
var text = $msg.val();
|
||||
var len = text.length;
|
||||
var len = getByteLen(text);
|
||||
var remainder = maxLen - len;
|
||||
|
||||
if (len >= maxLen) {
|
||||
|
|
|
@ -66,7 +66,8 @@ func checkContextUser(c *context.Context, uid int64) *models.User {
|
|||
}
|
||||
|
||||
func Create(c *context.Context) {
|
||||
c.Data["Title"] = c.Tr("new_repo")
|
||||
c.Title("new_repo")
|
||||
c.RequireAutosize()
|
||||
|
||||
// Give default value for template to render.
|
||||
c.Data["Gitignores"] = models.Gitignores
|
||||
|
@ -75,7 +76,6 @@ func Create(c *context.Context) {
|
|||
c.Data["readme"] = "Default"
|
||||
c.Data["private"] = c.User.LastRepoVisibility
|
||||
c.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
|
||||
c.Data["RequireAutosize"] = true
|
||||
|
||||
ctxUser := checkContextUser(c, c.QueryInt64("org"))
|
||||
if c.Written() {
|
||||
|
|
|
@ -34,7 +34,7 @@ const (
|
|||
func Settings(c *context.Context) {
|
||||
c.Title("repo.settings")
|
||||
c.PageIs("SettingsOptions")
|
||||
c.Data["RequireAutosize"] = true
|
||||
c.RequireAutosize()
|
||||
c.Success(SETTINGS_OPTIONS)
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.11.55.0609
|
||||
0.11.56.0611
|
|
@ -49,6 +49,9 @@
|
|||
<link rel="stylesheet" href="{{AppSubURL}}/plugins/dropzone-4.2.0/dropzone.css">
|
||||
<script src="{{AppSubURL}}/plugins/dropzone-4.2.0/dropzone.js"></script>
|
||||
{{end}}
|
||||
{{if .RequireAutosize}}
|
||||
<script src="{{AppSubURL}}/plugins/autosize-4.0.2/autosize.min.js"></script>
|
||||
{{end}}
|
||||
<script src="{{AppSubURL}}/js/libs/emojify-1.1.0.min.js"></script>
|
||||
<script src="{{AppSubURL}}/js/libs/clipboard-1.5.9.min.js"></script>
|
||||
|
||||
|
|
|
@ -41,9 +41,7 @@
|
|||
<script src="{{AppSubURL}}/js/libs/jquery.are-you-sure.js"></script>
|
||||
<link rel="stylesheet" href="{{AppSubURL}}/assets/font-awesome-4.6.3/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="{{AppSubURL}}/assets/octicons-4.3.0/octicons.min.css">
|
||||
{{if .RequireAutosize}}
|
||||
<script src="{{AppSubURL}}/plugins/autosize-4.0.2/dist/autosize.min.js"></script>
|
||||
{{end}}
|
||||
|
||||
<!-- notebook.js for rendering ipython notebooks and marked.js for rendering markdown in notebooks -->
|
||||
{{if .IsIPythonNotebook}}
|
||||
<script src="{{AppSubURL}}/plugins/notebookjs-0.3.0/notebook.min.js"></script>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</div>
|
||||
<div class="inline field {{if .Err_Description}}error{{end}}">
|
||||
<label for="description">{{.i18n.Tr "repo.repo_desc"}}</label>
|
||||
<textarea id="description" name="description" rows="3">{{.description}}</textarea>
|
||||
<textarea class="autosize" id="description" name="description" rows="3">{{.description}}</textarea>
|
||||
<span class="help">{{.i18n.Tr "repo.repo_description_helper" | Safe}}</span>
|
||||
<span class="help">{{.i18n.Tr "repo.repo_description_length"}}: <span id="descLength"></span></span>
|
||||
</div>
|
||||
|
@ -116,13 +116,4 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
if (typeof window.autosize !== "undefined") {
|
||||
autosize($('#description'));
|
||||
}
|
||||
showMessageMaxLength(512, 'description', 'descLength');
|
||||
});
|
||||
</script>
|
||||
|
||||
{{template "base/footer" .}}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</div>
|
||||
<div class="field {{if .Err_Description}}error{{end}}">
|
||||
<label for="description">{{$.i18n.Tr "repo.repo_desc"}}</label>
|
||||
<textarea id="description" name="description" rows="3">{{.Repository.Description}}</textarea>
|
||||
<textarea class="autosize" id="description" name="description" rows="3">{{.Repository.Description}}</textarea>
|
||||
<p class="help">{{.i18n.Tr "repo.settings.description_desc"}}</p>
|
||||
<p class="help">{{.i18n.Tr "repo.settings.description_length"}}: <span id="descLength"></span></p>
|
||||
</div>
|
||||
|
@ -417,13 +417,4 @@
|
|||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
if (typeof window.autosize !== "undefined") {
|
||||
autosize($('#description'));
|
||||
}
|
||||
showMessageMaxLength(512, 'description', 'descLength');
|
||||
});
|
||||
</script>
|
||||
|
||||
{{template "base/footer" .}}
|
||||
|
|
Loading…
Reference in New Issue