]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/social_share_button_helper.rb
Enable share button to do native share
[rails.git] / app / helpers / social_share_button_helper.rb
index da49347c3054a56f32a063e54cb44faf84bc2e79..04f0729abc4d1354ac0878613b7ecb5bbcb11503 100644 (file)
@@ -14,20 +14,35 @@ module SocialShareButtonHelper
   # Generates a set of social share buttons based on the specified options.
   def social_share_buttons(title:, url:)
     tag.div(
-      :class => "social-share-button d-flex gap-1 align-items-end flex-wrap mb-3"
+      :class => "social-share-buttons d-flex gap-1 align-items-end flex-wrap mb-3"
     ) do
-      safe_join(SOCIAL_SHARE_CONFIG.map do |site, icon|
+      buttons = [
+        tag.button(:type => "button",
+                   :class => "btn btn-secondary p-1 border-1 rounded-circle",
+                   :title => I18n.t("application.share.share.title"),
+                   :hidden => true,
+                   :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
+      ]
+
+      buttons << SOCIAL_SHARE_CONFIG.map do |site, icon|
         link_options = {
           :rel => "nofollow",
-          :class => "ssb-icon rounded-circle",
+          :class => "rounded-circle focus-ring",
           :title => I18n.t("application.share.#{site}.title"),
-          :target => "_blank"
+          :target => "_blank",
+          :data => { :share_type => site == :email ? "email" : "site" }
         }
 
         link_to generate_share_url(site, title, url), link_options do
           image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
         end
-      end, "\n")
+      end
+
+      safe_join(buttons, "\n")
     end
   end
 
@@ -35,8 +50,8 @@ module SocialShareButtonHelper
 
   def generate_share_url(site, title, url)
     site = site.to_sym
-    title = URI.encode_www_form_component(title)
-    url = URI.encode_www_form_component(url)
+    title = URI.encode_uri_component(title)
+    url = URI.encode_uri_component(url)
 
     case site
     when :email