mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	Merge pull request #1432 from manfer/enhance-copy-clipboard
Enhance copy clipboard
This commit is contained in:
		| @@ -33,6 +33,8 @@ golang.org/x/net = commit:937a34c9de13 | |||||||
| golang.org/x/text = commit:5b2527008a4c | golang.org/x/text = commit:5b2527008a4c | ||||||
| gopkg.in/ini.v1 = commit:caf3f03ad9 | gopkg.in/ini.v1 = commit:caf3f03ad9 | ||||||
| gopkg.in/redis.v2 = commit:e617904962 | gopkg.in/redis.v2 = commit:e617904962 | ||||||
|  | github.com/hashicorp/go-version = commit:999359b6b7 | ||||||
|  | github.com/mssola/user_agent = commit:f659b98638 | ||||||
|  |  | ||||||
| [res] | [res] | ||||||
| include = etc|public|scripts|templates | include = etc|public|scripts|templates | ||||||
|   | |||||||
| @@ -16,6 +16,14 @@ import ( | |||||||
| 	"github.com/gogits/gogs/modules/git" | 	"github.com/gogits/gogs/modules/git" | ||||||
| 	"github.com/gogits/gogs/modules/log" | 	"github.com/gogits/gogs/modules/log" | ||||||
| 	"github.com/gogits/gogs/modules/setting" | 	"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 { | func ApiRepoAssignment() macaron.Handler { | ||||||
| @@ -345,6 +353,24 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { | |||||||
|  |  | ||||||
| 		ctx.Data["BranchName"] = ctx.Repo.BranchName | 		ctx.Data["BranchName"] = ctx.Repo.BranchName | ||||||
| 		ctx.Data["CommitId"] = ctx.Repo.CommitId | 		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)) | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -269,8 +269,35 @@ var Gogits = {}; | |||||||
|         if ($(selector).hasClass('js-copy-bind')) { |         if ($(selector).hasClass('js-copy-bind')) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if ( document.documentElement.classList.contains("is-copy-enabled") ) { | ||||||
|  |  | ||||||
|  |             $(selector).click(function(event) { | ||||||
|  |                 var $this = $(this); | ||||||
|  |  | ||||||
|  |                 var cfrom = $this.attr('data-copy-from'); | ||||||
|  |                 $(cfrom).select(); | ||||||
|  |                 document.execCommand('copy'); | ||||||
|  |                 getSelection().removeAllRanges(); | ||||||
|  |  | ||||||
|  |                 $this.tipsy("hide").attr('original-title', $this.data('after-title')); | ||||||
|  |                 setTimeout(function () { | ||||||
|  |                     $this.tipsy("show"); | ||||||
|  |                 }, 200); | ||||||
|  |                 setTimeout(function () { | ||||||
|  |                     $this.tipsy('hide').attr('original-title', $this.data('original-title')); | ||||||
|  |                 }, 2000); | ||||||
|  |                  | ||||||
|  |                 this.blur(); | ||||||
|  |                 return; | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             $(selector).addClass("js-copy-bind"); | ||||||
|  |  | ||||||
|  |         } else { | ||||||
|  |  | ||||||
|             $(selector).zclip({ |             $(selector).zclip({ | ||||||
|             path: "/js/ZeroClipboard.swf", |                 path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", | ||||||
|                 copy: function () { |                 copy: function () { | ||||||
|                     var t = $(this).data("copy-val"); |                     var t = $(this).data("copy-val"); | ||||||
|                     var to = $($(this).data("copy-from")); |                     var to = $($(this).data("copy-from")); | ||||||
| @@ -288,18 +315,17 @@ var Gogits = {}; | |||||||
|                 }, |                 }, | ||||||
|                 afterCopy: function () { |                 afterCopy: function () { | ||||||
|                     var $this = $(this); |                     var $this = $(this); | ||||||
|                 $this.tooltip('hide') |                     $this.tipsy("hide").attr('original-title', $this.data('after-title')); | ||||||
|                     .attr('data-original-title', 'Copied OK'); |  | ||||||
|                     setTimeout(function () { |                     setTimeout(function () { | ||||||
|                     $this.tooltip("show"); |                         $this.tipsy("show"); | ||||||
|                     }, 200); |                     }, 200); | ||||||
|                     setTimeout(function () { |                     setTimeout(function () { | ||||||
|                     $this.tooltip('hide') |                         $this.tipsy('hide').attr('original-title', $this.data('original-title')); | ||||||
|                         .attr('data-original-title', 'Copy to Clipboard'); |                     }, 2000); | ||||||
|                 }, 3000); |  | ||||||
|                 } |                 } | ||||||
|             }).addClass("js-copy-bind"); |             }).addClass("js-copy-bind"); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // api working |     // api working | ||||||
|     Gogits.getUsers = function (val, $target) { |     Gogits.getUsers = function (val, $target) { | ||||||
|   | |||||||
| @@ -333,6 +333,33 @@ var Gogs = {}; | |||||||
|         if ($(selector).hasClass('js-copy-bind')) { |         if ($(selector).hasClass('js-copy-bind')) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if ( document.documentElement.classList.contains("is-copy-enabled") ) { | ||||||
|  |  | ||||||
|  |             $(selector).click(function(event) { | ||||||
|  |                 var $this = $(this); | ||||||
|  |  | ||||||
|  |                 var cfrom = $this.attr('data-copy-from'); | ||||||
|  |                 $(cfrom).select(); | ||||||
|  |                 document.execCommand('copy'); | ||||||
|  |                 getSelection().removeAllRanges(); | ||||||
|  |  | ||||||
|  |                 $this.tipsy("hide").attr('original-title', $this.data('after-title')); | ||||||
|  |                 setTimeout(function () { | ||||||
|  |                     $this.tipsy("show"); | ||||||
|  |                 }, 200); | ||||||
|  |                 setTimeout(function () { | ||||||
|  |                     $this.tipsy('hide').attr('original-title', $this.data('original-title')); | ||||||
|  |                 }, 2000); | ||||||
|  |                  | ||||||
|  |                 this.blur(); | ||||||
|  |                 return; | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             $(selector).addClass("js-copy-bind"); | ||||||
|  |  | ||||||
|  |         } else { | ||||||
|  |  | ||||||
|             $(selector).zclip({ |             $(selector).zclip({ | ||||||
|                 path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", |                 path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", | ||||||
|                 copy: function () { |                 copy: function () { | ||||||
| @@ -362,6 +389,7 @@ var Gogs = {}; | |||||||
|                 } |                 } | ||||||
|             }).addClass("js-copy-bind"); |             }).addClass("js-copy-bind"); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| })(jQuery); | })(jQuery); | ||||||
|  |  | ||||||
| function initCore() { | function initCore() { | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| <!DOCTYPE html> | <!DOCTYPE html> | ||||||
| <html> | <html{{if .BrowserSupportsCopy}} class="is-copy-enabled"{{end}}> | ||||||
| 	<head data-suburl="{{AppSubUrl}}"> | 	<head data-suburl="{{AppSubUrl}}"> | ||||||
| 		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | 		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||||
|         <meta http-equiv="X-UA-Compatible" content="IE=edge"/> |         <meta http-equiv="X-UA-Compatible" content="IE=edge"/> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user