Integrating ZeroClipboard in Copay as directive

This commit is contained in:
Gustavo Maximiliano Cortez 2014-07-31 16:34:21 -03:00
commit dc565e0a68
4 changed files with 37 additions and 1 deletions

View file

@ -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();
});
}
};
})
;