1/* 2 * Sharrre.com - Make your sharing widget! 3 * Version: beta 1.3.3 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;(function ($, window, document, isUndefined) { 9 10 /* Defaults 11 ================================================== */ 12 var pluginName = 'sharrre', 13 defaults = { 14 className: 'sharrre', 15 share: { 16 googlePlus: false, 17 facebook: false, 18 twitter: false, 19 digg: false, 20 delicious: false, 21 stumbleupon: false, 22 linkedin: false, 23 pinterest: false 24 }, 25 shareTotal: 0, 26 template: '', 27 title: '', 28 url: document.location.href, 29 text: document.title, 30 urlCurl: 'sharrre.php', //PHP script for google plus... 31 count: {}, //counter by social network 32 total: 0, //total of sharing 33 shorterTotal: true, //show total by k or M when number is to big 34 enableCounter: true, //disable if you just want use buttons 35 enableTracking: false, //tracking with google analitycs 36 37 enableHover: true, //disable if you want to personalize hover event with callback 38 hover: false, // hover.call() personalize hover event with this callback function 39 hide: false, // hide.call() personalize hide event with this callback function 40 41 click: false, // click.call() personalize click event with this callback function 42 render: function() {}, //personalize render event with this callback function 43 44 buttons: { //settings for buttons 45 googlePlus : { //http://www.google.com/webmasters/+1/button/ 46 url: '', //if you need to personnalize button url 47 urlCount: false, //if you want to use personnalize button url on global counter 48 size: 'medium', 49 lang: 'en-US', 50 annotation: '', 51 onstartinteraction: '', 52 onendinteraction: '' 53 }, 54 facebook: { //http://developers.facebook.com/docs/reference/plugins/like/ 55 url: '', //if you need to personalize url button 56 urlCount: false, //if you want to use personnalize button url on global counter 57 action: 'like', 58 layout: 'button_count', 59 width: '', 60 send: 'false', 61 faces: 'false', 62 colorscheme: '', 63 font: '', 64 lang: 'en_US' 65 }, 66 twitter: { //http://twitter.com/about/resources/tweetbutton 67 url: '', //if you need to personalize url button 68 urlCount: false, //if you want to use personnalize button url on global counter 69 count: 'horizontal', 70 hashtags: '', 71 via: '', 72 related: '', 73 lang: 'en' 74 }, 75 digg: { //http://about.digg.com/downloads/button/smart 76 url: '', //if you need to personalize url button 77 urlCount: false, //if you want to use personnalize button url on global counter 78 type: 'DiggCompact' 79 }, 80 delicious: { 81 url: '', //if you need to personalize url button 82 urlCount: false, //if you want to use personnalize button url on global counter 83 size: 'medium' //medium or tall 84 }, 85 stumbleupon: { //http://www.stumbleupon.com/badges/ 86 url: '', //if you need to personalize url button 87 urlCount: false, //if you want to use personnalize button url on global counter 88 layout: '1' 89 }, 90 linkedin: { //http://developer.linkedin.com/plugins/share-button 91 url: '', //if you need to personalize url button 92 urlCount: false, //if you want to use personnalize button url on global counter 93 counter: '' 94 }, 95 pinterest: { //http://pinterest.com/about/goodies/ 96 url: '', //if you need to personalize url button 97 media: '', 98 description: '', 99 layout: 'horizontal' 100 } 101 } 102 }, 103 /* Json URL to get count number 104 ================================================== */ 105 urlJson = { 106 googlePlus: "", 107 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=?", 108 //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json" 109 twitter: "http://cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?", 110 digg: "http://services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?", 111 delicious: 'http://feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?', 112 //stumbleupon: "http://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}&format=jsonp&callback=?", 113 stumbleupon: "", 114 linkedin: "http://www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", 115 pinterest: "" 116 },
117 /* Load share buttons asynchronously 118 ================================================== */ 119 loadButton = { 120 googlePlus: function(self) { 121 122 var settings = self.options.buttons.googlePlus, 123 tpl = '<div class="button googleplus">' + 124 '<div class="g-plusone" data-size="%size" data-href="%href" %annotation data-onstartinteraction="googlePlusInteractionStart" data-onendinteraction="googlePlusInteractionEnd" />' + 125 '</div>', 126 loading = 0; 127 128 tpl = tpl.replace('%size', settings.size); 129 tpl = tpl.replace('%href', settings.url != '' ? settings.url : self.options.url); 130 131 if (settings.annotation) { 132 tpl = tpl.replace('%annotation', 'data-annotation="' + settings.annotation + '"'); 133 } 134 135 $(self.element).find('.buttons').append($(tpl)); 136 137 window.___gcfg = { 138 lang: self.options.buttons.googlePlus.lang 139 }; 140 141 if ((typeof gapi === 'undefined') && !loading) { 142 143 loading = 1; 144 (function() { 145 var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 146 po.src = '//apis.google.com/js/plusone.js'; 147 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 148 })(); 149 150 } else { 151 gapi.plusone.go(); 152 } 153 154 }, 155 facebook : function(self){ 156 var sett = self.options.buttons.facebook; 157 //$(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>'); 158 $(self.element).find('.buttons').append('<div class="button facebook"><iframe src="//www.facebook.com/plugins/like.php?href='+(sett.url !== '' ? escape(sett.url) : escape(self.options.url))+'&send=false&layout=button_count&width=75&show_faces=true&font&colorscheme=light&action=like&height=21&appId=270151016331206" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:75px; height:21px;" allowTransparency="true"></iframe></div>'); 159 var loading = 0; 160 if(typeof FB === 'undefined' && loading == 0){ 161 loading = 1; 162 (function(d, s, id) { 163 var js, fjs = d.getElementsByTagName(s)[0]; 164 if (d.getElementById(id)) {return;} 165 js = d.createElement(s); js.id = id; 166 js.src = '//connect.facebook.net/'+sett.lang+'/all.js#xfbml=1'; 167 fjs.parentNode.insertBefore(js, fjs); 168 }(document, 'script', 'facebook-jssdk')); 169 } 170 else{ 171 FB.XFBML.parse(); 172 } 173 }, 174 twitter : function(self){ 175 var sett = self.options.buttons.twitter; 176 $(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>'); 177 var loading = 0; 178 if(typeof twttr === 'undefined' && loading == 0){ 179 loading = 1; 180 (function() { 181 var twitterScriptTag = document.createElement('script'); 182 twitterScriptTag.type = 'text/javascript'; 183 twitterScriptTag.async = true; 184 twitterScriptTag.src = '//platform.twitter.com/widgets.js'; 185 var s = document.getElementsByTagName('script')[0]; 186 s.parentNode.insertBefore(twitterScriptTag, s); 187 })(); 188 } 189 else{ 190 $.ajax({ url: '//platform.twitter.com/widgets.js', dataType: 'script', cache:true}); //http://stackoverflow.com/q/6536108 191 } 192 }, 193 digg : function(self){ 194 var sett = self.options.buttons.digg; 195 $(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>'); 196 var loading = 0; 197 if(typeof __DBW === 'undefined' && loading == 0){ 198 loading = 1; 199 (function() { 200 var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0]; 201 s.type = 'text/javascript'; 202 s.async = true; 203 s.src = '//widgets.digg.com/buttons.js'; 204 s1.parentNode.insertBefore(s, s1); 205 })(); 206 } 207 }, 208 delicious : function(self){ 209 if(self.options.buttons.delicious.size == 'tall'){//tall 210 var css = 'width:50px;', 211 cssCount = 'height:35px;width:50px;font-size:15px;line-height:35px;', 212 cssShare = 'height:18px;line-height:18px;margin-top:3px;'; 213 } 214 else{//medium 215 var css = 'width:93px;', 216 cssCount = 'float:right;padding:0 3px;
216height:20px;width:26px;line-height:20px;', 217 cssShare = 'float:left;height:20px;line-height:20px;'; 218 } 219 var count = self.shorterTotal(self.options.count.delicious); 220 if(typeof count === "undefined"){ 221 count = 0; 222 } 223 $(self.element).find('.buttons').append( 224 '<div class="button delicious"><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;">'+ 225 '<div style="'+cssCount+'background-color:#fff;margin-bottom:5px;overflow:hidden;text-align:center;border:1px solid #ccc;border-radius:3px;">'+count+'</div>'+ 226 '<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;">'+ 227 '<img src="http://www.delicious.com/static/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> Add</div></div></div>'); 228 229 $(self.element).find('.delicious').on('click', function(){ 230 self.openPopup('delicious'); 231 }); 232 }, 233 stumbleupon : function(self){ 234 var sett = self.options.buttons.stumbleupon; 235 $(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>'); 236 var loading = 0; 237 if(typeof STMBLPN === 'undefined' && loading == 0){ 238 loading = 1; 239 (function() { 240 var li = document.createElement('script');li.type = 'text/javascript';li.async = true; 241 li.src = '//platform.stumbleupon.com/1/widgets.js'; 242 var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); 243 })(); 244 s = window.setTimeout(function(){ 245 if(typeof STMBLPN !== 'undefined'){ 246 STMBLPN.processWidgets(); 247 clearInterval(s); 248 } 249 },500); 250 } 251 else{ 252 STMBLPN.processWidgets(); 253 } 254 }, 255 linkedin : function(self){ 256 var sett = self.options.buttons.linkedin; 257 $(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>'); 258 var loading = 0; 259 if(typeof window.IN === 'undefined' && loading == 0){ 260 loading = 1; 261 (function() { 262 var li = document.createElement('script');li.type = 'text/javascript';li.async = true; 263 li.src = '//platform.linkedin.com/in.js'; 264 var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); 265 })(); 266 } 267 else{ 268 window.IN.init(); 269 } 270 }, 271 pinterest : function(self){ 272 var sett = self.options.buttons.pinterest; 273 274 if (!sett.media) { 275 var $ogimage = $('meta[property="og:image"]'); 276 if ($ogimage.length) { 277 sett.media = $ogimage.attr('content'); 278 } 279 } 280 281 $(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)+'&description='+sett.description+'" class="pin-it-button" data-pin-do="buttonBookmark" count-layout="'+sett.layout+'">Pin It</a></div>'); 282 283 (function() { 284 var li = document.createElement('script');li.type = 'text/javascript';li.async = true; 285 li.src = '//assets.pinterest.com/js/pinit.js'; 286 var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); 287 })(); 288 } 289 }, 290 /* Tracking for Google Analytics 291 ================================================== */ 292 tracking = { 293 googlePlus: function(){}, 294 facebook: function(){ 295 fb = window.setInterval(function(){ 296 if (typeof FB !== 'undefined') { 297 FB.Event.subscribe('edge.create', function(targetUrl) {
298 _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]); 299 }); 300 FB.Event.subscribe('edge.remove', function(targetUrl) { 301 _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]); 302 }); 303 FB.Event.subscribe('message.send', function(targetUrl) { 304 _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]); 305 }); 306 clearInterval(fb); 307 } 308 },1000); 309 }, 310 twitter: function(){ 311 tw = window.setInterval(function(){ 312 if (typeof twttr !== 'undefined') { 313 twttr.events.bind('tweet', function(event) { 314 if (event) { 315 _gaq.push(['_trackSocial', 'twitter', 'tweet']); 316 } 317 }); 318 clearInterval(tw); 319 } 320 },1000); 321 }, 322 digg: function(){ 323 //if somenone find a solution, mail me ! 324 /*$(this.element).find('.digg').on('click', function(){ 325 _gaq.push(['_trackSocial', 'digg', 'add']); 326 });*/ 327 }, 328 delicious: function(){}, 329 stumbleupon: function(){}, 330 linkedin: function(){ 331 function LinkedInShare() { 332 _gaq.push(['_trackSocial', 'linkedin', 'share']); 333 } 334 }, 335 pinterest: function(){ 336 //if somenone find a solution, mail me ! 337 } 338 }, 339 /* Popup for each social network 340 ================================================== */ 341 popup = { 342 googlePlus: function(opt){ 343 window.open("https://plus.google.com/share?hl="+opt.buttons.googlePlus.lang+"&url="+encodeURIComponent((opt.buttons.googlePlus.url !== '' ? opt.buttons.googlePlus.url : opt.url)), "", "toolbar=0, status=0, width=900, height=500"); 344 }, 345 facebook: function(opt){ 346 window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent((opt.buttons.facebook.url !== '' ? opt.buttons.facebook.url : opt.url))+"&t="+opt.text+"", "", "toolbar=0, status=0, width=900, height=500"); 347 }, 348 twitter: function(opt){ 349 window.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(opt.text)+"&url="+encodeURIComponent((opt.buttons.twitter.url !== '' ? opt.buttons.twitter.url : opt.url))+(opt.buttons.twitter.via !== '' ? '&via='+opt.buttons.twitter.via : ''), "", "toolbar=0, status=0, width=650, height=360"); 350 }, 351 digg: function(opt){ 352 window.open("http://digg.com/tools/diggthis/submit?url="+encodeURIComponent((opt.buttons.digg.url !== '' ? opt.buttons.digg.url : opt.url))+"&title="+opt.text+"&related=true&style=true", "", "toolbar=0, status=0, width=650, height=360"); 353 }, 354 delicious: function(opt){ 355 window.open('http://www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent((opt.buttons.delicious.url !== '' ? opt.buttons.delicious.url : opt.url))+'&title='+opt.text, 'delicious', 'toolbar=no,width=550,height=550'); 356 }, 357 stumbleupon: function(opt){ 358 window.open('http://www.stumbleupon.com/badge/?url='+encodeURIComponent((opt.buttons.delicious.url !== '' ? opt.buttons.delicious.url : opt.url)), 'stumbleupon', 'toolbar=no,width=550,height=550'); 359 }, 360 linkedin: function(opt){ 361 window.open('https://www.linkedin.com/cws/share?url='+encodeURIComponent((opt.buttons.delicious.url !== '' ? opt.buttons.delicious.url : opt.url))+'&token=&isFramed=true', 'linkedin', 'toolbar=no,width=550,height=550'); 362 }, 363 pinterest: function(opt){ 364 window.open('http://pinterest.com/pin/create/button/?url='+encodeURIComponent((opt.buttons.pinterest.url !== '' ? opt.buttons.pinterest.url : opt.url))+'&media='+encodeURIComponent(opt.buttons.pinterest.media)+'&description='+opt.buttons.pinterest.description, 'pinterest', 'toolbar=no,width=700,height=300'); 365 } 366 }; 367 368 /* Plugin constructor 369 ================================================== */ 370 function Plugin( element, options ) { 371 this.element = element; 372 373 this.options = $.extend( true, {}, defaults, options); 374 this.options.share = options.share; //simple solution to allow order of buttons 375 376 this._defaults = defaults; 377 this._name = pluginName; 378 379 this.init(); 380 }; 381 382 /* Initialization method 383 ================================================== */ 384 Plugin.prototype.init = function () { 385 386 var self = this, 387 $el = $(this.element); 388 389 this.$el = $el; 390 391 if (this.options.urlCurl !== '') { 392 urlJson.googlePlus = this.options.urlCurl + '?url={url}&type=googlePlus'; // PHP script for GooglePlus... 393 urlJson.stumbleupon = this.options.urlCurl + '?url={url}&type=stumbleupon'; // PHP script for Stumbleupon... 394 urlJson.pinterest = this.options.urlCurl + '?url={url}&type=pinterest'; // PHP script for Pinterest... 395 } 396 397 $el.addClass(this.options.className + ' state-hidden'); 398 399 $el.data('title') && (this.options.title = $el.attr('data-title'));
400 $el.data('url') && (this.options.url = $el.data('url')); 401 $el.data('text') && (this.options.text = $el.data('text')); 402 403 //how many social website have been selected 404 $.each(this.options.share, function(name, val) { 405 if (val === true) { 406 self.options.shareTotal++; 407 } 408 }); 409 410 if (self.options.enableCounter === true) { //if for some reason you don't need counter 411 $.each(this.options.share, function(name, val) { 412 if (val === true) { 413 try { 414 self.getSocialJson(name); 415 } catch (e) { 416 } 417 } 418 }); 419 } else if (self.options.template !== '') { //for personalized button (with template) 420 this.options.render(this, this.options); 421 } else { // if you want to use official button like example 3 or 5 422 this.loadButtons(); 423 } 424 425 var $buttons = $(this.element).find('.buttons'), 426 loading = false, 427 preloadButtons = function () { 428 if (!$buttons.length && !loading) { 429 loading = true; 430 self.loadButtons(); 431 $buttons = $(self.element).find('.buttons'); 432 } 433 }, 434 openSharrre = function () { 435 436 preloadButtons(); 437 438 $el.removeClass('state-hidden').addClass('state-visible'); 439 if ($buttons.is(':animated')) { 440 $buttons.stop().css('opacity', '1'); 441 } else { 442 $buttons.fadeIn(400); 443 } 444 445 }, 446 closeSharrre = function () { 447 448 $el.addClass('state-hidden').removeClass('state-visible'); 449 450 if ($buttons.is(':animated')) { 451 $el.addClass('state-hidden').removeClass('state-visible'); 452 } else { 453 $buttons.fadeOut(400); 454 } 455 456 } 457 458 $el.on('mouseover.sharrre', preloadButtons); 459 460 $el.on('click.sharrre', '.counts,.share', function (e) { 461 462 if (self.options.click) { 463 self.options.click.call(self, self.options); 464 } else { 465 $el.is('.state-hidden') ? openSharrre() : closeSharrre(); 466 } 467 468 return false; 469 470 }); 471 472 $el.on('click.sharrre', '.close', function (e) { 473 closeSharrre(); 474 return false; 475 }); 476 477 $(document).on('click.sharrre', function (e) { 478 if ( $(e.target).closest('.sharrre').length == 0 ) { // Only if we didn't click inside the sharrre popup 479 closeSharrre(); // Close the sharrre when clicking anywhere on the page 480 } 481 }); 482 483 }; 484 485 /* loadButtons methode 486 ================================================== */ 487 Plugin.prototype.loadButtons = function () { 488 var self = this, 489 buttonsTemplate = ''; 490 491 if (this.options.buttonsTemplate != isUndefined) { 492 buttonsTemplate = this.options.buttonsTemplate; 493 } 494 495 $(this.element).append('<div class="buttons">' + buttonsTemplate + '</div>'); 496 497 $.each(self.options.share, function(name, val) { 498 if (val == true) { 499 loadButton[name](self); 500 if (self.options.enableTracking === true) { //add tracking 501 tracking[name](); 502 } 503 } 504 }); 505 506 if (this.options.afterLoadButtons != isUndefined) { 507 this.options.afterLoadButtons.call(this); 508 } 509 }; 510 511 /* getSocialJson methode 512 ================================================== */ 513 Plugin.prototype.getSocialJson = function (name) { 514 var self = this, 515 count = 0, 516 url = urlJson[name].replace('{url}', encodeURIComponent(this.options.url)); 517 if(this.options.buttons[name].urlCount === true && this.options.buttons[name].url !== ''){
518 url = urlJson[name].replace('{url}', this.options.buttons[name].url); 519 } 520 if(url != '' && self.options.urlCurl !== ''){ //urlCurl = '' if you don't want to used PHP script but used social button 521 $.getJSON(url, function(json){ 522 json = json || {}; 523 if(typeof json.count !== "undefined"){ //GooglePlus, Stumbleupon, Twitter and Digg 524 var temp = json.count + ''; 525 temp = temp.replace('\u00c2\u00a0', ''); //remove google plus special chars 526 count += parseInt(temp, 10); 527 } 528 //get the FB total count (shares, likes and more) 529 else if(json.data && json.data.length > 0 && typeof json.data[0].total_count !== "undefined"){ //Facebook total count 530 count += parseInt(json.data[0].total_count, 10); 531 } 532 else if(typeof json.shares !== "undefined"){ //Facebook 533 count += parseInt(json.shares, 10); 534 } 535 else if(typeof json[0] !== "undefined"){ //Delicious 536 count += parseInt(json[0].total_posts, 10); 537 } 538 else if(typeof json[0] !== "undefined"){ //Stumbleupon 539 } 540 self.options.count[name] = count; 541 self.options.total += count; 542 self.renderer(); 543 self.rendererPerso(); 544 }) 545 .error(function() { 546 self.options.count[name] = 0; 547 self.rendererPerso(); 548 }); 549 } 550 else{ 551 self.renderer(); 552 self.options.count[name] = 0; 553 self.rendererPerso(); 554 } 555 }; 556 557 /* launch render methode 558 ================================================== */ 559 Plugin.prototype.rendererPerso = function () { 560 //check if this is the last social website to launch render 561 var shareCount = 0; 562 for (e in this.options.count) { shareCount++; } 563 if(shareCount === this.options.shareTotal){ 564 this.options.render(this, this.options); 565 } 566 }; 567 568 /* render methode 569 ================================================== */ 570 Plugin.prototype.renderer = function () { 571 572 var total = this.options.total, 573 template = this.options.template; 574 if (this.options.shorterTotal === true) { //format number like 1.2k or 5M 575 total = this.shorterTotal(total); 576 } 577 578 if (template !== '') { 579 template = template.replace('{total}', total); 580 $(this.element).html(template); 581 } else { 582 $(this.element).html('<div class="box"><a class="count" href="#">' + total + '</a>' + 583 (this.options.title !== '' ? '<a class="share" href="#">' + this.options.title + '</a>' : '') + 584 '</div>'); 585 } 586 587 588 589 }; 590 591 /* format total numbers like 1.2k or 5M 592 ================================================== */ 593 Plugin.prototype.shorterTotal = function (num) { 594 if (num >= 1e6){ 595 num = (num / 1e6).toFixed(2) + "M" 596 } else if (num >= 1e3){ 597 num = (num / 1e3).toFixed(1) + "k" 598 } 599 return num; 600 }; 601 602 /* Methode for open popup 603 ================================================== */ 604 Plugin.prototype.openPopup = function (site) { 605 popup[site](this.options); //open 606 if(this.options.enableTracking === true){ 607 var tracking = { 608 googlePlus: {site: 'Google', action: '+1'}, 609 facebook: {site: 'facebook', action: 'like'}, 610 twitter: {site: 'twitter', action: 'tweet'}, 611 digg: {site: 'digg', action: 'add'}, 612 delicious: {site: 'delicious', action: 'add'}, 613 stumbleupon: {site: 'stumbleupon', action: 'add'}, 614 linkedin: {site: 'linkedin', action: 'share'}, 615 pinterest: {site: 'pinterest', action: 'pin'} 616 }; 617 _gaq.push(['_trackSocial', tracking[site].site, tracking[site].action]); 618 } 619 }; 620 621 /* Methode for add +1 to a counter 622 ================================================== */ 623 Plugin.prototype.simulateClick = function () { 624 var html = $(this.element).html(); 625 $(this.element).html(html.replace(this.options.total, this.options.total+1)); 626 }; 627 628 /* Methode for add +1 to a counter 629 ================================================== */ 630 Plugin.prototype.update = function (url, text) { 631 if(url !== ''){
632 this.options.url = url; 633 } 634 if(text !== ''){ 635 this.options.text = text; 636 } 637 }; 638 639 /* A really lightweight plugin wrapper around the constructor, preventing against multiple instantiations 640 ================================================== */ 641 $.fn[pluginName] = function ( options ) { 642 var args = arguments; 643 if (options === isUndefined || typeof options === 'object') { 644 return this.each(function () { 645 if (!$.data(this, 'plugin_' + pluginName)) { 646 $.data(this, 'plugin_' + pluginName, new Plugin( this, options )); 647 } 648 }); 649 } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { 650 return this.each(function () { 651 var instance = $.data(this, 'plugin_' + pluginName); 652 if (instance instanceof Plugin && typeof instance[options] === 'function') { 653 instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) ); 654 } 655 }); 656 } 657 }; 658 659})(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.