add clipboard API support

This commit is contained in:
Fernando San Julián 2015-08-03 21:27:15 +02:00
parent 6a89eeedf3
commit eebcbf9d34
2 changed files with 100 additions and 46 deletions

View file

@ -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) {

View file

@ -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() {