From 73065734542bfb98eec9b266c80531a8f049b52c Mon Sep 17 00:00:00 2001 From: Arnaud Ruffin Date: Wed, 14 Dec 2016 16:34:33 +0100 Subject: [PATCH] fix(clipboard): replaced zero clipboard to clipboard.js to get rid of flash. Closes #12 --- app.js | 2 +- client/jdropit-send.js | 17 ++++++----------- package.json | 2 +- views/send.jade | 6 +++--- views/thirdparties.jade | 8 ++++---- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index d2cec70..7ad7209 100644 --- a/app.js +++ b/app.js @@ -47,7 +47,7 @@ app.use(express.static(path.join(__dirname, path.join('node_modules', 'tether', app.use(express.static(path.join(__dirname, path.join('node_modules', 'boosted', 'dist')))); app.use(express.static(path.join(__dirname, path.join('node_modules', 'jquery', 'dist','cdn')))); app.use(express.static(path.join(__dirname, path.join('node_modules', 'jquery-file-download', 'src','Scripts')))); -app.use(express.static(path.join(__dirname, path.join('node_modules', 'zeroclipboard', 'dist')))); +app.use(express.static(path.join(__dirname, path.join('node_modules', 'clipboard', 'dist')))); var receiveUriPath = '/receive'; app.use('/', send); diff --git a/client/jdropit-send.js b/client/jdropit-send.js index dd00fa0..4f71713 100644 --- a/client/jdropit-send.js +++ b/client/jdropit-send.js @@ -230,18 +230,13 @@ function sendFile(isLocal) { var senderHandler = new SenderHandler(isLocal); $("#clipboardcopyok").hide(); - //____ Handling of copy to clipboard with zeroClipboard - var clip = new ZeroClipboard(document.getElementById("copy-button")); - clip.on("ready", function () { - clip.on("copy", function (event) { - var clipboard = event.clipboardData; - clipboard.setData("text/plain", 'http://' + senderHandler.receiverUrl); - }); - clip.on("aftercopy", function () { - $("#clipboardcopyok").show(300); - }); - }); + var clipboard = new Clipboard('#copy-button'); + clipboard.on('success', function(e) { + console.info('Copied to clipboard:', e.text); + $("#clipboardcopyok").show(300); + e.clearSelection(); + }); var dropZone = $('#drop-zone'); //----- Handling drag and drop zone style diff --git a/package.json b/package.json index bf11acc..a076aed 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "uglify-js" : "~2.4.23", "boosted" : "~4.0.0-alpha.4", "tether" : "~1.1.1", - "zeroclipboard" : "~2.2.0", + "clipboard" : "~1.5.16", "jquery" : "1.11.2", "jquery-file-download" : "1.4.5" diff --git a/views/send.jade b/views/send.jade index 2f66e5b..2dbbde7 100644 --- a/views/send.jade +++ b/views/send.jade @@ -26,13 +26,13 @@ block extra_scripts script(src="/js/HackTimer.js") script(src="/js/HackTimerWorker.js") script(src="/js/socket.io-stream.js") - script(src="/ZeroClipboard.js") + script(src="/clipboard.js") script(src="/js/jdropit-send.js") else script(src="/js/HackTimer.silent.min.js") script(src="/js/HackTimerWorker.min.js") script(src="/js/socket.io-stream.min.js") - script(src="/ZeroClipboard.min.js") + script(src="/clipboard.min.js") script(src="/js/jdropit-send.min.js") script. @@ -72,7 +72,7 @@ block content p.lead Tell your friend to go to this url: p.text-muted.text-xs-center.lead#generatedurl span.text-success.pull-xs-right.icon-checkbox-tick#clipboardcopyok(aria-hidden="true") - button.btn.btn-orange.pull-xs-right#copy-button(title="Click to copy url to clipboard") Copy to clipboard + button.btn.btn-orange.pull-xs-right#copy-button(title="Click to copy url to clipboard",data-clipboard-target="#generatedurl") Copy to clipboard div#transferContainer(style="display: none;") div.row.top-buffer div.col-xs-12 diff --git a/views/thirdparties.jade b/views/thirdparties.jade index a8b0b16..a274850 100644 --- a/views/thirdparties.jade +++ b/views/thirdparties.jade @@ -38,12 +38,12 @@ block modal_body a(href="https://github.com/socketio/nkzawa/socket.io-stream/blob/master/LICENSE") MIT license h4 - a(href="http://zeroclipboard.org/") ZeroClipboard - p Copyright (c) 2009-2014 Jon Rohan, James M. Greene + a(href="https://clipboardjs.com/") clipboard.js + p Copyright (c) 2016 Zeno Rocha br - | ZeroClipboard is distributed under the terms and conditions of the   + | clipboard.js is distributed under the terms and conditions of the   i - a(href="https://github.com/zeroclipboard/zeroclipboard/blob/master/LICENSE") MIT License + a(href="https://zenorocha.mit-license.org/") MIT License h4 a(href="http://jquery.com") jQuery JavaScript Library p Includes