Browse Source

add clipboard API support

pull/1432/head
Fernando San Julián 9 years ago
parent
commit
eebcbf9d34
  1. 78
      public/js/app.js
  2. 68
      public/ng/js/gogs.js

78
public/js/app.js

@ -269,36 +269,62 @@ var Gogits = {};
if ($(selector).hasClass('js-copy-bind')) { if ($(selector).hasClass('js-copy-bind')) {
return; return;
} }
$(selector).zclip({
path: "/js/ZeroClipboard.swf", if ( document.documentElement.classList.contains("is-copy-enabled") ) {
copy: function () {
var t = $(this).data("copy-val"); $(selector).click(function(event) {
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); 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 () { 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);
} this.blur();
}).addClass("js-copy-bind"); 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 // api working

68
public/ng/js/gogs.js

@ -333,25 +333,17 @@ var Gogs = {};
if ($(selector).hasClass('js-copy-bind')) { if ($(selector).hasClass('js-copy-bind')) {
return; return;
} }
$(selector).zclip({
path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", if ( document.documentElement.classList.contains("is-copy-enabled") ) {
copy: function () {
var t = $(this).data("copy-val"); $(selector).click(function(event) {
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); 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')); $this.tipsy("hide").attr('original-title', $this.data('after-title'));
setTimeout(function () { setTimeout(function () {
$this.tipsy("show"); $this.tipsy("show");
@ -359,8 +351,44 @@ var Gogs = {};
setTimeout(function () { setTimeout(function () {
$this.tipsy('hide').attr('original-title', $this.data('original-title')); $this.tipsy('hide').attr('original-title', $this.data('original-title'));
}, 2000); }, 2000);
}
}).addClass("js-copy-bind"); 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");
}
} }
})(jQuery); })(jQuery);

Loading…
Cancel
Save