1/*! 2 * Sharrre.com - Make your sharing widget! 3 * Version: beta 1.3.5 4 * Author: Julien Hany 5 * License: MIT http://en.wikipedia.org/wiki/MIT_License or GPLv2 http://en.wikipedia.org/wiki/GNU_General_Public_License 6 */ 7 8/** 9 * Track to GA via GTM 10 */ 11sharrre_track = function (site, action, targetUrl) { 12 if (typeof dataLayer !== 'undefined') { 13 dataLayer.push({ 14 "event" : "track-social", 15 "action": site, 16 "label" : action 17 }); 18 } 19}; 20 21addURLParam = function (url, paramName, paramValue) { 22 var index = url.indexOf(paramName), 23 hash_index = url.indexOf("#"), 24 hash = ""; 25 26 // Save hash for later 27 if (hash_index > -1) { 28 hash = url.substring(hash_index); 29 url = url.substring(0, hash_index); 30 } 31 32 // Update url with new value 33 if (url.indexOf(paramName + "=") >= 0) { 34 // update existing param 35 var prefix = url.substring(0, index), 36 suffix = url.substring(index); 37 suffix = suffix.substring(suffix.indexOf("=") + 1); 38 suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : ""; 39 url = prefix + paramName + "=" + paramValue + suffix; 40 } else { 41 // add new 42 if (url.indexOf("?") < 0) 43 url += "?" + paramName + "=" + paramValue; 44 else 45 url += "&" + paramName + "=" + paramValue; 46 } 47 return url + hash; 48}; 49 50(function ($, window, document, undefined) { 51 52 /* Defaults 53 ================================================== */ 54 var pluginName = 'sharrre', 55 defaults = { 56 className : 'sharrre', 57 share : { 58 googlePlus : false, 59 facebook : false, 60 twitter : false, 61 digg : false, 62 delicious : false, 63 stumbleupon: false, 64 linkedin : false, 65 pinterest : false, 66 reddit : false, 67 email : false, 68 sms : false, 69 whatsapp : false, 70 tumblr : false 71 }, 72 shareTotal : 0, 73 template : '', 74 title : '', 75 url : document.location.href, 76 utmSource : false, 77 text : document.title, 78 urlCurl : '/wp-content/plugins/wp-pi-sharrre/sharrre.php', //PHP script for google plus... 79 count : {}, //counter by social network 80 total : 0, //total of sharing 81 shorterTotal : true, //show total by k or M when number is to big 82 enableHover : true, //disable if you want to personalize hover event with callback 83 enableCounter : true, //disable if you just want use buttons 84 enableTracking: false, //tracking with google analitycs 85 hover : function () { 86 }, //personalize hover event with this callback function 87 hide : function () { 88 }, //personalize hide event with this callback function 89 click : function () { 90 }, //personalize click event with this callback function 91 render : function () { 92 }, //personalize render event with this callback function 93 buttons : { //settings for buttons 94 googlePlus : { //http://www.google.com/webmasters/+1/button/ 95 url : '', //if you need to personnalize button url 96 urlCount : false, //if you want to use personnalize button url on global counter 97 size : 'medium', 98 lang : 'en-US', 99 annotation: '' 100 }, 101 facebook : { //http://developers.facebook.com/docs/reference/plugins/like/ 102 url : '', //if you need to personalize url button 103 urlCount : false, //if you want to use personnalize button url on global counter 104 action : 'like', 105 layout : 'button_count', 106 width : '', 107 send : 'false', 108 faces : 'false', 109 colorscheme: '', 110 font : '', 111 lang : 'en_US' 112 }, 113 twitter : { //http://twitter.com/about/resources/tweetbutton 114 url : '', //if you need to personalize url button 115 urlCount: false, //if you want to use personnalize button url on global counter 116 count : 'horizontal', 117 hashtags: '', 118 via : '', 119 related : '', 120 lang : 'en' 121 }, 122 digg : { //http://about.digg.com/downloads/button/smart 123 url : '', //if you need to personalize url button 124 urlCount: false, //if you want to use personnalize button url on global counter 125 type : 'DiggCompact' 126 }, 127 delicious : { 128 url : '', //if you need to personalize url button 129 urlCount: false, //if you want to use personnalize button url on global counter 130 size : 'medium' //medium or tall 131 }, 132 stumbleupon: { //http://www.stumbleupon.com/badges/ 133 url : '', //if you need to personalize url button 134 urlCount: false, //if you want to use personnalize button url on global counter 135 layout : '1' 136 }, 137 linkedin : { //http://developer.linkedin.com/plugins/share-button 138 url : '', //if you need to personalize url button 139 urlCount: false, //if you want to use personnalize button url on global counter 140 counter : '' 141 }, 142 pinterest : { //http://pinterest.com/about/goodies/ 143 url : '', //if you need to personalize url button 144 media : '', 145 description: '', 146 layout : 'horizontal' 147 }, 148 reddit : { 149 url : '', 150 urlCount: false, 151 layout : '1' 152 }, 153 email : { 154 url : '', 155 urlCount: false, 156 layout : '1' 157 }, 158 sms : { 159 url : '', 160 urlCount: false, 161 layout : '1' 162 }, 163 whatsapp : { 164 url : '', 165 urlCount: false, 166 layout : '1' 167 }, 168 tumblr : { 169 url : '', 170 urlCount: false, 171 layout : '1' 172 } 173 } 174 }, 175 /* Json URL to get count number 176 ================================================== */ 177 urlJson = { 178 googlePlus: "", 179 180 //new FQL method by Sire 181 facebook : "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?", 182 //old method facebook: "http://graph.facebook.com/?id={url}&callback=?", 183 //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json" 184 185 twitter : "http://cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?", 186 digg : "http://services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?", 187 delicious : 'http://feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?', 188 //stumbleupon: "http://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}&format=jsonp&callback=?", 189 stumbleupon: "", 190 linkedin : "http://www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", 191 pinterest : "http://api.pinterest.com/v1/urls/count.json?url={url}&callback=?", 192 reddit : "http://buttons.reddit.com/button_info.json?url={url}" 193 }, 194 /* Load share buttons asynchronously 195 ================================================== */ 196 loadButton = { 197 googlePlus : function (self) { 198 var sett = self.options.buttons.googlePlus; 199 //$(self.element).find('.buttons').append('<div class="button googleplus"><g:plusone size="'+self.options.buttons.googlePlus.size+'" href="'+self.options.url+'"></g:plusone></div>'); 200 $(self.element).find('.buttons').append('<div class="button googleplus"><div class="g-plusone" data-size="' + sett.size + '" data-href="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-annotation="' + sett.annotation + '"></div></div>'); 201 window.___gcfg = { 202 lang: self.options.buttons.googlePlus.lang 203 }; 204 var loading = 0; 205 if (typeof gapi === 'undefined' && loading == 0) { 206 loading = 1; 207 (function () { 208 var po = document.createElement('script'); 209 po.type = 'text/javascript'; 210 po.async = true; 211 po.src = '//apis.google.com/js/plusone.js'; 212 var s = document.getElementsByTagName('script')[0]; 213 s.parentNode.insertBefore(po, s); 214 })(); 215 } 216 else { 217 gapi.plusone.go(); 218 } 219 }, 220 facebook : function (self) { 221 var sett = self.options.buttons.facebook; 222 $(self.element).find('.buttons').append('<div class="button facebook"><div id="fb-root"></div><div class="fb-like" data-href="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-send="' + sett.send + '" data-layout="' + sett.layout + '" data-width="' + sett.width + '" data-show-faces="' + sett.faces + '" data-action="' + sett.action + '" data-colorscheme="' + sett.colorscheme + '" data-font="' + sett.font + '" data-via="' + sett.via + '"></div></div>'); 223 var loading = 0; 224 if (typeof FB === 'undefined' && loading == 0) { 225 loading = 1; 226 (function (d, s, id) { 227 var js, fjs = d.getElementsByTagName(s)[0]; 228 if (d.getElementById(id)) { 229 return; 230 } 231 js = d.createElement(s); 232 js.id = id; 233 js.src = '//connect.facebook.net/' + sett.lang + '/all.js#xfbml=1'; 234 fjs.parentNode.insertBefore(js, fjs); 235 }(document, 'script', 'facebook-jssdk')); 236 } 237 else { 238 FB.XFBML.parse(); 239 } 240 }, 241 twitter : function (self) { 242 var sett = self.options.buttons.twitter; 243 $(self.element).find('.buttons').append('<div class="button twitter"><a href="https://twitter.com/share" class="twitter-share-button" data-url="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-count="' + sett.count + '" data-text="' + self.options.text + '" data-via="' + sett.via + '" data-hashtags="' + sett.hashtags + '" data-related="' + sett.related + '" data-lang="' + sett.lang + '">Tweet</a></div>'); 244 var loading = 0; 245 if (typeof twttr === 'undefined' && loading == 0) { 246 loading = 1; 247 (function () { 248 var twitterScriptTag = document.createElement('script'); 249 twitterScriptTag.type = 'text/javascript'; 250 twitterScriptTag.async = true; 251 twitterScriptTag.src = '//platform.twitter.com/widgets.js'; 252 var s = document.getElementsByTagName('script')[0]; 253 s.parentNode.insertBefore(twitterScriptTag, s); 254 })(); 255 } 256 else { 257 $.ajax({url: '//platform.twitter.com/widgets.js', dataType: '
257script', cache: true}); //http://stackoverflow.com/q/6536108 258 } 259 }, 260 digg : function (self) { 261 var sett = self.options.buttons.digg; 262 $(self.element).find('.buttons').append('<div class="button digg"><a class="DiggThisButton ' + sett.type + '" rel="nofollow external" href="http://digg.com/submit?url=' + encodeURIComponent((sett.url !== '' ? sett.url : self.options.url)) + '"></a></div>'); 263 var loading = 0; 264 if (typeof __DBW === 'undefined' && loading == 0) { 265 loading = 1; 266 (function () { 267 var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0]; 268 s.type = 'text/javascript'; 269 s.async = true; 270 s.src = '//widgets.digg.com/buttons.js'; 271 s1.parentNode.insertBefore(s, s1); 272 })(); 273 } 274 }, 275 delicious : function (self) { 276 if (self.options.buttons.delicious.size == 'tall') {//tall 277 var css = 'width:50px;', 278 cssCount = 'height:35px;width:50px;font-size:15px;line-height:35px;', 279 cssShare = 'height:18px;line-height:18px;margin-top:3px;'; 280 } 281 else {//medium 282 var css = 'width:93px;', 283 cssCount = 'float:right;padding:0 3px;height:20px;width:26px;line-height:20px;', 284 cssShare = 'float:left;height:20px;line-height:20px;'; 285 } 286 var count = self.shorterTotal(self.options.count.delicious); 287 if (typeof count === "undefined") { 288 count = 0; 289 } 290 $(self.element).find('.buttons').append( 291 '<div class="button delicious">
291<div style="' + css + 'font:12px Arial,Helvetica,sans-serif;cursor:pointer;color:#666666;display:inline-block;float:none;height:20px;line-height:normal;margin:0;padding:0;text-indent:0;vertical-align:baseline;">' + 292 '<div style="' + cssCount + 'background-color:#fff;margin-bottom:5px;overflow:hidden;text-align:center;border:1px solid #ccc;border-radius:3px;">' + count + '</div>' + 293 '<div style="' + cssShare + 'display:block;padding:0;text-align:center;text-decoration:none;width:50px;background-color:#7EACEE;border:1px solid #40679C;border-radius:3px;color:#fff;">' + 294 '<img src="http://www.delicious.com/static/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> Add</div></div></div>'); 295 296 $(self.element).find('.delicious').on('click', function () { 297 self.openPopup('delicious'); 298 }); 299 }, 300 stumbleupon: function (self) { 301 var sett = self.options.buttons.stumbleupon; 302 $(self.element).find('.buttons').append('<div class="button stumbleupon"><su:badge layout="' + sett.layout + '" location="' + (sett.url !== '' ? sett.url : self.options.url) + '"></su:badge></div>'); 303 var loading = 0; 304 if (typeof STMBLPN === 'undefined' && loading == 0) { 305 loading = 1; 306 (function () { 307 var li = document.createElement('script'); 308 li.type = 'text/javascript'; 309 li.async = true; 310 li.src = '//platform.stumbleupon.com/1/widgets.js'; 311 var s = document.getElementsByTagName('script')[0]; 312 s.parentNode.insertBefore(li, s); 313 })(); 314 s = window.setTimeout(function () { 315 if (typeof STMBLPN !== 'undefined') { 316 STMBLPN.processWidgets(); 317 clearInterval(s); 318 } 319 }, 500); 320 } 321 else { 322 STMBLPN.processWidgets(); 323 } 324 }, 325 linkedin : function (self) { 326 var sett = self.options.buttons.linkedin; 327 $(self.element).find('.buttons').append('<div class="button linkedin"><script type="in/share" data-url="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-counter="' + sett.counter + '"></script></div>'); 328 var loading = 0; 329 if (typeof window.IN === 'undefined' && loading == 0) { 330 loading = 1; 331 (function () { 332 var li = document.createElement('script'); 333 li.type = 'text/javascript'; 334 li.async = true; 335 li.src = '//platform.linkedin.com/in.js'; 336 var s = document.getElementsByTagName('script')[0]; 337 s.parentNode.insertBefore(li, s); 338 })(); 339 } 340 else { 341 window.IN.init(); 342 } 343 }, 344 pinterest : function (self) { 345 var sett = self.options.buttons.pinterest; 346 $(self.element).find('.buttons').append('<div class="button pinterest"><a href="http://pinterest.com/pin/create/button/?url=' + (sett.url !== '' ? sett.url : self.options.url) + '&media=' + sett.media + '&description=' + sett.description + '" class="pin-it-button" count-layout="' + sett.layout + '">Pin It</a></div>'); 347 348 (function () { 349 var li = document.createElement('script'); 350 li.type = 'text/javascript'; 351 li.async = true; 352 li.src = '//assets.pinterest.com/js/pinit.js'; 353 var s = document.getElementsByTagName('script')[0]; 354 s.parentNode.insertBefore(li, s); 355 })(); 356 }, 357 reddit : function (self) { 358 }, 359 email : function (self) { 360 }, 361 sms : function (self) { 362 }, 363 whatsapp : function (self) { 364 }, 365 tumblr : function (self) { 366 } 367 }, 368 /* Tracking for Google Analytics 369 ================================================== */ 370 tracking = { 371 googlePlus : function () { 372 }, 373 facebook : function () { 374 //console.log('facebook'); 375 fb = window.setInterval(function () { 376 if (typeof FB !== 'undefined') { 377 FB.Event.subscribe('edge.create', function (targetUrl) { 378 sharrre_track('facebook', 'like', targetUrl); 379 }); 380 FB.Event.subscribe('edge.remove', function (targetUrl) { 381 sharrre_track('facebook', 'unlike', targetUrl); 382 }); 383 FB.Event.subscribe('message.send', function (targetUrl) { 384 sharrre_track('facebook', 'send', targetUrl); 385 }); 386 clearInterval(fb); 387 } 388 }, 1000); 389 }, 390 twitter : function () { 391 tw = window.setInterval(function () { 392 if (typeof twttr !== 'undefined') { 393 twttr.events.bind('tweet', function (event) { 394 if (event) { 395 sharrre_track('twitter', 'tweet'); 396 } 397 }); 398 clearInterval(tw); 399 } 400 }, 1000); 401 }, 402 digg : function () { 403 //if somenone find a solution, mail me ! 404 /*$(this.element).find('.digg').on('click', function(){
405 _gaq.push(['_trackSocial', 'digg', 'add']); 406 });*/ 407 }, 408 delicious : function () { 409 }, 410 stumbleupon: function () { 411 }, 412 linkedin : function () { 413 function LinkedInShare() { 414 sharrre_track('linkedin', 'share'); 415 } 416 }, 417 pinterest : function () { 418 //if somenone find a solution, mail me ! 419 }, 420 reddit : function () { 421 }, 422 email : function () { 423 }, 424 sms : function () { 425 }, 426 whatsapp : function () { 427 }, 428 tumblr : function (self) { 429 } 430 }, 431 /* Popup for each social network 432 ================================================== */ 433 popup = { 434 googlePlus : function (opt) { 435 var share_url = (opt.buttons.googlePlus.url !== '' ? opt.buttons.googlePlus.url : opt.url); 436 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 437 share_url = addURLParam(share_url, "utm_medium", "button"); 438 window.open("https://plus.google.com/share?hl=" + opt.buttons.googlePlus.lang + "&url=" + encodeURIComponent(share_url), "", "toolbar=0, status=0, width=515, height=475"); 439 }, 440 facebook : function (opt) { 441 var share_url = (opt.buttons.facebook.url !== '' ? opt.buttons.facebook.url : opt.url) 442 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 443 share_url = addURLParam(share_url, "utm_medium", "button"); 444 window.open("http://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(share_url), "", "toolbar=0, status=0, width=600, height=500"); 445 }, 446 twitter : function (opt) { 447 var share_url = (opt.buttons.twitter.url !== '' ? opt.buttons.twitter.url : opt.url) 448 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 449 share_url = addURLParam(share_url, "utm_medium", "button"); 450 451 window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(opt.text) + "&url=" + encodeURIComponent(share_url) + (opt.buttons.twitter.via !== '' ? '&via=' + opt.buttons.twitter.via : ''), "", "toolbar=0, status=0, width=650, height=360"); 452 }, 453 digg : function (opt) { 454 var share_url = (opt.buttons.digg.url !== '' ? opt.buttons.digg.url : opt.url); 455 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 456 share_url = addURLParam(share_url, "utm_medium", "button"); 457 window.open("http://digg.com/tools/diggthis/submit?url=" + encodeURIComponent(share_url) + "&title=" + opt.text + "&related=true&style=true", "", "toolbar=0, status=0, width=650, height=360"); 458 }, 459 delicious : function (opt) { 460 var share_url = (opt.buttons.delicious.url !== '' ? opt.buttons.delicious.url : opt.url); 461 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 462 share_url = addURLParam(share_url, "utm_medium", "button"); 463 window.open('http://www.delicious.com/save?v=5&noui&jump=close&url=' + encodeURIComponent(share_url) + '&title=' + opt.text, 'delicious', 'toolbar=no,width=550,height=550'); 464 }, 465 stumbleupon: function (opt) { 466 var share_url = (opt.buttons.stumbleupon.url !== '' ? opt.buttons.stumbleupon.url : opt.url); 467 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 468 share_url = addURLParam(share_url, "utm_medium", "button"); 469 window.open('http://www.stumbleupon.com/badge/?url=' + encodeURIComponent(share_url), 'stumbleupon', 'toolbar=no,width=550,height=550'); 470 }, 471 linkedin : function (opt) { 472 var share_url = (opt.buttons.linkedin.url !== '' ? opt.buttons.linkedin.url : opt.url); 473 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 474 share_url = addURLParam(share_url, "utm_medium", "button"); 475 window.open('https://www.linkedin.com/cws/share?url=' + encodeURIComponent(share_url) + '&token=&isFramed=true', 'linkedin', 'toolbar=no,width=550,height=550'); 476 }, 477 pinterest : function (opt) { 478 var share_url = (opt.buttons.pinterest.url !== '' ? opt.buttons.pinterest.url : opt.url); 479 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 480 share_url = addURLParam(share_url, "utm_medium", "button"); 481 window.open('http://pinterest.com/pin/create/button/?url=' + encodeURIComponent(share_url) + '&media=' + encodeURIComponent(opt.media) + '&description=' + opt.text, 'pinterest', 'toolbar=no,width=700,height=300'); 482 }, 483 reddit : function (opt) { 484 var share_url = opt.url; 485 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 486 share_url = addURLParam(share_url, "utm_medium", "button"); 487 window.open('http://www.reddit.com/submit?url=' + encodeURIComponent(share_url) + '&title=' + encodeURIComponent(document.title), 'reddit', 'toolbar=no,width=850,height=615'); 488 }, 489 email : function (opt) { 490 var share_url = opt.url; 491 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 492 share_url = addURLParam(share_url, "utm_medium", "button"); 493 window.location.href = "mailto:?subject=" + encodeURIComponent(opt.text) + "&body=Article: " + encodeURIComponent(share_url); 494 }, 495 sms : function (opt) { 496 var share_url = opt.url; 497 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 498 share_url = addURLParam(share_url, "utm_medium", "button"); 499 var sms = "sms:;body="; 500 if (/Android/i.test(navigator.userAgent)) { 501 sms = 'sms:?body=Check out this article: '; 502 } else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { 503 sms = 'sms:&body=Check out this article: '; 504 } 505 window.location.href = sms + encodeURIComponent(share_url); 506 }, 507 whatsapp : function (opt) { 508 var share_url = opt.url; 509 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 510 share_url = addURLParam(share_url, "utm_medium", "button"); 511 window.location.href = 'whatsapp://send?text=' + encodeURIComponent(share_url); 512 }, 513 tumblr : function (opt) { 514 var share_url = opt.url; 515 share_url = addURLParam(share_url, "utm_source", opt.utmSource); 516 share_url = addURLParam(share_url, "utm_medium", "button"); 517 518 window.open('https://www.tumblr.com/widgets/share/tool?canonicalUrl=' + encodeURIComponent(share_url) + '&title=' + encodeURIComponent(document.title), 'tumblr', 'toolbar=no,width=540,height=682'); 519 } 520 }; 521 522 /* Plugin constructor 523 ================================================== */ 524 function Plugin(element, options) { 525 this.element = element; 526 527 this.options = $.extend(true, {}, defaults, options); 528 this.options.share = options.share; //simple solution to allow order of buttons 529 530 this._defaults = defaults; 531 this._name = pluginName; 532 533 this.init(); 534 }; 535 536 /* Initialization method 537 ================================================== */ 538 Plugin.prototype.init = function () { 539 var self = this; 540 if (this.options.urlCurl !== '') { 541 urlJson.googlePlus = this.options.urlCurl + '?url={url}&type=googlePlus'; // PHP script for GooglePlus... 542 urlJson.stumbleupon = this.options.urlCurl + '?url={url}&type=stumbleupon'; // PHP script for Stumbleupon... 543 } 544 $(this.element).addClass(this.options.className);
544 //add class 545 546 //HTML5 Custom data 547 548 $.each($(this.element).data(), function (k, v) { 549 var dot = k.indexOf('.'); 550 if(dot > -1) { 551 var key1 = k.slice(0, dot), 552 key2 = k.slice(dot+1); 553 k = key1; 554 self.options[key1] = self.options[key1] || {}; 555 self.options[key1][key2] = v; 556 } 557 else { 558 self.options[k] = v; 559 } 560 }); 561 562 //how many social website have been selected 563 $.each(this.options.share, function (name, val) { 564 if (val === true) { 565 self.options.shareTotal++; 566 } 567 }); 568 569 if (self.options.enableCounter === true) { //if for some reason you don't need counter 570 //get count of social share that have been selected 571 $.each(this.options.share, function (name, val) { 572 if (val === true) { 573 //self.getSocialJson(name); 574 try { 575 self.getSocialJson(name); 576 } catch (e) { 577 } 578 } 579 }); 580 } 581 else if (self.options.template !== '') { //for personalized button (with template) 582 self.renderer(); 583 self.rendererPerso(); 584 } 585 else { // if you want to use official button like example 3 or 5 586 this.loadButtons(); 587 } 588 589 //add hover event 590 $(this.element).hover(function () { 591 //load social button if enable and 1 time 592 if ($(this).find('.buttons').length === 0 && self.options.enableHover === true) { 593 self.loadButtons(); 594 } 595 self.options.hover(self, self.options); 596 }, function () { 597 self.options.hide(self, self.options); 598 }); 599 600 //click event 601 // SM MOD, pass event to click event 602 $(this.element).click(function (e) { 603 self.options.click(self, self.options, e); 604 return false; 605 }); 606 }; 607 608 /* loadButtons methode 609 ================================================== */ 610 Plugin.prototype.loadButtons = function () { 611 var self = this; 612 $(this.element).append('<div class="buttons"></div>'); 613 $.each(self.options.share, function (name, val) { 614 if (val == true) { 615 loadButton[name](self); 616 if (self.options.enableTracking === true) { //add tracking 617 tracking[name](); 618 } 619 } 620 }); 621 }; 622 623 /* getSocialJson methode 624 ================================================== */ 625 Plugin.prototype.getSocialJson = function (name) { 626 var self = this, 627 count = 0, 628 629 url = urlJson[name].replace('{url}', encodeURIComponent(this.options.url)); 630 631 if (this.options.buttons[name].urlCount === true && this.options.buttons[name].url !== '') { 632 url = urlJson[name].replace('{url}', this.options.buttons[name].url); 633 } 634 //console.log('name : ' + name + ' - url : '+url); //debug 635 if (url != '' && self.options.urlCurl !== '') { //urlCurl = '' if you don't want to used PHP script but used social button 636 $.getJSON(url, function (json) { 637 if (typeof json.count !== "undefined") { //GooglePlus, Stumbleupon, Twitter, Pinterest and Digg 638 var temp = json.count + ''; 639 temp = temp.replace('\u00c2\u00a0', ''); //remove google plus special chars 640 count += parseInt(temp, 10); 641 } 642 //get the FB total count (shares, likes and more) 643 else if (json.data && json.data.length > 0 && typeof json.data[0].total_count !== "undefined") { //Facebook total count 644 count += parseInt(json.data[0].total_count, 10); 645 } 646 else if (typeof json[0] !== "undefined" && json[0].total_posts) { //Delicious 647 count += parseInt(json[0].total_posts, 10); 648 } 649 else if ( 650 typeof json.data !== "undefined" 651 && typeof json.data.children !== "undefined" 652 && typeof json.data.children[0] !== "undefined") { // Reddit 653 count += json.data.children[0].data.score; 654 } 655 self.options.count[name] = count; 656 self.options.total += count; 657 self.renderer(); 658 self.rendererPerso(); 659 }) 660 .error(function () { 661 self.options.count[name] = 0; 662 self.rendererPerso(); 663 }); 664 } 665 else { 666 self.renderer(); 667 self.options.count[name] = 0; 668 self.rendererPerso(); 669 } 670 }; 671 672 /* launch render methode 673 ================================================== */ 674 Plugin.prototype.rendererPerso = function () { 675 //check if this is the last social website to launch render 676 var shareCount = 0; 677 for (e in this.options.count) { 678 shareCount++; 679 } 680 if (shareCount === this.options.shareTotal) { 681 this.options.render(this, this.options); 682 } 683 }; 684 685 /* render methode 686 ================================================== */ 687 Plugin.prototype.renderer = function () { 688 var total = this.options.total, 689 template = this.options.template; 690 if (this.options.shorterTotal === true) { //format number like 1.2k or 5M 691 total = this.shorterTotal(total); 692 } 693 694 // Check if total is 0 and add a class to the parent incase it should be styled differently 695 if (this.options.total == 0 ) { 696 $(this.element).addClass('not-shared'); 697 } 698 699 if (template !== '') { //if there is a template 700 template = template.replace('{total}', total); 701 template = template.replace('{title}', this.options.title); 702 $(this.element).html(template); 703 } 704 else { //template by defaults 705 $(this.element).html( 706 '<div class="box"><a class="count" href="#">
706' + total + '</a>' + 707 (this.options.title !== '' ? '<a class="share" href="#">' + this.options.title + '</a>' : '') + 708 '</div>' 709 ); 710 } 711 }; 712 713 /* format total numbers like 1.2k or 5M 714 ================================================== */ 715 Plugin.prototype.shorterTotal = function (num) { 716 if (num >= 1e6) { 717 num = (num / 1e6).toFixed(2) + "M" 718 } else if (num >= 1e3) { 719 num = (num / 1e3).toFixed(1) + "k" 720 } 721 return num; 722 }; 723 724 /* Methode for open popup 725 ================================================== */ 726 Plugin.prototype.openPopup = function (site) { 727 popup[site](this.options); //open 728 if (this.options.enableTracking === true) { //tracking! 729 var tracking = { 730 googlePlus : {site: 'Google', action: '+1'}, 731 facebook : {site: 'facebook', action: 'share'}, 732 twitter : {site: 'twitter', action: 'tweet'}, 733 digg : {site: 'digg', action: 'add'}, 734 delicious : {site: 'delicious', action: 'add'}, 735 stumbleupon: {site: 'stumbleupon', action: 'add'}, 736 linkedin : {site: 'linkedin', action: 'share'}, 737 pinterest : {site: 'pinterest', action: 'pin'}, 738 reddit : {site: 'reddit', action: 'add'}, 739 email : {site: 'email', action: 'send'}, 740 sms : {site: 'sms', action: 'text'}, 741 whatsapp : {site: 'whatsapp', action: 'send'}, 742 tumblr : {site: 'tumblr', action: 'send'} 743 }; 744 sharrre_track(tracking[site].site, tracking[site].action, location.href); 745 } 746 }; 747 748 /* Methode for add +1 to a counter 749 ================================================== */ 750 Plugin.prototype.simulateClick = function () { 751 var html = $(this.element).html(); 752 $(this.element).html(html.replace(this.options.total, this.options.total + 1)); 753 }; 754 755 /* Methode for add +1 to a counter 756 ================================================== */ 757 Plugin.prototype.update = function (url, text) { 758 if (url !== '') { 759 this.options.url = url; 760 } 761 if (text !== '') { 762 this.options.text = text; 763 } 764 }; 765 766 /* A really lightweight plugin wrapper around the constructor, preventing against multiple instantiations 767 ================================================== */ 768 $.fn[pluginName] = function (options) { 769 var args = arguments; 770 if (options === undefined || typeof options === 'object') { 771 return this.each(function () { 772 if (!$.data(this, 'plugin_' + pluginName)) { 773 $.data(this, 'plugin_' + pluginName, new Plugin(this, options)); 774 } 775 }); 776 } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { 777 return this.each(function () { 778 var instance = $.data(this, 'plugin_' + pluginName); 779 if (instance instanceof Plugin && typeof instance[options] === 'function') { 780 instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 781 } 782 }); 783 } 784 }; 785})(jQuery, window, document);
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.