added copy-to-clipboard directive that does not require Flash

This commit is contained in:
alecmerdler 2017-05-24 21:42:06 -07:00
parent 6ed5235dfd
commit 062c1a1626
13 changed files with 186 additions and 74 deletions

View file

@ -1,49 +1,5 @@
$.fn.clipboardCopy = function() {
if (__zeroClipboardSupported) {
(new ZeroClipboard($(this)));
return true;
}
this.hide();
return false;
};
// Initialize the clipboard system.
(function () {
__zeroClipboardSupported = true;
ZeroClipboard.on("error", function(e) {
__zeroClipboardSupported = false;
});
ZeroClipboard.on('aftercopy', function(e) {
var container = e.target.parentNode.parentNode.parentNode;
var message = $(container).find('.clipboard-copied-message')[0];
if (!message) {
return;
}
// Resets the animation.
var elem = message;
elem.style.display = 'none';
elem.classList.remove('animated');
// Show the notification.
setTimeout(function() {
elem.style.display = 'inline-block';
elem.classList.add('animated');
}, 10);
// Reset the notification.
setTimeout(function() {
elem.style.display = 'none';
}, 5000);
});
})();
/**
* An element which displays a textfield with a "Copy to Clipboard" icon next to it. Note
* that this method depends on the clipboard copying library in the lib/ folder.
* An element which displays a textfield with a "Copy to Clipboard" icon next to it.
*/
angular.module('quay').directive('copyBox', function () {
var directiveDefinitionObject = {
@ -62,13 +18,6 @@ angular.module('quay').directive('copyBox', function () {
var number = $rootScope.__copyBoxIdCounter || 0;
$rootScope.__copyBoxIdCounter = number + 1;
$scope.inputId = "copy-box-input-" + number;
var button = $($element).find('.copy-icon');
var input = $($element).find('input');
input.attr('id', $scope.inputId);
button.attr('data-clipboard-target', $scope.inputId);
$scope.disabled = !button.clipboardCopy();
}
};
return directiveDefinitionObject;