diff --git a/README.md b/README.md index 0e2a109..5cd6512 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Or install via npm and include from your `node_modules` folder Or install via zip, then include jQuery and Font-Awesome and the plugin on a page. ```html - + @@ -51,6 +51,7 @@ To make the social share buttons appear next to the specific content, instead of * **place**: `String` *(`top-left` by default)* Set the position of the box. Currently: `content-left`, `top-left` and `top-right` are available. * **counter**: `Boolean` *(`true` by default)* Set to `false` to hide counters that appear below the buttons. +* **twitter_counter**: `Boolean` *(`false` by default)* Set to `true` to show twitter counter, but you also need to register to [Open Share Count](https://opensharecount.com/) since Twitter API does not provide counters without an API key. * **buttons**: `Array` *(`["facebook", "twitter", "google-plus"]` by default)* Sets the social buttons for sharing. Available ones are `envelope`, `facebook`, `google-plus`, `linkedin`, `odnoklassniki`, `pinterest`, `reddit`, `stumbleupon`, `tumblr`, `twitter` and `vk` * **title**: `String` *(`document.title` by default)* Sets the title for the share message. * **url**: `String` *(`window.location.href` by default)* Sets the url for the share message. @@ -66,6 +67,7 @@ To make the social share buttons appear next to the specific content, instead of $("body").floatingSocialShare({ place: "top-left", // alternatively content-left, top-right counter: true, // set to false for hiding the counters of buttons + twitter_counter: false, // Twitter API does not provide counters without API key, register to https://opensharecount.com/ buttons: ["envelope", "facebook", "google-plus", "linkedin", "odnoklassniki", "pinterest", "reddit", "stumbleupon", "tumblr", "twitter", "vk"], // all of the currently avalaible social buttons title: document.title, // your title, default is current page's title url: window.location.href, // your url, default is current page's url diff --git a/bower.json b/bower.json index 57995be..542a6b2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-floating-social-share", - "version": "1.2.0", + "version": "1.2.1", "homepage": "http://github.com/ozdemirburak/jquery-floating-social-share", "authors": [ "Burak Ozdemir " @@ -30,7 +30,7 @@ ], "description": "social media share buttons with counters", "dependencies": { - "jquery": "~1.11.1", - "font-awesome": "~4.4.0" + "jquery": ">=1.8", + "font-awesome": ">=4.0" } } diff --git a/demo/content.html b/demo/content.html index d1a40a8..8f3f4de 100644 --- a/demo/content.html +++ b/demo/content.html @@ -5,7 +5,7 @@ jQuery Floating Social Share - + @@ -23,8 +23,8 @@ buttons: ["facebook", "twitter", "google-plus", "linkedin", "pinterest"], text: "share with: ", place: "content-left", - url: "https://google.com" + url: "http://google.com" }); - \ No newline at end of file + diff --git a/demo/index.html b/demo/index.html index 4057ee8..abdc8b2 100644 --- a/demo/index.html +++ b/demo/index.html @@ -5,7 +5,7 @@ jQuery Floating Social Share - + @@ -21,9 +21,10 @@ - \ No newline at end of file + diff --git a/dist/jquery.floating-social-share.min.css b/dist/jquery.floating-social-share.min.css index b7966ba..a85a41b 100644 --- a/dist/jquery.floating-social-share.min.css +++ b/dist/jquery.floating-social-share.min.css @@ -1,7 +1 @@ -/*! - * jQuery Floating Social Share Plugin v1.2.0 - * http://burakozdemir.co.uk - * Burak Ozdemir - - * Released under the MIT license - */ -*{box-sizing:border-box}#floatingSocialShare{position:relative}#floatingSocialShare a{position:relative;width:48px;height:48px;line-height:24px;display:list-item;list-style-type:none;padding:5px 0;text-align:center;color:#fff}#floatingSocialShare a:focus,#floatingSocialShare a:hover{color:#fff;width:52px;opacity:.8;transition-duration:.3s;transition-property:right;transition-timing-function:ease-out}#floatingSocialShare a,#floatingSocialShare a:active,#floatingSocialShare a:focus,#floatingSocialShare a:hover,#floatingSocialShare a:visited{outline:0!important}#floatingSocialShare i{line-height:inherit;font-size:24px;text-align:center}#floatingSocialShare .content-left,#floatingSocialShare .top-left,#floatingSocialShare .top-right{position:fixed;top:25%}#floatingSocialShare .top-left{left:0}#floatingSocialShare .top-right{right:0}#floatingSocialShare .content-left{margin:0 0 0 -75px}#floatingSocialShare .facebook{background-color:#3b5998}#floatingSocialShare .twitter{background-color:#00aced}#floatingSocialShare .google-plus{background-color:#dd4b39}#floatingSocialShare .linkedin{background-color:#007bb6}#floatingSocialShare .envelope{background-color:#726C6C}#floatingSocialShare .pinterest{background-color:#c92228}#floatingSocialShare .stumbleupon{background-color:#eb4924}#floatingSocialShare .reddit{background-color:#a9bacb}#floatingSocialShare .tumblr{background-color:#36465d}#floatingSocialShare .vk{background-color:#6383a8}#floatingSocialShare .odnoklassniki{background-color:#f6900b}#floatingSocialShare .shareCount{position:absolute;bottom:0;right:0;left:0;margin:auto;color:#fff;font-size:10px}#floatingSocialShare .margin-top-5{margin-top:5px}@media only screen and (min-device-width:0px) and (max-width:961px){#floatingSocialShare{margin-top:50px}#floatingSocialShare .content-left,#floatingSocialShare .top-left,#floatingSocialShare .top-right{top:auto;bottom:0;margin:0;right:0;left:0;width:100%;z-index:999}#floatingSocialShare a{position:relative;float:left;display:list-item;list-style-type:none}#floatingSocialShare a:focus,#floatingSocialShare a:hover{-moz-transition-property:none;-webkit-transition-property:none;-o-transition-property:none;transition-property:none}} \ No newline at end of file +*{box-sizing:border-box}#floatingSocialShare{position:relative}#floatingSocialShare a{position:relative;width:48px;height:48px;line-height:24px;display:list-item;list-style-type:none;padding:5px 0;text-align:center;color:#fff}#floatingSocialShare a:focus,#floatingSocialShare a:hover{color:#fff;width:52px;opacity:.8;transition-duration:.3s;transition-property:right;transition-timing-function:ease-out}#floatingSocialShare a,#floatingSocialShare a:active,#floatingSocialShare a:focus,#floatingSocialShare a:hover,#floatingSocialShare a:visited{outline:0!important}#floatingSocialShare i{line-height:inherit;font-size:24px;text-align:center}#floatingSocialShare .content-left,#floatingSocialShare .top-left,#floatingSocialShare .top-right{position:fixed;top:25%}#floatingSocialShare .top-left{left:0}#floatingSocialShare .top-right{right:0}#floatingSocialShare .content-left{margin:0 0 0 -75px}#floatingSocialShare .facebook{background-color:#3b5998}#floatingSocialShare .twitter{background-color:#00aced}#floatingSocialShare .google-plus{background-color:#dd4b39}#floatingSocialShare .linkedin{background-color:#007bb6}#floatingSocialShare .envelope{background-color:#726C6C}#floatingSocialShare .pinterest{background-color:#c92228}#floatingSocialShare .stumbleupon{background-color:#eb4924}#floatingSocialShare .reddit{background-color:#a9bacb}#floatingSocialShare .tumblr{background-color:#36465d}#floatingSocialShare .vk{background-color:#6383a8}#floatingSocialShare .odnoklassniki{background-color:#f6900b}#floatingSocialShare .shareCount{position:absolute;bottom:0;right:0;left:0;margin:auto;color:#fff;font-size:10px}#floatingSocialShare .margin-top-5{margin-top:5px}@media only screen and (min-device-width:0px) and (max-width:961px){#floatingSocialShare{margin-top:50px}#floatingSocialShare .content-left,#floatingSocialShare .top-left,#floatingSocialShare .top-right{top:auto;bottom:0;margin:0;right:0;left:0;width:100%;z-index:999}#floatingSocialShare a{position:relative;float:left;display:list-item;list-style-type:none}#floatingSocialShare a:focus,#floatingSocialShare a:hover{-moz-transition-property:none;-webkit-transition-property:none;-o-transition-property:none;transition-property:none}} diff --git a/dist/jquery.floating-social-share.min.js b/dist/jquery.floating-social-share.min.js index 9253b45..d201ec9 100644 --- a/dist/jquery.floating-social-share.min.js +++ b/dist/jquery.floating-social-share.min.js @@ -1,7 +1 @@ -/*! - * jQuery Floating Social Share Plugin v1.2.0 - * http://burakozdemir.co.uk - * Burak Ozdemir - - * Released under the MIT license - */ -!function(t,e,i,n){"use strict";function s(e,i){this.element=e,this.settings=t.extend({},p,i),this._defaults=p,this._name=u,this.init()}function r(t,n,s,r){var c=e.innerWidth?e.innerWidth:i.documentElement.clientWidth?i.documentElement.clientWidth:screen.width,l=e.innerHeight?e.innerHeight:i.documentElement.clientHeight?i.documentElement.clientHeight:screen.height,a=c/2-s/2+10,o=l/2-r/2+50;e.open(t,n,"scrollbars=yes, width="+s+", height="+r+", top="+o+", left="+a).focus()}function c(t){return t>=1e9?(t/1e9).toFixed(1).replace(/\.0$/,"")+"G":t>=1e6?(t/1e6).toFixed(1).replace(/\.0$/,"")+"M":t>=1e3?(t/1e3).toFixed(1).replace(/\.0$/,"")+"K":t}function l(n){var s=e.innerWidth?e.innerWidth:i.documentElement.clientWidth?i.documentElement.clientWidth:screen.width;t.each(n,function(){961>s?t(this).css("width",100/n.length+"%"):t(this).removeAttr("style")})}function a(e,i){e&&e>0&&i.append(t("",{"class":"shareCount"}).append(c(e))).find("i").removeClass("margin-top-5")}function o(i,n,s){switch(i){case"facebook":t.get("https://graph.facebook.com/"+n,function(t){a(t.shares,s)},"jsonp");break;case"google-plus":t.get("https://share.yandex.ru/gpp.xml?url="+n+"&callback=?",function(){},"jsonp"),e.services=e.services||{},e.services.gplus=e.services.gplus||{},e.services.gplus.cb=function(t){a(t,s)};break;case"linkedin":t.get("https://www.linkedin.com/countserv/count/share?url="+n+"&callback=?",function(t){a(t.count,s)},"jsonp");break;case"odnoklassniki":t.get("https://connect.ok.ru/dk?st.cmd=extLike&ref="+n+"&callback=?",function(){},"jsonp"),e.ODKL=e.ODKL||{},e.ODKL.updateCount=function(t,e){a(e,s)};break;case"pinterest":t.get("https://api.pinterest.com/v1/urls/count.json?url="+n+"&callback=?",function(t){a(t.count,s)},"jsonp");break;case"reddit":t.get("https://www.reddit.com/api/info.json?url="+n+"&jsonp=?",function(t){a(t.data.children[0].data.score,s)},"jsonp");break;case"tumblr":t.get("https://api.tumblr.com/v2/share/stats?url="+n+"&callback=?",function(t){a(t.response.note_count,s)},"jsonp");break;case"twitter":t.get("https://urls.api.twitter.com/1/urls/count.json?url="+n+"&callback=?",function(t){a(t.count,s)},"jsonp");break;case"vk":t.get("https://vk.com/share.php?act=count&index=1&url="+n+"&callback=?",function(){},"jsonp"),e.VK=e.VK||{},e.VK.Share=e.VK.Share||{},e.VK.Share.count=function(t,e){a(e,s)};break;default:return-1}}var u="floatingSocialShare",p={place:"top-left",counter:!0,buttons:["facebook","twitter","google-plus"],title:i.title,url:e.location.href,description:t('meta[name="description"]').attr("content")||"",media:t('meta[property="og:image"]').attr("content")||"",text:"share with ",popup_width:400,popup_height:300};t.extend(s.prototype,{init:function(){-1==t.inArray(this.settings.place,h)&&(this.settings.place=this._defaults.place);var i=this,n=t("
",{id:"floatingSocialShare"}),s=t("
",{"class":this.settings.place}).appendTo(n);t.each(this.settings.buttons,function(e,n){t.each(d,function(e,r){if(n===e){var c=t("",{"class":"margin-top-5 fa fa-"+n}),l=r.url.replace("{url}",i.settings.url).replace("{title}",i.settings.title).replace("{description}",i.settings.description).replace("{media}",i.settings.media),a=t("",{title:i.settings.title,"class":r.className+" pop-upper"}).attr("href",l).attr("title",i.settings.text+n).append(c);return i.settings.counter===!0&&o(n,encodeURI(i.settings.url),a),s.append(a),!1}})}),n.appendTo(this.element);var c=t(this.element).find(".pop-upper");c.on("click",function(e){e.preventDefault(),r(t(this).attr("href"),t(this).attr("title"),i.settings.popup_width,i.settings.popup_height)}),l(c),t(e).resize(function(){l(c)})}});var h=["content-left","top-left","top-right"],d={envelope:{className:"envelope",url:"mailto:user@domain.com?subject={url}"},facebook:{className:"facebook",url:"https://www.facebook.com/sharer/sharer.php?u={url}&t={title}"},"google-plus":{className:"google-plus",url:"https://plus.google.com/share?url={url}"},linkedin:{className:"linkedin",url:"https://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={description}&source="},odnoklassniki:{className:"odnoklassniki",url:"https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl={url}"},pinterest:{className:"pinterest",url:"https://pinterest.com/pin/create%2Fbutton/?url={url}&description={description}&media={media}"},reddit:{className:"reddit",url:"https://www.reddit.com/submit?url={url}&title={title}"},stumbleupon:{className:"stumbleupon",url:"https://www.stumbleupon.com/submit?url={url}&title={title}"},tumblr:{className:"tumblr",url:"https://www.tumblr.com/share/link?url={url}&name={title}&description={description}"},twitter:{className:"twitter",url:"https://twitter.com/home?status={url}"},vk:{className:"vk",url:"https://vk.com/share.php?url={url}&title={title}&description={description}"}};t.fn[u]=function(e){return this.each(function(){t.data(this,"plugin_"+u)||t.data(this,"plugin_"+u,new s(this,e))})}}(jQuery,window,document); \ No newline at end of file +!function(t,e,n,i){"use strict";function s(e,n){this.element=e,this.settings=t.extend({},p,n),this._defaults=p,this._name=u,this.init()}function r(t,i,s,r){var o=e.innerWidth?e.innerWidth:n.documentElement.clientWidth?n.documentElement.clientWidth:screen.width,a=e.innerHeight?e.innerHeight:n.documentElement.clientHeight?n.documentElement.clientHeight:screen.height,c=o/2-s/2+10,l=a/2-r/2+50;e.open(t,i,"scrollbars=yes, width="+s+", height="+r+", top="+l+", left="+c).focus()}function o(t){return t>=1e9?(t/1e9).toFixed(1).replace(/\.0$/,"")+"G":t>=1e6?(t/1e6).toFixed(1).replace(/\.0$/,"")+"M":t>=1e3?(t/1e3).toFixed(1).replace(/\.0$/,"")+"K":t}function a(i){var s=e.innerWidth?e.innerWidth:n.documentElement.clientWidth?n.documentElement.clientWidth:screen.width;t.each(i,function(){961>s?t(this).css("width",100/i.length+"%"):t(this).removeAttr("style")})}function c(e,n){e&&e>0&&n.append(t("",{"class":"shareCount"}).append(o(e))).find("i").removeClass("margin-top-5")}function l(n,i,s,r){switch(n){case"facebook":t.get("https://graph.facebook.com/"+i,function(t){c(t.shares,s)},"jsonp");break;case"google-plus":t.get("https://share.yandex.ru/gpp.xml?url="+i+"&callback=?",function(t){c(t,s)},"jsonp");break;case"linkedin":t.get("https://www.linkedin.com/countserv/count/share?url="+i+"&callback=?",function(t){c(t.count,s)},"jsonp");break;case"odnoklassniki":t.get("https://connect.ok.ru/dk?st.cmd=extLike&ref="+i+"&callback=?",function(){},"jsonp"),e.ODKL=e.ODKL||{},e.ODKL.updateCount=function(t,e){c(e,s)};break;case"pinterest":t.get("https://api.pinterest.com/v1/urls/count.json?url="+i+"&callback=?",function(t){c(t.count,s)},"jsonp");break;case"reddit":t.get("https://www.reddit.com/api/info.json?url="+i+"&jsonp=?",function(t){c(t.data.children[0].data.score,s)},"jsonp");break;case"tumblr":t.get("https://api.tumblr.com/v2/share/stats?url="+i+"&callback=?",function(t){c(t.response.note_count,s)},"jsonp");break;case"twitter":1==r&&t.get("https://opensharecount.com/count.json?url="+i+"&callback=?",function(t){c(t.count,s)},"jsonp");break;case"vk":t.get("https://vk.com/share.php?act=count&index=1&url="+i+"&callback=?",function(){},"jsonp"),e.VK=e.VK||{},e.VK.Share=e.VK.Share||{},e.VK.Share.count=function(t,e){c(e,s)};break;default:return-1}}var u="floatingSocialShare",p={place:"top-left",counter:!0,twitter_counter:!1,buttons:["facebook","twitter","google-plus"],title:n.title,url:e.location.href,description:t('meta[name="description"]').attr("content")||"",media:t('meta[property="og:image"]').attr("content")||"",text:"share with ",popup_width:400,popup_height:300};t.extend(s.prototype,{init:function(){-1==t.inArray(this.settings.place,h)&&(this.settings.place=this._defaults.place);var n=this,i=t("
",{id:"floatingSocialShare"}),s=t("
",{"class":this.settings.place}).appendTo(i);t.each(this.settings.buttons,function(e,i){t.each(d,function(e,r){if(i===e){var o=t("",{"class":"margin-top-5 fa fa-"+i}),a=r.url.replace("{url}",n.settings.url).replace("{title}",n.settings.title).replace("{description}",n.settings.description).replace("{media}",n.settings.media),c=t("",{title:n.settings.title,"class":r.className+" pop-upper"}).attr("href",a).attr("title",n.settings.text+i).append(o);return n.settings.counter===!0&&l(i,encodeURI(n.settings.url),c,n.settings.twitter_counter),s.append(c),!1}})}),i.appendTo(this.element);var o=t(this.element).find(".pop-upper");o.on("click",function(e){e.preventDefault(),r(t(this).attr("href"),t(this).attr("title"),n.settings.popup_width,n.settings.popup_height)}),a(o),t(e).resize(function(){a(o)})}});var h=["content-left","top-left","top-right"],d={envelope:{className:"envelope",url:"mailto:user@domain.com?subject={url}"},facebook:{className:"facebook",url:"https://www.facebook.com/sharer/sharer.php?u={url}&t={title}"},"google-plus":{className:"google-plus",url:"https://plus.google.com/share?url={url}"},linkedin:{className:"linkedin",url:"https://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={description}&source="},odnoklassniki:{className:"odnoklassniki",url:"https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl={url}"},pinterest:{className:"pinterest",url:"https://pinterest.com/pin/create%2Fbutton/?url={url}&description={description}&media={media}"},reddit:{className:"reddit",url:"https://www.reddit.com/submit?url={url}&title={title}"},stumbleupon:{className:"stumbleupon",url:"https://www.stumbleupon.com/submit?url={url}&title={title}"},tumblr:{className:"tumblr",url:"https://www.tumblr.com/share/link?url={url}&name={title}&description={description}"},twitter:{className:"twitter",url:"https://twitter.com/home?status={url}"},vk:{className:"vk",url:"https://vk.com/share.php?url={url}&title={title}&description={description}"}};t.fn[u]=function(e){return this.each(function(){t.data(this,"plugin_"+u)||t.data(this,"plugin_"+u,new s(this,e))})}}(jQuery,window,document); diff --git a/package.json b/package.json index 6c6c1f9..0c4f096 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-floating-social-share", - "version": "1.2.0", + "version": "1.2.1", "description": "social media share buttons with counters", "main": [ "dist/jquery-floating-social-share.min.js", @@ -11,8 +11,8 @@ "url": "https://github.com/ozdemirburak/jquery-floating-share-plugin.git" }, "devDependencies": { - "jquery": "~1.11.1", - "font-awesome": "~4.4.0" + "jquery": ">=1.8", + "font-awesome": ">=4.0" }, "keywords": [ "social", diff --git a/src/jquery.floating-social-share.css b/src/jquery.floating-social-share.css index 774679f..d64f452 100644 --- a/src/jquery.floating-social-share.css +++ b/src/jquery.floating-social-share.css @@ -1,5 +1,5 @@ /*! - * jQuery Floating Social Share Plugin v1.1.1 + * jQuery Floating Social Share Plugin v1.2.1 * http://burakozdemir.co.uk * Burak Ozdemir - * Released under the MIT license diff --git a/src/jquery.floating-social-share.js b/src/jquery.floating-social-share.js index 81576d7..3d90f0a 100644 --- a/src/jquery.floating-social-share.js +++ b/src/jquery.floating-social-share.js @@ -1,5 +1,5 @@ /*! - * jQuery Floating Social Share Plugin v1.1.1 + * jQuery Floating Social Share Plugin v1.2.1 * http://burakozdemir.co.uk * Burak Ozdemir - * Released under the MIT license @@ -13,6 +13,7 @@ defaults = { place: "top-left", counter: true, + twitter_counter: false, buttons: ["facebook", "twitter", "google-plus"], title: document.title, url: window.location.href, @@ -34,8 +35,9 @@ $.extend(Plugin.prototype, { init: function() { - if ($.inArray(this.settings.place, places) == -1) + if ($.inArray(this.settings.place, places) == -1) { this.settings.place = this._defaults.place; + } var base = this, $template = $("
", { id: "floatingSocialShare" }), @@ -50,8 +52,9 @@ .replace('{description}', base.settings.description) .replace('{media}', base.settings.media), $component = $("", { title: base.settings.title, class: v.className + " pop-upper"}).attr("href", _href).attr("title", base.settings.text + value).append($icon); - if(base.settings.counter === true) - setShareCount(value, encodeURI(base.settings.url), $component); + if (base.settings.counter === true) { + setShareCount(value, encodeURI(base.settings.url), $component, base.settings.twitter_counter); + } $child.append($component); return false; } @@ -60,17 +63,17 @@ $template.appendTo(this.element); - var diss = $(this.element).find(".pop-upper"); + var popup = $(this.element).find(".pop-upper"); - diss.on("click",function(event) { + popup.on("click",function(event) { event.preventDefault(); openPopUp($(this).attr("href"), $(this).attr("title"), base.settings.popup_width, base.settings.popup_height); }); - setMobileCss(diss); + setMobileCss(popup); $(window).resize(function() { - setMobileCss(diss); + setMobileCss(popup); }); } @@ -160,7 +163,7 @@ } } - function setShareCount(network, url, $component) { + function setShareCount(network, url, $component, twitter_counter) { switch(network) { case "facebook": $.get('https://graph.facebook.com/'+ url, function(data) { @@ -168,12 +171,9 @@ },'jsonp'); break; case "google-plus": - $.get('https://share.yandex.ru/gpp.xml?url='+ url +'&callback=?', function() {}, 'jsonp'); - window.services = window.services || {}; - window.services.gplus = window.services.gplus || {}; - window.services.gplus.cb = function(count) { + $.get('https://share.yandex.ru/gpp.xml?url='+ url +'&callback=?', function(count) { appendButtons(count, $component); - }; + }, 'jsonp'); break; case "linkedin": $.get('https://www.linkedin.com/countserv/count/share?url='+ url +'&callback=?', function(data) { @@ -203,9 +203,11 @@ },'jsonp'); break; case "twitter": - $.get('https://urls.api.twitter.com/1/urls/count.json?url='+ url +'&callback=?', function(data) { - appendButtons(data.count, $component); - },'jsonp'); + if (twitter_counter == true) { + $.get('https://opensharecount.com/count.json?url='+ url +'&callback=?', function(data) { + appendButtons(data.count, $component); + },'jsonp'); + } break; case "vk": $.get('https://vk.com/share.php?act=count&index=1&url='+ url +'&callback=?', function() {},'jsonp');