]> git.openstreetmap.org Git - rails.git/commitdiff
Enable share button to do native share
authorAnton Khorev <tony29@yandex.ru>
Thu, 3 Apr 2025 14:28:37 +0000 (17:28 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 3 Apr 2025 15:01:07 +0000 (18:01 +0300)
app/assets/javascripts/social_share_button.js
app/helpers/social_share_button_helper.rb

index 4ea11128cc81297a4bddf4d07e1a8678ea34c6b8..e8c6673b526698ed9e74f638d777f5882753600b 100644 (file)
@@ -14,4 +14,13 @@ $(function () {
     e.preventDefault();
     openShareUrl(this.href);
   });
+
+  if (navigator.share) {
+    $(".social-share-buttons [data-share-type='native']").prop("hidden", false).on("click", function () {
+      navigator.share({
+        text: this.dataset.shareText,
+        url: this.dataset.shareUrl
+      });
+    });
+  }
 });
index b9c8e309e06557a8b64d35de630cb4152568237d..04f0729abc4d1354ac0878613b7ecb5bbcb11503 100644 (file)
@@ -21,7 +21,9 @@ module SocialShareButtonHelper
                    :class => "btn btn-secondary p-1 border-1 rounded-circle",
                    :title => I18n.t("application.share.share.title"),
                    :hidden => true,
-                   :data => { :share_type => "native" }) do
+                   :data => { :share_type => "native",
+                              :share_text => title,
+                              :share_url => url }) do
           image_tag("social_icons/share.svg", :alt => I18n.t("application.share.share.alt"), :size => 18, :class => "d-block")
         end
       ]