forked from gitea/gitea
1
0
Fork 0

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')) {
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({
path: "/js/ZeroClipboard.swf",
path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf",
copy: function () {
var t = $(this).data("copy-val");
var to = $($(this).data("copy-from"));
@ -288,18 +315,17 @@ var Gogits = {};
},
afterCopy: function () {
var $this = $(this);
$this.tooltip('hide')
.attr('data-original-title', 'Copied OK');
$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);
$this.tipsy('hide').attr('original-title', $this.data('original-title'));
}, 2000);
}
}).addClass("js-copy-bind");
}
}
// api working
Gogits.getUsers = function (val, $target) {

View File

@ -333,6 +333,33 @@ var Gogs = {};
if ($(selector).hasClass('js-copy-bind')) {
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({
path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf",
copy: function () {
@ -362,6 +389,7 @@ var Gogs = {};
}
}).addClass("js-copy-bind");
}
}
})(jQuery);
function initCore() {