diff options
author | 无闻 <u@gogs.io> | 2015-08-04 08:51:06 +0800 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2015-08-04 08:51:06 +0800 |
commit | 96c1ce960602d65252fbb038e10db629f235936d (patch) | |
tree | 8970c3fe3c95ec93562b1b3ff6e51b6b27fe2fe6 /public/js/app.js | |
parent | 8e8d535e233966acd1510df78c01e11dc8156514 (diff) | |
parent | eebcbf9d3438a9910dee56fd76ab624726eb207c (diff) |
Merge pull request #1432 from manfer/enhance-copy-clipboard
Enhance copy clipboard
Diffstat (limited to 'public/js/app.js')
-rw-r--r-- | public/js/app.js | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/public/js/app.js b/public/js/app.js index 6208dbed..3dbf29c1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -269,36 +269,62 @@ var Gogits = {}; if ($(selector).hasClass('js-copy-bind')) { return; } - $(selector).zclip({ - path: "/js/ZeroClipboard.swf", - copy: function () { - var t = $(this).data("copy-val"); - var to = $($(this).data("copy-from")); - var str = ""; - if (t == "txt") { - str = to.text(); - } - if (t == 'val') { - str = to.val(); - } - if (t == 'html') { - str = to.html(); - } - return str; - }, - afterCopy: function () { + + if ( document.documentElement.classList.contains("is-copy-enabled") ) { + + $(selector).click(function(event) { var $this = $(this); - $this.tooltip('hide') - .attr('data-original-title', 'Copied OK'); + + 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.tooltip("show"); + $this.tipsy("show"); }, 200); setTimeout(function () { - $this.tooltip('hide') - .attr('data-original-title', 'Copy to Clipboard'); - }, 3000); - } - }).addClass("js-copy-bind"); + $this.tipsy('hide').attr('original-title', $this.data('original-title')); + }, 2000); + + this.blur(); + return; + }); + + $(selector).addClass("js-copy-bind"); + + } else { + + $(selector).zclip({ + path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", + copy: function () { + var t = $(this).data("copy-val"); + var to = $($(this).data("copy-from")); + var str = ""; + if (t == "txt") { + str = to.text(); + } + if (t == 'val') { + str = to.val(); + } + if (t == 'html') { + str = to.html(); + } + return str; + }, + afterCopy: function () { + var $this = $(this); + $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); + } + }).addClass("js-copy-bind"); + } } // api working |