From dc565e0a68c3195017d47f191d544bcf7b9281b9 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 31 Jul 2014 16:34:21 -0300 Subject: [PATCH] Integrating ZeroClipboard in Copay as directive --- bower.json | 3 ++- img/icons/copy.png | Bin 0 -> 148 bytes index.html | 1 + js/directives.js | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 img/icons/copy.png diff --git a/bower.json b/bower.json index cf1a4f301..ba78d8346 100644 --- a/bower.json +++ b/bower.json @@ -21,6 +21,7 @@ "bitcore": "0.1.34", "angular-moment": "~0.7.1", "socket.io-client": ">=1.0.0", - "mousetrap": "1.4.6" + "mousetrap": "1.4.6", + "zeroclipboard": "~2.1.6" } } diff --git a/img/icons/copy.png b/img/icons/copy.png new file mode 100644 index 0000000000000000000000000000000000000000..b43ca063492c22a1436ae1d2ce852d638df9e38c GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`(Vi}jAr-fhQyQAu+S>l}xG*h< za+8=Xc(dWxud1e5($dl|6Bs-MH!>_|JhH3p8(YF>zD;*LiWzq;yi(3+R-bgag-2qe w=Ar3p64y1WW^UqXSe1C>HB(KU`#B$mX;bUjd88Ho0j**1boFyt=akR{0FnYUOaK4? literal 0 HcmV?d00001 diff --git a/index.html b/index.html index acc29b64d..69fd2321f 100644 --- a/index.html +++ b/index.html @@ -74,6 +74,7 @@ + diff --git a/js/directives.js b/js/directives.js index b1d6c3b35..8601249b3 100644 --- a/js/directives.js +++ b/js/directives.js @@ -232,4 +232,38 @@ angular.module('copayApp.directives') } }; }) + .directive('clipCopy', function() { + ZeroClipboard.config({ + moviePath: '/lib/zeroclipboard/dist/ZeroClipboard.swf', + trustedDomains: ['*'], + allowScriptAccess: 'always', + forceHandCursor: true + }); + + return { + restric: 'A', + scope: { clipCopy: '=clipCopy' }, + link: function(scope, elm) { + var client = new ZeroClipboard(elm); + + client.on( 'ready', function(event) { + client.on( 'copy', function(event) { + event.clipboardData.setData('text/plain', scope.clipCopy); + }); + + client.on( 'aftercopy', function(event) { + elm.removeClass('btn-copy').addClass('btn-copied').html('Copied!'); + setTimeout(function() { + elm.addClass('btn-copy').removeClass('btn-copied').html(''); + }, 1000); + }); + }); + + client.on( 'error', function(event) { + console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message ); + ZeroClipboard.destroy(); + }); + } + }; + }) ;