snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit 83dc58b5c23106899dc5baea3122b7d8e57416bb
parent 184eda47e3eda2f166bb50299d792bde10ebdfde
Author: Robin Linus <robin_woll@capira.de>
Date:   Sun,  3 Jan 2016 03:07:32 +0100

Check if clipboard supported provide fallbacks

Diffstat:
Mapp/elements/text-sharing/text-input-dialog.html | 56++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 52 insertions(+), 4 deletions(-)

diff --git a/app/elements/text-sharing/text-input-dialog.html b/app/elements/text-sharing/text-input-dialog.html @@ -27,7 +27,7 @@ @media all and (max-height: 600px) { #sendDialog { padding-top: 24px; - top:0px !important; + top: 0px !important; } } @@ -68,10 +68,13 @@ </div> <div class="buttons"> <paper-button dialog-dismiss>Discard</paper-button> + <paper-button on-tap="_copy" autofocus hidden$="{{!clipboardSupported}}">Copy</paper-button> <a href="tel:{{tel}}" hidden$="{{!tel}}"> - <paper-button dialog-dismiss>Call</paper-button> + <paper-button autofocus dialog-dismiss>Call</paper-button> + </a> + <a href="{{url}}" hidden$="{{!url}}" target="_blank"> + <paper-button autofocus dialog-dismiss>Open</paper-button> </a> - <paper-button on-tap="_copy" autofocus>Copy</paper-button> </div> </paper-dialog> </template> @@ -84,9 +87,11 @@ * */ var phoneNumbers = /^\+?[0-9x/ ]*$/; + var urls = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/; + Polymer({ is: 'text-input-dialog', - behaviors: [Chat.ClipboardBehavior,Chat.SoundNotificationBehavior], + behaviors: [Chat.ClipboardBehavior, Chat.SoundNotificationBehavior], properties: { textToSend: { type: String @@ -100,6 +105,17 @@ tel: { computed: '_isPhoneNumber(receivedText)', value: false + }, + url: { + computed: '_isUrl(receivedText)', + value: false + }, + clipboardSupported: { + value: false + }, + fallback: { + computed: '_isFallback(url,tel,clipboardSupported)', + value: false } }, open: function(contact) { @@ -107,9 +123,27 @@ this.$.sendDialog.open(); }, attached: function() { + // clipboard must be initalized by user interaction + var that = this; + var hackListener = function() { + document.body.removeEventListener('touchstart', hackListener, false); + document.body.removeEventListener('click', hackListener, false); + // wait 1s to tell the ui that copy is supported + that.async(function() { + that.clipboardSupported = document.queryCommandSupported && document.queryCommandSupported('copy'); + }, 1000); + }; + document.body.addEventListener('touchstart', hackListener, false); + document.body.addEventListener('click', hackListener, false); + + this.async(function() { app.conn.addEventListener('text-received', function(e) { var receivedText = e.detail.text; + if (!receivedText || receivedText.trim() === '') { + this.playSound(); + return; + } this.receivedText = receivedText; this.$.receivedText.textContent = receivedText; window.linkifyElement(this.$.receivedText, {}, document); @@ -136,6 +170,8 @@ } } }.bind(this), false); + + }, _send: function() { this.$.sendDialog.close(); @@ -156,6 +192,18 @@ } }, + _isUrl: function(text) { + if (!text) { + return false; + } + if (urls.test(text)) { + return text; + } + + }, + _isFallback: function(url, tel, clipboardSupported) { + return (!url && !tel && !clipboardSupported); + } }); }()); </script>