huacnlee / social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
MIT License
582 stars 311 forks source link

Adds social share on WhatsApp #170

Closed decabeza closed 5 years ago

decabeza commented 6 years ago

What

This PR adds social share button for WhatsApp in two versions:

whatsapp_app for mobile version using whatsapp://send?text=

whatsapp_web for desktop browsers using https://web.whatsapp.com/send?text=

Notes

screenshot 2018-10-27 at 12 14 24

If you wanna use both versions, you should add some extra CSS (media-queries for example) for .ssb-whatsapp_app and .ssb-whatsapp_web classes to show different version depending of device or screen size, to avoid show both at same time and confuse to users.

shayani commented 5 years ago

Merge this commit, please

huacnlee commented 5 years ago

Just released 1.2.0

StarWar commented 5 years ago

@huacnlee When using the WhatsApp as it's implemented, the snippet doesn't show and doesn't include the URL. I.e. You have to append the urlencoded URL to the text itself. Because including the URL as a query parameter doesn't work. I'm doing following work around:

//set up the url
        var url = "whatsapp://send?text=";
        //define the message text
        var title = $(document).find("title").text();
        var canonical = $("link[rel='canonical']").attr("href");
        var text = title + " at " + canonical;
        //encode the text
        var encodedText = encodeURIComponent(text);
        //set the href attribute on the link
        $whatsApp_app.attr("href", url + encodedText);