Files
meanTorrent/modules/core/client/services/mtCopyToClipboard.client.service.js
2019-06-05 11:20:54 +08:00

37 lines
948 B
JavaScript

'use strict';
angular
.module('core')
.service('mtCopy', ['$window', function ($window) {
var body = angular.element($window.document.body);
var textarea = angular.element('<textarea/>');
textarea.css({
position: 'fixed',
opacity: '0'
});
return function (toCopy) {
textarea.val(toCopy);
body.append(textarea);
textarea[0].readOnly = true;
textarea[0].select();
textarea[0].setSelectionRange(0, 99999);
document.execCommand('copy');
textarea.remove();
};
}])
.directive('mtCopyToClipboard', ['mtCopy', 'NotifycationService', function (mtCopy, NotifycationService) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.bind('click', function (e) {
mtCopy(attrs.mtCopyToClipboard);
NotifycationService.showNotify('info', '', 'COPY_TO_CLIPBOARD_SUCCESSFULLY');
});
}
};
}]);