From d9f2cac578396b929ef79431bd75832253c0bd34 Mon Sep 17 00:00:00 2001 From: Andrew Leedham Date: Tue, 30 Oct 2018 11:27:41 +0000 Subject: [PATCH 1/5] Allowed dataOpts to be blank strings --- dist/js/social-share-kit.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dist/js/social-share-kit.js b/dist/js/social-share-kit.js index 8385d1f..79a8eaa 100644 --- a/dist/js/social-share-kit.js +++ b/dist/js/social-share-kit.js @@ -312,8 +312,15 @@ var SocialShareKit = (function () { for (a in validOpts) { optKey = validOpts[a]; dataKey = 'data-' + optKey; - optValue = el.getAttribute(dataKey) || parent.getAttribute(dataKey) || - (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); + var fromEl = el.getAttribute(dataKey); + optValue = typeof fromEl != 'undefined' && fromEl; + if (typeof optValue == 'undefined') { + var fromParent = parent.getAttribute(dataKey); + optValue = fromParent != 'undefined' && fromParent; + } + if (typeof optValue == 'undefined') { + optValue = (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); + } if (typeof optValue != 'undefined') { opts[optKey] = optValue; } From e1e82d736c471365f5b046adc931e9aebe5eb276 Mon Sep 17 00:00:00 2001 From: Andrew Leedham Date: Tue, 30 Oct 2018 11:39:32 +0000 Subject: [PATCH 2/5] truthyOrEmpty --- dist/js/social-share-kit.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/js/social-share-kit.js b/dist/js/social-share-kit.js index 79a8eaa..30ad80c 100644 --- a/dist/js/social-share-kit.js +++ b/dist/js/social-share-kit.js @@ -305,6 +305,10 @@ var SocialShareKit = (function () { return text || '' } + function truthyOrEmpty(value) { + return value || value === ''; + } + function getDataOpts(options, network, el) { var validOpts = ['url', 'title', 'text', 'image'], opts = {}, optValue, optKey, dataKey, a, parent = el.parentNode; @@ -314,11 +318,11 @@ var SocialShareKit = (function () { dataKey = 'data-' + optKey; var fromEl = el.getAttribute(dataKey); optValue = typeof fromEl != 'undefined' && fromEl; - if (typeof optValue == 'undefined') { + if (!truthyOrEmpty(optValue)) { var fromParent = parent.getAttribute(dataKey); optValue = fromParent != 'undefined' && fromParent; } - if (typeof optValue == 'undefined') { + if (!truthyOrEmpty(optValue)) { optValue = (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); } if (typeof optValue != 'undefined') { From 98188ca33a1043fd28b5dcdc97633f2bafdb5745 Mon Sep 17 00:00:00 2001 From: Andrew Leedham Date: Tue, 30 Oct 2018 11:44:13 +0000 Subject: [PATCH 3/5] Updated minified version # Conflicts: # dist/js/social-share-kit.min.js --- dist/js/social-share-kit.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/js/social-share-kit.min.js b/dist/js/social-share-kit.min.js index c975cac..e20b553 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(){var t,n,r=/(twitter|facebook|google-plus|pinterest|tumblr|vk|linkedin|buffer|email)/;function o(e){return document.querySelectorAll(e)}function p(e){return e.className.match(r)}function h(e,t,n,r){return(r=r||v(e,t,n)).url||window.location.href}function f(e,t){var n,r=o("meta["+(t||(0===e.indexOf("og:")?"property":"name"))+'="'+e+'"]');return r.length&&(n=r[0].getAttribute("content")||""),n||""}function m(e){return e||""===e}function v(e,t,n){var r,o,i,a,c=["url","title","text","image"],s={},u=n.parentNode;for(a in"twitter"==t&&c.push("via"),c){i="data-"+(o=c[a]);var d=n.getAttribute(i);if(!m(r=void 0!==d&&d)){var l=u.getAttribute(i);r="undefined"!=l&&l}m(r)||(r=e[t]&&void 0!==e[t][o]?e[t][o]:e[o]),void 0!==r&&(s[o]=r)}return s}function i(e,t){var n=document.createElement("div");n.innerHTML=t,n.className="ssk-num",e.appendChild(n)}function a(e,t,n,r){var o,i,a,c,s,u,d=encodeURIComponent(t);switch(e){case"facebook":o="https://graph.facebook.com/?id="+d,i=function(e){return r(e.share?e.share.share_count:0)};break;case"twitter":n&&n.twitter&&n.twitter.countCallback&&n.twitter.countCallback(t,r);break;case"google-plus":return a=o="https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",c=i=function(e){if((e=JSON.parse(e)).length)return r(e[0].result.metadata.globalCounts.count)},s='[{"method":"pos.plusones.get","id":"p","params":{"id":"'+t+'","userId":"@viewer","groupId":"@self","nolog":true},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]',(u=new XMLHttpRequest).onreadystatechange=function(){4===this.readyState&&200<=this.status&&this.status<400&&c(this.responseText)},u.open("POST",a,!0),u.setRequestHeader("Content-Type","application/json"),void u.send(s);case"linkedin":o="https://www.linkedin.com/countserv/count/share?url="+d,i=function(e){return r(e.count)};break;case"pinterest":o="https://api.pinterest.com/v1/urls/count.json?url="+d,i=function(e){return r(e.count)};break;case"vk":o="https://vk.com/share.php?act=count&url="+d,i=function(e){return r(e)};break;case"buffer":o="https://api.bufferapp.com/1/links/shares.json?url="+d,i=function(e){return r(e.shares)}}o&&i&&function(e,t,n){var r="cb_"+e+"_"+Math.round(1e5*Math.random()),o=document.createElement("script");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+(0<=t.indexOf("?")?"&":"?")+"callback="+r,document.body.appendChild(o)}(e,o,i)}return(n=function(e){var t=e||{},n=t.selector||".ssk";this.nodes=o(n),this.options=t}).prototype={share:function(){var e,t=this.nodes,u=this.options,d={},n=function(){t.length&&(function(e,t){for(var n=0;n Date: Tue, 30 Oct 2018 15:09:32 +0000 Subject: [PATCH 4/5] Fixed truthy for element --- dist/js/social-share-kit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/js/social-share-kit.js b/dist/js/social-share-kit.js index 30ad80c..603557e 100644 --- a/dist/js/social-share-kit.js +++ b/dist/js/social-share-kit.js @@ -317,10 +317,10 @@ var SocialShareKit = (function () { optKey = validOpts[a]; dataKey = 'data-' + optKey; var fromEl = el.getAttribute(dataKey); - optValue = typeof fromEl != 'undefined' && fromEl; + optValue = truthyOrEmpty(fromEl) && fromEl; if (!truthyOrEmpty(optValue)) { var fromParent = parent.getAttribute(dataKey); - optValue = fromParent != 'undefined' && fromParent; + optValue = truthyOrEmpty(fromParent) && fromParent; } if (!truthyOrEmpty(optValue)) { optValue = (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); From 0772e665d442f578ff3eecfc2151a66a1e5fe715 Mon Sep 17 00:00:00 2001 From: Andrew Leedham Date: Tue, 30 Oct 2018 16:44:09 +0000 Subject: [PATCH 5/5] Updated min version # Conflicts: # dist/js/social-share-kit.min.js --- dist/js/social-share-kit.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/js/social-share-kit.min.js b/dist/js/social-share-kit.min.js index e20b553..761ff41 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(){var t,n,r=/(twitter|facebook|google-plus|pinterest|tumblr|vk|linkedin|buffer|email)/;function o(e){return document.querySelectorAll(e)}function p(e){return e.className.match(r)}function h(e,t,n,r){return(r=r||v(e,t,n)).url||window.location.href}function f(e,t){var n,r=o("meta["+(t||(0===e.indexOf("og:")?"property":"name"))+'="'+e+'"]');return r.length&&(n=r[0].getAttribute("content")||""),n||""}function m(e){return e||""===e}function v(e,t,n){var r,o,i,a,c=["url","title","text","image"],s={},u=n.parentNode;for(a in"twitter"==t&&c.push("via"),c){i="data-"+(o=c[a]);var d=n.getAttribute(i);if(!m(r=void 0!==d&&d)){var l=u.getAttribute(i);r="undefined"!=l&&l}m(r)||(r=e[t]&&void 0!==e[t][o]?e[t][o]:e[o]),void 0!==r&&(s[o]=r)}return s}function i(e,t){var n=document.createElement("div");n.innerHTML=t,n.className="ssk-num",e.appendChild(n)}function a(e,t,n,r){var o,i,a,c,s,u,d=encodeURIComponent(t);switch(e){case"facebook":o="https://graph.facebook.com/?id="+d,i=function(e){return r(e.share?e.share.share_count:0)};break;case"twitter":n&&n.twitter&&n.twitter.countCallback&&n.twitter.countCallback(t,r);break;case"google-plus":return a=o="https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",c=i=function(e){if((e=JSON.parse(e)).length)return r(e[0].result.metadata.globalCounts.count)},s='[{"method":"pos.plusones.get","id":"p","params":{"id":"'+t+'","userId":"@viewer","groupId":"@self","nolog":true},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]',(u=new XMLHttpRequest).onreadystatechange=function(){4===this.readyState&&200<=this.status&&this.status<400&&c(this.responseText)},u.open("POST",a,!0),u.setRequestHeader("Content-Type","application/json"),void u.send(s);case"linkedin":o="https://www.linkedin.com/countserv/count/share?url="+d,i=function(e){return r(e.count)};break;case"pinterest":o="https://api.pinterest.com/v1/urls/count.json?url="+d,i=function(e){return r(e.count)};break;case"vk":o="https://vk.com/share.php?act=count&url="+d,i=function(e){return r(e)};break;case"buffer":o="https://api.bufferapp.com/1/links/shares.json?url="+d,i=function(e){return r(e.shares)}}o&&i&&function(e,t,n){var r="cb_"+e+"_"+Math.round(1e5*Math.random()),o=document.createElement("script");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+(0<=t.indexOf("?")?"&":"?")+"callback="+r,document.body.appendChild(o)}(e,o,i)}return(n=function(e){var t=e||{},n=t.selector||".ssk";this.nodes=o(n),this.options=t}).prototype={share:function(){var e,t=this.nodes,u=this.options,d={},n=function(){t.length&&(function(e,t){for(var n=0;n