mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 03:17:56 +01:00
Fix #281. Add mouse-over precise time and on-click switch listener.
This commit is contained in:
parent
c20f5dc2ea
commit
835e85b5ce
4 changed files with 81 additions and 2 deletions
|
@ -192,6 +192,12 @@ MAX_SIZE
|
||||||
; Max number of files per upload. Defaults to 10
|
; Max number of files per upload. Defaults to 10
|
||||||
MAX_FILES =
|
MAX_FILES =
|
||||||
|
|
||||||
|
[time]
|
||||||
|
; Specifies the format for fully outputed dates. Defaults to RFC1123
|
||||||
|
; Special supported values are ANSIC, UnixDate, RubyDate, RFC822, RFC822Z, RFC850, RFC1123, RFC1123Z, RFC3339, RFC3339Nano, Kitchen, Stamp, StampMilli, StampMicro and StampNano
|
||||||
|
; For more information about the format see http://golang.org/pkg/time/#pkg-constants
|
||||||
|
FORMAT =
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
ROOT_PATH =
|
ROOT_PATH =
|
||||||
; Either "console", "file", "conn", "smtp" or "database", default is "console"
|
; Either "console", "file", "conn", "smtp" or "database", default is "console"
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
|
"html/template"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -239,8 +240,8 @@ func TimeSincePro(then time.Time) string {
|
||||||
return strings.TrimPrefix(timeStr, ", ")
|
return strings.TrimPrefix(timeStr, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeSince calculates the time interval and generate user-friendly string.
|
// timeSince calculates the time interval and generate user-friendly string.
|
||||||
func TimeSince(then time.Time) string {
|
func timeSince(then time.Time) string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
lbl := "ago"
|
lbl := "ago"
|
||||||
|
@ -290,6 +291,11 @@ func TimeSince(then time.Time) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimeSince calculates the time interval and generate user-friendly string.
|
||||||
|
func TimeSince(t time.Time) template.HTML {
|
||||||
|
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`, t.Format(setting.TimeFormat), timeSince(t)))
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Byte = 1
|
Byte = 1
|
||||||
KByte = Byte * 1024
|
KByte = Byte * 1024
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/Unknwon/goconfig"
|
"github.com/Unknwon/goconfig"
|
||||||
|
@ -78,6 +79,9 @@ var (
|
||||||
AttachmentMaxFiles int
|
AttachmentMaxFiles int
|
||||||
AttachmentEnabled bool
|
AttachmentEnabled bool
|
||||||
|
|
||||||
|
// Time settings.
|
||||||
|
TimeFormat string
|
||||||
|
|
||||||
// Cache settings.
|
// Cache settings.
|
||||||
Cache cache.Cache
|
Cache cache.Cache
|
||||||
CacheAdapter string
|
CacheAdapter string
|
||||||
|
@ -179,6 +183,55 @@ func NewConfigContext() {
|
||||||
AttachmentMaxFiles = Cfg.MustInt("attachment", "MAX_FILES", 10)
|
AttachmentMaxFiles = Cfg.MustInt("attachment", "MAX_FILES", 10)
|
||||||
AttachmentEnabled = Cfg.MustBool("attachment", "ENABLE", true)
|
AttachmentEnabled = Cfg.MustBool("attachment", "ENABLE", true)
|
||||||
|
|
||||||
|
TimeFormat = Cfg.MustValue("time", "FORMAT", time.RFC1123)
|
||||||
|
|
||||||
|
switch TimeFormat {
|
||||||
|
case "ANSIC":
|
||||||
|
TimeFormat = time.ANSIC
|
||||||
|
|
||||||
|
case "UnixDate":
|
||||||
|
TimeFormat = time.UnixDate
|
||||||
|
|
||||||
|
case "RubyDate":
|
||||||
|
TimeFormat = time.RubyDate
|
||||||
|
|
||||||
|
case "RFC822":
|
||||||
|
TimeFormat = time.RFC822
|
||||||
|
|
||||||
|
case "RFC822Z":
|
||||||
|
TimeFormat = time.RFC822Z
|
||||||
|
|
||||||
|
case "RFC850":
|
||||||
|
TimeFormat = time.RFC850
|
||||||
|
|
||||||
|
case "RFC1123":
|
||||||
|
TimeFormat = time.RFC1123
|
||||||
|
|
||||||
|
case "RFC1123Z":
|
||||||
|
TimeFormat = time.RFC1123Z
|
||||||
|
|
||||||
|
case "RFC3339":
|
||||||
|
TimeFormat = time.RFC3339
|
||||||
|
|
||||||
|
case "RFC3339Nano":
|
||||||
|
TimeFormat = time.RFC3339Nano
|
||||||
|
|
||||||
|
case "Kitchen":
|
||||||
|
TimeFormat = time.Kitchen
|
||||||
|
|
||||||
|
case "Stamp":
|
||||||
|
TimeFormat = time.Stamp
|
||||||
|
|
||||||
|
case "StampMilli":
|
||||||
|
TimeFormat = time.StampMilli
|
||||||
|
|
||||||
|
case "StampMicro":
|
||||||
|
TimeFormat = time.StampMicro
|
||||||
|
|
||||||
|
case "StampNano":
|
||||||
|
TimeFormat = time.StampNano
|
||||||
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
|
if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
|
||||||
log.Fatal("Could not create directory %s: %s", AttachmentPath, err)
|
log.Fatal("Could not create directory %s: %s", AttachmentPath, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -960,6 +960,18 @@ function initOrganization() {
|
||||||
console.log("init script : organization done");
|
console.log("init script : organization done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initTimeSwitch() {
|
||||||
|
$(".time-since[title]").on("click", function() {
|
||||||
|
var $this = $(this);
|
||||||
|
|
||||||
|
var title = $this.attr("title");
|
||||||
|
var text = $this.text();
|
||||||
|
|
||||||
|
$this.text(title);
|
||||||
|
$this.attr("title", text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
(function ($) {
|
(function ($) {
|
||||||
$(function () {
|
$(function () {
|
||||||
initCore();
|
initCore();
|
||||||
|
@ -988,6 +1000,8 @@ function initOrganization() {
|
||||||
if ($('#body-nav').hasClass("org-nav")) {
|
if ($('#body-nav').hasClass("org-nav")) {
|
||||||
initOrganization();
|
initOrganization();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initTimeSwitch();
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue