From 073885d651ed5ac02a4ffe0a61c4d2b952100272 Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Sat, 13 Aug 2016 20:04:38 -0400 Subject: [PATCH 1/4] Add button to copy link/password to clipboard - Using clipboard.js - On browsers not supporting evalCommand(), the text will be selected, and the keyboard shortcut displayed, depending on platform. (tested on Safari) - Now using Bootstrap readonly text form, instead of a header, to display the passwords and generated links; - Using fontawesome to get a clipboard icon (like GitHub, GitLab, etc.) - fontawesome and clipboard.js are pulled from a CDN. --- snappass/static/css/custom.css | 4 +++ snappass/static/scripts/clipboard_button.js | 31 +++++++++++++++++++++ snappass/templates/base.html | 2 ++ snappass/templates/confirm.html | 14 +++++++++- snappass/templates/password.html | 14 +++++++++- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 snappass/static/css/custom.css create mode 100644 snappass/static/scripts/clipboard_button.js diff --git a/snappass/static/css/custom.css b/snappass/static/css/custom.css new file mode 100644 index 0000000..deda990 --- /dev/null +++ b/snappass/static/css/custom.css @@ -0,0 +1,4 @@ +input[readonly].readonly-text { + background-color: #fff; + cursor: text; +} \ No newline at end of file diff --git a/snappass/static/scripts/clipboard_button.js b/snappass/static/scripts/clipboard_button.js new file mode 100644 index 0000000..2502e1c --- /dev/null +++ b/snappass/static/scripts/clipboard_button.js @@ -0,0 +1,31 @@ +(function(){ + + var targetButtonSelector = '#copy-clipboard-btn' + var clipboard = new Clipboard(targetButtonSelector); + + var copyError = function(e) { + var key; + if (/Mac/i.test(navigator.userAgent)) { + key = '⌘'; + } else { + key = 'Ctrl'; + } + $(e.trigger).attr('title', "Press " + key + "-C to copy" ) + .tooltip('fixTitle') + .tooltip('show'); + }; + + var copySuccess = function(e) { + $(e.trigger).attr('title', 'Copied!') + .tooltip('fixTitle') + .tooltip('show'); + e.clearSelection(); + + }; + + clipboard.on('success', copySuccess); + clipboard.on('error', copyError); + + $(targetButtonSelector).tooltip(); + +})(); \ No newline at end of file diff --git a/snappass/templates/base.html b/snappass/templates/base.html index 11fe82e..468e416 100644 --- a/snappass/templates/base.html +++ b/snappass/templates/base.html @@ -4,6 +4,8 @@ Send Password + +