New directive copy-to-clipboard multiplatform
This commit is contained in:
parent
8bcb332276
commit
0a047782bb
15 changed files with 66 additions and 68 deletions
39
src/js/directives/copyToClipboard.js
Normal file
39
src/js/directives/copyToClipboard.js
Normal 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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue