Browse Source

browser supports copy detection

pull/1432/head
Fernando San Julián 10 years ago
parent
commit
6a89eeedf3
  1. 2
      .gopmfile
  2. 26
      modules/middleware/repo.go
  3. 2
      templates/ng/base/head.tmpl

2
.gopmfile

@ -33,6 +33,8 @@ golang.org/x/net = commit:937a34c9de13
golang.org/x/text = commit:5b2527008a4c
gopkg.in/ini.v1 = commit:caf3f03ad9
gopkg.in/redis.v2 = commit:e617904962
github.com/hashicorp/go-version = commit:999359b6b7
github.com/mssola/user_agent = commit:f659b98638
[res]
include = etc|public|scripts|templates

26
modules/middleware/repo.go

@ -16,6 +16,14 @@ import (
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
"github.com/hashicorp/go-version"
"github.com/mssola/user_agent"
)
const (
FIREFOX_COPY_SUPPORT = "41.0"
CHROME_COPY_SUPPORT = "43.0.2356"
)
func ApiRepoAssignment() macaron.Handler {
@ -345,6 +353,24 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["BranchName"] = ctx.Repo.BranchName
ctx.Data["CommitId"] = ctx.Repo.CommitId
userAgent := ctx.Req.Header.Get("User-Agent")
ua := user_agent.New(userAgent);
browserName, browserVer := ua.Browser()
sliceVer := strings.Split(browserVer, ".")
var max int
if max = len(sliceVer); 3 < max {
max = 3
}
browserVer = strings.Join(sliceVer[:max], ".")
browserVersion, err := version.NewVersion(browserVer)
chromeConstraint, err := version.NewConstraint(">= " + CHROME_COPY_SUPPORT)
firefoxConstraint, err := version.NewConstraint(">= " + FIREFOX_COPY_SUPPORT)
ctx.Data["BrowserSupportsCopy"] = (browserName == "Chrome" && chromeConstraint.Check(browserVersion)) || (browserName == "Firefox" && firefoxConstraint.Check(browserVersion))
}
}

2
templates/ng/base/head.tmpl

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html{{if .BrowserSupportsCopy}} class="is-copy-enabled"{{end}}>
<head data-suburl="{{AppSubUrl}}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

Loading…
Cancel
Save