From 1d0803eca4493737173c4a5b45bd22504bcf1390 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 4 Dec 2021 22:11:55 -0700 Subject: [PATCH] Add share/copy menu --- www/assets/js/home.js | 89 +++++++++++++++++++++++++++++++++++++++ www/assets/js/map.js | 11 +++-- www/assets/js/platform.js | 30 ++++++++----- www/pages/home.html | 11 +++-- 4 files changed, 125 insertions(+), 16 deletions(-) diff --git a/www/assets/js/home.js b/www/assets/js/home.js index 99a622e..3cef06c 100644 --- a/www/assets/js/home.js +++ b/www/assets/js/home.js @@ -46,4 +46,93 @@ function dolookup(words) { } catch (e) { app.dialog.alert(e, "Error"); } +} + +function openLocationActionDialog(latitude, longitude, words) { + app.actions.create({ + buttons: [ + [ + { + text: words, + label: true, + bold: true + } + ], + [ + { + text: "   Share", + label: true + }, + { + text: "FixPhrase", + onClick: function () { + window.plugins.socialsharing.shareWithOptions({ + message: words + }); + } + }, + { + text: "Link", + onClick: function () { + window.plugins.socialsharing.shareWithOptions({ + message: words, + url: "https://fixphrase.com/#" + words.replaceAll(" ", "-") + }); + } + }, + { + text: "Coordinates", + onClick: function () { + window.plugins.socialsharing.shareWithOptions({ + message: latitude + ", " + longitude + }); + } + } + ], + [ + { + text: "   Copy", + label: true + }, + { + text: "FixPhrase", + onClick: function () { + console.log("wefuiefhui weu"); + navigator.clipboard.writeText(words).then(() => { + app.toast.show({text: "Copied!", closeTimeout: 3000}); + }); + } + }, + { + text: "Link", + onClick: function () { + navigator.clipboard.writeText("https://fixphrase.com/#" + words.replaceAll(" ", "-")).then(() => { + app.toast.show({text: "Copied!", closeTimeout: 3000}); + }); + } + }, + { + text: "Coordinates", + onClick: function () { + navigator.clipboard.writeText(latitude + ", " + longitude).then(() => { + app.toast.show({text: "Copied!", closeTimeout: 3000}); + }); + } + } + ], + [ + { + text: "Open in Default Maps App", + onClick: function () { + openGeoLink("geo:" + latitude + "," + longitude); + } + } + ], + [ + { + text: "Cancel" + } + ] + ] + }).open(); } \ No newline at end of file diff --git a/www/assets/js/map.js b/www/assets/js/map.js index 488e65b..0897dc6 100644 --- a/www/assets/js/map.js +++ b/www/assets/js/map.js @@ -68,9 +68,14 @@ function animateMapIn(latitude, longitude, zoom, heading) { function showLocationPopup(latitude, longitude, words, accuracy) { clearRectangle(); $("#location-info-words").text(words); - $("#location-info-coordlink").attr("href", "geo:" + (Math.round(latitude * 10000) / 10000) + "," + (Math.round(longitude * 10000) / 10000)); - $("#location-info-coords").text((Math.round(latitude * 10000) / 10000) + ", " + (Math.round(longitude * 10000) / 10000)); - $("#location-info-coordlink").css("visibility", ""); + latitude = (Math.round(latitude * 10000) / 10000); + longitude = (Math.round(longitude * 10000) / 10000); + $("#location-info-coords").text(latitude + ", " + longitude); + $("#openLocationActionDialogButton").css("visibility", ""); + $("#openLocationActionDialogButton").off("click"); + $("#openLocationActionDialogButton").on("click", function () { + openLocationActionDialog(latitude, longitude, words); + }); drawRectangle( latitude - (accuracy / 2), longitude - (accuracy / 2), diff --git a/www/assets/js/platform.js b/www/assets/js/platform.js index 58d5557..efc4b79 100644 --- a/www/assets/js/platform.js +++ b/www/assets/js/platform.js @@ -58,6 +58,22 @@ var getLocation = function (success, error) { } } +var openGeoLink = function (href) { + if (platform_type == "cordova") { + if (cordova.platformId == "ios") { + window.open(href.replace("geo:", "http://maps.apple.com/?q="), "_system"); + } else if (cordova.platformId == "android") { + window.open(href.replace("geo:", "geo:0,0?q="), "_system"); + } else { + window.open(href, "_system"); + } + } else if (platform_type == "nw") { + require('nw.gui').Shell.openExternal(href); + } else { + window.open(href, "_blank"); + } +} + function initCordova() { platform_type = "cordova"; @@ -150,13 +166,7 @@ function initCordova() { // Handle geo: urls $("body").on("click", "a[href^='geo:']", function (evt) { - if (cordova.platformId == "ios") { - window.open($(this).attr("href").replace("geo:", "http://maps.apple.com/?q="), "_system"); - } else if (cordova.platformId == "android") { - window.open($(this).attr("href").replace("geo:", "geo:0,0?q="), "_system"); - } else { - window.open($(this).attr("href"), "_system"); - } + openGeoLink($(this).attr("href")); evt.preventDefault(); }); } @@ -198,7 +208,7 @@ function initNW() { // Handle geo: urls $("body").on("click", "a[href^='geo:']", function (evt) { - require('nw.gui').Shell.openExternal($(this).attr("href")); + openGeoLink($(this).attr("href")); evt.preventDefault(); }); @@ -222,8 +232,8 @@ function initBrowser() { window.open(url); } - $("body").on("click", ".geolink", function (evt) { - window.open($(this).attr("href"), "_blank"); + $("body").on("click", "a[href^='geo:']", function (evt) { + openGeoLink($(this).attr("href")); evt.preventDefault(); }); diff --git a/www/pages/home.html b/www/pages/home.html index 794ceb9..082a609 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -33,9 +33,14 @@
-
-
- +
+
+
+
+
+
\ No newline at end of file