1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
export default function share( network, url, context, option = { twitterUser: "", description: "", quote: "", encodedHashtags: "", media: "", } ) { let ua = navigator.userAgent.toLowerCase();
let key = network.toLowerCase();
if (key === "sms" && (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1)) { networks[key].replace(":?", ":&"); }
let link = networks[key];
if (key === "twitter") { link = link.replace("&hashtags=@h", "").replace("@tu", ""); }
link = link .replace(/@tu/g, "&via=" + encodeURIComponent(option.twitterUser)) .replace(/@u/g, encodeURIComponent(url)) .replace(/@t/g, encodeURIComponent(context)) .replace(/@d/g, encodeURIComponent(option.description)) .replace(/@q/g, encodeURIComponent(option.quote)) .replace(/@h/g, option.encodedHashtags) .replace(/@m/g, encodeURIComponent(option.media));
if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) { window.location.href = link; } else { window.open(link, "sharer-" + key, ",height=426,width=626"); } }
|