1// VERSION: 1.0 LAST UPDATE: 18.12.2014 2/* 3 * . . . 4 * | | | 5 * ,-. ,-. |-. . . |- |- ,-. ;-. ,-. 6 * | `-. | | | | | | | | | | `-. 7 * `-' `-' `-' `-` `-' `-' `-' ' ' `-' 8 * 9 * Social customs counter buttons (Facebook, Twitter, Google+, LinkedIn, Pinterest) 10 * Made by Mathieu ORLANDO, [email protected], Acrow, FRANCE 11 * Website: http://csbuttons.acrow.fr/ 12 */ 13(function($) 14{ 15 $.fn.cSButtons = function(options) 16 { 17 // Default params 18 var defaults = 19 { 20 "url" : null, 21 "type" : 'facebook', 22 "txt" : null, 23 "via" : null, 24 "count" : false, 25 "count_position" : 'right', 26 "apikey": null, 27 "media" : null, 28 "lang" : null, 29 "total" : null, 30 } 31 32 var parametres = $.extend(defaults, options); 33 var totalShare = 0; 34 var nbButtons = this.length; 35 var i = 0; 36 var jg = 0; 37 38 return this.each(function() 39 { 40 i++; 41 // If option on the link attributs 42 var url = ($(this).attr('data-url') != undefined && $(this).attr('data-url') != '') ? $(this).attr('data-url') : parametres.url; 43 var type = ($(this).attr('data-type') != undefined && $(this).attr('data-type') != '') ? $(this).attr('data-type') : parametres.type; 44 var txt = ($(this).attr('data-txt') != undefined && $(this).attr('data-txt') != '') ? $(this).attr('data-txt') : parametres.txt; 45 var via = ($(this).attr('data-via') != undefined && $(this).attr('data-via') != '') ? $(this).attr('data-via') : parametres.via; 46 var count = ($(this).attr('data-count') != undefined && $(this).attr('data-count') != '') ? $(this).attr('data-count') : parametres.count; 47 var cPosition = ($(this).attr('data-count-position') != undefined && $(this).attr('data-count-position') != '') ? $(this).attr('data-count-position') : parametres.count_position; 48 var apikey = ($(this).attr('data-apikey') != undefined && $(this).attr('data-apikey') != '') ? $(this).attr('data-apikey') : parametres.apikey; 49 var media = ($(this).attr('data-media') != undefined && $(this).attr('data-media') != '') ? $(this).attr('data-media') : parametres.media; 50 var lang = ($(this).attr('data-lang') != undefined && $(this).attr('data-lang') != '') ? $(this).attr('data-lang') : parametres.lang; 51 var popupWidth = 0; 52 var popupHeight = 0; 53 var shareUrl = ''; 54 55 // Url use to share 56 url = (url != null) ? url : document.URL; 57 $URL = url; 58 59 // If count total share 60 if(count){ 61 if(cPosition == 'left'){ 62 $(this).prepend('<span class="csbuttons-count" />'); 63 } 64 else 65 { 66 $(this).append('<span class="csbuttons-count" />'); 67 } 68 } 69 70 switch(type) 71 { 72 case 'twitter': // Twitter share 73 var twitter = $(this); 74 popupWidth = 550; 75 popupHeight = 420; 76 shareUrl = (txt != null) ? 'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(document.URL) + '&text=' + encodeURIComponent(txt) + '&url=' + encodeURIComponent(url) : 'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(document.URL) + '&url=' + encodeURIComponent(url); 77 shareUrl = (via != null) ? shareUrl + '&via=' + via : shareUrl; 78 79 if(count) 80 { 81 $('span.csbuttons-count', twitter).text(0); 82 $.getJSON('http://cdn.api.twitter.com/1/urls/count.json?url=' + $URL + '&callback=?', function( twitdata ) { 83 $('span.csbuttons-count', twitter).text(twitdata.count); 84 totalShare += (isNaN(parseInt(twitdata.count))) ? 0 : parseInt(twitdata.count); 85 if(parametres.total != null && i == nbButtons) 86 $(parametres.total).text(totalShare); 87 }); 88 } 89 break; 90 case 'google': // Google + share 91 var google = $(this); 92 jg++; 93 94 popupWidth = 600; 95 popupHeight = 600; 96 shareUrl = 'https://plus.google.com/share?url=' + url; 97 shareUrl = (lang != null) ? shareUrl + '&hl=' + lang : shareUrl; 98 99 if(count) 100 { 101 $('span.csbuttons-count', google).text(0); 102 if(apikey != null) 103 { 104 $.post('https://clients6.google.com/rpc?key=' + apikey, 105 { 106 "method":"pos.plusones.get", 107 "id":"p", 108 "params":{ 109 "nolog":true, 110 "id": $URL, 111 "source":"widget", 112 "userId":"@viewer", 113 "groupId":"@self" 114 }, 115 "jsonrpc":"2.0", 116 "key":"p", 117 "apiVersion":"v1" 118 }, 119 function(gpdata){ 120 $('span.csbuttons-count', google).text(gpdata.result.metadata.globalCounts.count); 121 totalShare += (isNaN(parseInt(gpdata.result.metadata.globalCounts.count))) ? 0 : parseInt(gpdata.result.metadata.globalCounts.count); 122 if(parametres.total != null && i == nbButtons) 123 $(parametres.total).text(totalShare); 124 }); 125 } 126 else // Alternative yandex 127 { 128 window['gplus'+jg] = google; 129 if (!window.services) window.services = {}; 130 window.services.gplus = { 131 cb: function(number) { 132 window['gplusnb'+jg] = (number == '') ? 0 : number; 133 } 134 }; 135 136 $.getScript( 'http://share.yandex.ru/gpp.xml?url=' + $URL + '&callback=?', function(){ 137 $('span.csbuttons-count', google).text(window['gplusnb'+jg]); 138 totalShare += (isNaN(parseInt(window['gplusnb'+jg]))) ? 0 : parseInt(window['gplusnb'+jg]); 139 if(parametres.total != null && i == nbButtons) 140 $(parametres.total).text(totalShare); 141 }); 142 } 143 } 144 break; 145 case 'linkedin' : // Linkedin share 146 var linkedin = $(this); 147 popupWidth = 600; 148 popupHeight = 213; 149 shareUrl = 'https://www.linkedin.com/cws/share?url=' + url; 150 151 if(count) 152 { 153 $('span.csbuttons-count', linkedin).text(0); 154 $.getJSON('http://www.linkedin.com/countserv/count/share?url=' + $URL + '&callback=?', function( indata ) { 155 $('span.csbuttons-count', linkedin).text(indata.count); 156 totalShare += (isNaN(parseInt(indata.count))) ? 0 : parseInt(indata.count); 157 if(parametres.total != null && i == nbButtons) 158 $(parametres.total).text(totalShare); 159 }); 160 } 161 break; 162 case 'pinterest': // Pinterest share 163 var pinterest = $(this); 164 popupWidth = 1000; 165 popupHeight = 617; 166 shareUrl = 'http://www.pinterest.com/pin/create/button/?url=' + url; 167 shareUrl = (media != null) ? shareUrl + '&media=' + media : shareUrl; 168 shareUrl = (txt != null) ? shareUrl + '&description=' + txt : shareUrl; 169 170 if(count) 171 { 172 $('span.csbuttons-count', pinterest).text(0); 173 $.getJSON('https://api.pinterest.com/v1/urls/count.json?url=' + $URL + '&callback=?', function( ptrdata ) { 174 $('span.csbuttons-count', pinterest).text(ptrdata.count); 175 totalShare += (isNaN(parseInt(ptrdata.count))) ? 0 : parseInt(ptrdata.count); 176 if(parametres.total != null && i == nbButtons) 177 $(parametres.total).text(totalShare); 178 }) 179 } 180 break; 181 default: // Default Facebook share 182 var facebook = $(this); 183 popupWidth = 670; 184 popupHeight = 340; 185 shareUrl = 'https://www.facebook.com/sharer/sharer.php?u=' + url; 186 187 if(count) 188 { 189 $('span.csbuttons-count', facebook).text(0); 190 $.getJSON('http://graph.facebook.com/?id=' + $URL, function( fbdata ) { 191 $('span.csbuttons-count', facebook).text(fbdata.shares); 192 193 totalShare += (isNaN(parseInt(fbdata.shares))) ? 0 : parseInt(fbdata.shares); 194 if(parametres.total != null && i == nbButtons) 195 $(parametres.total).text(totalShare); 196 }); 197 } 198 break; 199 } 200 201 // Click to Action Open Popup Share 202 $(this).on('click tap', function() 203 { 204 // Center popup to the screen 205 var left = (screen.width/2)-(popupWidth/2);
206 var top = (screen.height/2)-(popupHeight/2); 207 208 popupWindow = window.open(shareUrl,'popUpWindow','height=' + popupHeight + ',width=' + popupWidth + ',left=' + left + ',top=' + top + ',resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes'); 209 }); 210 }); 211 }; 212})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.