New directive copy-to-clipboard multiplatform

This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-23 12:16:05 -03:00
commit 0a047782bb
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
15 changed files with 66 additions and 68 deletions

View file

@ -0,0 +1,39 @@
'use strict';
angular.module('copayApp.directives')
.directive('copyToClipboard', function(platformInfo, gettextCatalog, ionicToast, clipboard) {
return {
restrict: 'A',
scope: {
copyToClipboard: '=copyToClipboard'
},
link: function(scope, elem, attrs, ctrl) {
var isCordova = platformInfo.isCordova;
var isChromeApp = platformInfo.isChromeApp;
var isNW = platformInfo.isNW;
elem.bind('mouseover', function() {
elem.css('cursor', 'pointer');
});
var msg = gettextCatalog.getString('Copied to clipboard');
elem.bind('click', function() {
var data = scope.copyToClipboard;
if (isCordova) {
window.cordova.plugins.clipboard.copy(data);
window.plugins.toast.showShortCenter(msg);
} else if (isNW) {
nodeWebkit.writeToClipboard(data);
scope.$apply(function() {
ionicToast.show(msg, 'bottom', false, 1000);
});
} else if (clipboard.supported) {
clipboard.copyText(data);
scope.$apply(function() {
ionicToast.show(msg, 'bottom', false, 1000);
});
}
});
}
}
});