From 9e1b412167c43a1b6358109e669ee9e0b8c85989 Mon Sep 17 00:00:00 2001 From: benomatis Date: Sun, 17 Dec 2017 01:25:34 +0100 Subject: [PATCH] Add option to decode (previously url encoded) string coming from data input (mainly interesting for title and text) --- dist/js/social-share-kit.js | 10 +++++++++- dist/js/social-share-kit.min.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dist/js/social-share-kit.js b/dist/js/social-share-kit.js index 8385d1f..b061f00 100644 --- a/dist/js/social-share-kit.js +++ b/dist/js/social-share-kit.js @@ -305,6 +305,11 @@ var SocialShareKit = (function () { return text || '' } + // Source: https://stackoverflow.com/questions/3431512/javascript-equivalent-to-phps-urldecode + function urlDecode(url) { + return decodeURIComponent(url.replace(/\+/g, ' ')); + } + function getDataOpts(options, network, el) { var validOpts = ['url', 'title', 'text', 'image'], opts = {}, optValue, optKey, dataKey, a, parent = el.parentNode; @@ -315,7 +320,10 @@ var SocialShareKit = (function () { optValue = el.getAttribute(dataKey) || parent.getAttribute(dataKey) || (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); if (typeof optValue != 'undefined') { - opts[optKey] = optValue; + if (options.decode) + opts[optKey] = urlDecode(optValue); + else + opts[optKey] = optValue; } } return opts; diff --git a/dist/js/social-share-kit.min.js b/dist/js/social-share-kit.min.js index c975cac..7f6345b 100644 --- a/dist/js/social-share-kit.min.js +++ b/dist/js/social-share-kit.min.js @@ -5,4 +5,4 @@ * https://github.com/darklow/social-share-kit/blob/master/LICENSE * --- */ -var SocialShareKit=function(){function e(e){return b(e).share()}function t(e){"loading"!=document.readyState?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent("onreadystatechange",function(){"loading"!=document.readyState&&e()})}function n(e){return document.querySelectorAll(e)}function r(e,t){for(var n=0;n=200&&this.status<400&&t(this.responseText)},r.open("POST",e,!0),r.setRequestHeader("Content-Type","application/json"),r.send(n)}function k(e,t,n){var r="cb_"+e+"_"+Math.round(1e5*Math.random()),o=document.createElement("script");return window[r]=function(e){try{delete window[r]}catch(e){}document.body.removeChild(o),n(e)},"vk"==e?window.VK={Share:{count:function(e,t){window[r](t)}}}:"google-plus"==e&&(window.services={gplus:{cb:window[r]}}),o.src=t+(t.indexOf("?")>=0?"&":"?")+"callback="+r,document.body.appendChild(o),!0}var b,g,y=/(twitter|facebook|google-plus|pinterest|tumblr|vk|linkedin|buffer|email)/,U="*|*";return g=function(e){var t=e||{},r=t.selector||".ssk";this.nodes=n(r),this.options=t},g.prototype={share:function(){function e(e){var t,n=c(e),r=a(n),o=r[0];if(r&&(t=u(p,o,n))){if(window.twttr&&n.getAttribute("href").indexOf("twitter.com/intent/")!==-1)return void n.setAttribute("href",t);if("email"!==o){var i,d;"buffer"===o?(i=800,d=680):(i=575,d=400);var l=s(t,i,d);if(p.onOpen&&p.onOpen(n,o,t,l),p.onClose)var f=window.setInterval(function(){l.closed!==!1&&(window.clearInterval(f),p.onClose(n,o,t,l))},250)}else document.location=t}}function n(){var e,t;for(e in f)t=e.split(U),function(e){w(t[0],t[1],p,function(t){for(var n in e)m(e[n],t)})}(f[e])}var l=this.nodes,p=this.options,f={},h=function(){l.length&&(r(l,function(t){var n,r=a(t);if(r){if(t.getAttribute("data-ssk-ready")){if(!p.reinitialize||!t._skkListener)return;i(t,"click",t._skkListener)}t.setAttribute("data-ssk-ready",!0),o(t,"click",e),t._skkListener=e,t.parentNode.className.indexOf("ssk-count")!==-1&&(r=r[0],n=r+U+d(p,r,t),n in f||(f[n]=[]),f[n].push(t))}}),n())};return p.forceInit===!0?h():t(h),this.nodes}},b=function(e){return new g(e)},{init:e}}();window.SocialShareKit=SocialShareKit; +var SocialShareKit=function(){function e(e){return g(e).share()}function t(e){"loading"!=document.readyState?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent("onreadystatechange",function(){"loading"!=document.readyState&&e()})}function n(e){return document.querySelectorAll(e)}function o(e,t){for(var n=0;n=200&&this.status<400&&t(this.responseText)},o.open("POST",e,!0),o.setRequestHeader("Content-Type","application/json"),o.send(n)}function b(e,t,n){var o="cb_"+e+"_"+Math.round(1e5*Math.random()),r=document.createElement("script");return window[o]=function(e){try{delete window[o]}catch(t){}document.body.removeChild(r),n(e)},"vk"==e?window.VK={Share:{count:function(e,t){window[o](t)}}}:"google-plus"==e&&(window.services={gplus:{cb:window[o]}}),r.src=t+(t.indexOf("?")>=0?"&":"?")+"callback="+o,document.body.appendChild(r),!0}var g,U,y=/(twitter|facebook|google-plus|pinterest|tumblr|vk|linkedin|buffer|email)/,C="*|*";return U=function(e){var t=e||{},o=t.selector||".ssk";this.nodes=n(o),this.options=t},U.prototype={share:function(){function e(e){var t,n=c(e),o=a(n),r=o[0];if(o&&(t=u(p,r,n))){if(window.twttr&&-1!==n.getAttribute("href").indexOf("twitter.com/intent/"))return void n.setAttribute("href",t);if("email"!==r){var i,d;"buffer"===r?(i=800,d=680):(i=575,d=400);var l=s(t,i,d);if(p.onOpen&&p.onOpen(n,r,t,l),p.onClose)var f=window.setInterval(function(){l.closed!==!1&&(window.clearInterval(f),p.onClose(n,r,t,l))},250)}else document.location=t}}function n(){var e,t;for(e in f)t=e.split(C),function(e){v(t[0],t[1],p,function(t){for(var n in e)w(e[n],t)})}(f[e])}var l=this.nodes,p=this.options,f={},h=function(){l.length&&(o(l,function(t){var n,o=a(t);if(o){if(t.getAttribute("data-ssk-ready")){if(!p.reinitialize||!t._skkListener)return;i(t,"click",t._skkListener)}t.setAttribute("data-ssk-ready",!0),r(t,"click",e),t._skkListener=e,-1!==t.parentNode.className.indexOf("ssk-count")&&(o=o[0],n=o+C+d(p,o,t),n in f||(f[n]=[]),f[n].push(t))}}),n())};return p.forceInit===!0?h():t(h),this.nodes}},g=function(e){return new U(e)},{init:e}}();window.SocialShareKit=SocialShareKit; \ No newline at end of file