vendor: 2,443 bytes, lines 1-82
1/*! jssocials - v1.4.0 - 2016-10-10 2* http://js-socials.com 3* Copyright (c) 2016 Artem Tabalin; Licensed MIT */ 4(function(window, $, undefined) { 5 6 var JSSOCIALS = "JSSocials", 7 JSSOCIALS_DATA_KEY = JSSOCIALS; 8 9 var getOrApply = function(value, context) { 10 if($.isFunction(value)) { 11 return value.apply(context, $.makeArray(arguments).slice(2)); 12 } 13 return value; 14 }; 15 16 var IMG_SRC_REGEX = /(\.(jpeg|png|gif|bmp|svg)$|^data:image\/(jpeg|png|gif|bmp|svg\+xml);base64)/i; 17 var URL_PARAMS_REGEX = /(&?[a-zA-Z0-9]+=)?\{([a-zA-Z0-9]+)\}/g; 18 19 var MEASURES = { 20 "G": 1000000000, 21 "M": 1000000, 22 "K": 1000 23 }; 24 25 var shares = {}; 26 27 function Socials(element, config) { 28 var $element = $(element); 29 30 $element.data(JSSOCIALS_DATA_KEY, this); 31 32 this._$element = $element; 33 34 this.shares = []; 35 36 this._init(config); 37 this._render(); 38 } 39 40 Socials.prototype = { 41 url: "", 42 text: "", 43 shareIn: "blank", 44 45 showLabel: function(screenWidth) { 46 return (this.showCount === false) ? 47 (screenWidth > this.smallScreenWidth) : 48 (screenWidth >= this.largeScreenWidth); 49 }, 50 51 showCount: function(screenWidth) { 52 return (screenWidth <= this.smallScreenWidth) ? "inside" : true; 53 }, 54 55 smallScreenWidth: 640, 56 largeScreenWidth: 1024, 57 58 resizeTimeout: 200, 59 60 elementClass: "jssocials", 61 sharesClass: "jssocials-shares", 62 shareClass: "jssocials-share", 63 shareButtonClass: "jssocials-share-button", 64 shareLinkClass: "jssocials-share-link", 65 shareLogoClass: "jssocials-share-logo", 66 shareLabelClass: "jssocials-share-label", 67 shareLinkCountClass: "jssocials-share-link-count", 68 shareCountBoxClass: "jssocials-share-count-box", 69 shareCountClass: "jssocials-share-count", 70 shareZeroCountClass: "jssocials-share-no-count", 71 72 _init: function(config) { 73 this._initDefaults(); 74 $.extend(this, config); 75 this._initShares(); 76 this._attachWindowResizeCallback(); 77 }, 78 79 _initDefaults: function() { 80 this.url = window.location.href; 81 this.text = $.trim($("meta[name=description]").attr("content") || $("title").text()); 82 //this.text = "Checkout " + this.text
vendor: 10,962 bytes, lines 82-444
82; 83 }, 84 85 _initShares: function() { 86 this.shares = $.map(this.shares, $.proxy(function(shareConfig) { 87 if(typeof shareConfig === "string") { 88 shareConfig = { share: shareConfig }; 89 } 90 91 var share = (shareConfig.share && shares[shareConfig.share]); 92 93 if(!share && !shareConfig.renderer) { 94 throw Error("Share '" + shareConfig.share + "' is not found"); 95 } 96 97 return $.extend({ url: this.url, text: this.text }, share, shareConfig); 98 }, this)); 99 }, 100 101 _attachWindowResizeCallback: function() { 102 $(window).on("resize", $.proxy(this._windowResizeHandler, this)); 103 }, 104 105 _detachWindowResizeCallback: function() { 106 $(window).off("resize", this._windowResizeHandler); 107 }, 108 109 _windowResizeHandler: function() { 110 if($.isFunction(this.showLabel) || $.isFunction(this.showCount)) { 111 window.clearTimeout(this._resizeTimer); 112 this._resizeTimer = setTimeout($.proxy(this.refresh, this), this.resizeTimeout); 113 } 114 }, 115 116 _render: function() { 117 this._clear(); 118 119 this._defineOptionsByScreen(); 120 121 this._$element.addClass(this.elementClass); 122 123 this._$shares = $("<div>").addClass(this.sharesClass) 124 .appendTo(this._$element); 125 126 this._renderShares(); 127 }, 128 129 _defineOptionsByScreen: function() { 130 this._screenWidth = $(window).width(); 131 this._showLabel = getOrApply(this.showLabel, this, this._screenWidth); 132 this._showCount = getOrApply(this.showCount, this, this._screenWidth); 133 }, 134 135 _renderShares: function() { 136 $.each(this.shares, $.proxy(function(_, share) { 137 this._renderShare(share); 138 }, this)); 139 }, 140 141 _renderShare: function(share) { 142 var $share; 143 144 if($.isFunction(share.renderer)) { 145 $share = $(share.renderer()); 146 } else { 147 $share = this._createShare(share); 148 } 149 150 $share.addClass(this.shareClass) 151 .addClass(share.share ? "jssocials-share-" + share.share : "") 152 .addClass(share.css) 153 .appendTo(this._$shares); 154 }, 155 156 _createShare: function(share) { 157 var $result = $("<div>"); 158 var $shareLink = this._createShareLink(share).appendTo($result); 159 160 if(this._showCount) { 161 var isInsideCount = (this._showCount === "inside"); 162 var $countContainer = isInsideCount ? $shareLink : $("<div>").addClass(this.shareCountBoxClass).appendTo($result); 163 $countContainer.addClass(isInsideCount ? this.shareLinkCountClass : this.shareCountBoxClass); 164 this._renderShareCount(share, $countContainer); 165 } 166 167 return $result; 168 }, 169 170 _createShareLink: function(share) { 171 var shareStrategy = this._getShareStrategy(share); 172 173 var $result = shareStrategy.call(share, { 174 shareUrl: this._getShareUrl(share) 175 }); 176 177 $result.addClass(this.shareLinkClass) 178 .append(this._createShareLogo(share)); 179 180 if(this._showLabel) { 181 $result.append(this._createShareLabel(share)); 182 } 183 184 $.each(this.on || {}, function(event, handler) { 185 if($.isFunction(handler)) { 186 $result.on(event, $.proxy(handler, share)); 187 } 188 }); 189 190 return $result; 191 }, 192 193 _getShareStrategy: function(share) { 194 var result = shareStrategies[share.shareIn || this.shareIn]; 195 196 if(!result) 197 throw Error("Share strategy '" + this.shareIn + "' not found"); 198 199 return result; 200 }, 201 202 _getShareUrl: function(share) { 203 var shareUrl = getOrApply(share.shareUrl, share); 204 return this._formatShareUrl(shareUrl, share); 205 }, 206 207 _createShareLogo: function(share) { 208 var logo = share.logo; 209 210 var $result = IMG_SRC_REGEX.test(logo) ? 211 $("<img>").attr("src", share.logo) : 212 $("<i>").addClass(logo); 213 214 $result.addClass(this.shareLogoClass); 215 216 return $result; 217 }, 218 219 _createShareLabel: function(share) { 220 return $("<span>").addClass(this.shareLabelClass) 221 .text(share.label); 222 }, 223 224 _renderShareCount: function(share, $container) { 225 var $count = $("<span>").addClass(this.shareCountClass); 226 227 $container.addClass(this.shareZeroCountClass) 228 .append($count); 229 230 this._loadCount(share).done($.proxy(function(count) { 231 if(count) { 232 $container.removeClass(this.shareZeroCountClass); 233 $count.text(count); 234 } 235 }, this)); 236 }, 237 238 _loadCount: function(share) { 239 var deferred = $.Deferred(); 240 var countUrl = this._getCountUrl(share); 241 242 if(!countUrl) { 243 return deferred.resolve(0).promise(); 244 } 245 246 var handleSuccess = $.proxy(function(response) { 247 deferred.resolve(this._getCountValue(response, share)); 248 }, this); 249 250 $.getJSON(countUrl).done(handleSuccess) 251 .fail(function() { 252 $.get(countUrl).done(handleSuccess) 253 .fail(function() { 254 deferred.resolve(0); 255 }); 256 }); 257 258 return deferred.promise(); 259 }, 260 261 _getCountUrl: function(share) { 262 var countUrl = getOrApply(share.countUrl, share); 263 return this._formatShareUrl(countUrl, share); 264 }, 265 266 _getCountValue: function(response, share) { 267 var count = ($.isFunction(share.getCount) ? share.getCount(response) : response) || 0; 268 return (typeof count === "string") ? count : this._formatNumber(count); 269 }, 270 271 _formatNumber: function(number) { 272 $.each(MEASURES, function(letter, value) { 273 if(number >= value) { 274 number = parseFloat((number / value).toFixed(2)) + letter; 275 return false; 276 } 277 }); 278 279 return number; 280 }, 281 282 _formatShareUrl: function(url, share) { 283 return url.replace(URL_PARAMS_REGEX, function(match, key, field) { 284 var value = share[field] || ""; 285 return value ? (key || "") + window.encodeURIComponent(value) : ""; 286 }); 287 }, 288 289 _clear: function() { 290 window.clearTimeout(this._resizeTimer); 291 this._$element.empty(); 292 }, 293 294 _passOptionToShares: function(key, value) { 295 var shares = this.shares; 296 297 $.each(["url", "text"], function(_, optionName) { 298 if(optionName !== key) 299 return; 300 301 $.each(shares, function(_, share) { 302 share[key] = value; 303 }); 304 }); 305 }, 306 307 _normalizeShare: function(share) { 308 if($.isNumeric(share)) { 309 return this.shares[share]; 310 } 311 312 if(typeof share === "string") { 313 return $.grep(this.shares, function(s) { 314 return s.share === share; 315 })[0]; 316 } 317 318 return share; 319 }, 320 321 refresh: function() { 322 this._render(); 323 }, 324 325 destroy: function() { 326 this._clear(); 327 this._detachWindowResizeCallback(); 328 329 this._$element 330 .removeClass(this.elementClass) 331 .removeData(JSSOCIALS_DATA_KEY); 332 }, 333 334 option: function(key, value) { 335 if(arguments.length === 1) { 336 return this[key]; 337 } 338 339 this[key] = value; 340 341 this._passOptionToShares(key, value); 342 343 this.refresh(); 344 }, 345 346 shareOption: function(share, key, value) { 347 share = this._normalizeShare(share); 348 349 if(arguments.length === 2) { 350 return share[key]; 351 } 352 353 share[key] = value; 354 this.refresh(); 355 } 356 }; 357 358 359 $.fn.jsSocials = function(config) { 360 var args = $.makeArray(arguments), 361 methodArgs = args.slice(1), 362 result = this; 363 364 this.each(function() { 365 var $element = $(this), 366 instance = $element.data(JSSOCIALS_DATA_KEY), 367 methodResult; 368 369 if(instance) { 370 if(typeof config === "string") { 371 methodResult = instance[config].apply(instance, methodArgs); 372 if(methodResult !== undefined && methodResult !== instance) { 373 result = methodResult; 374 return false; 375 } 376 } else { 377 instance._detachWindowResizeCallback(); 378 instance._init(config); 379 instance._render(); 380 } 381 } else { 382 new Socials($element, config); 383 } 384 }); 385 386 return result; 387 }; 388 389 var setDefaults = function(config) { 390 var component; 391 392 if($.isPlainObject(config)) { 393 component = Socials.prototype; 394 } else { 395 component = shares[config]; 396 config = arguments[1] || {}; 397 } 398 399 $.extend(component, config); 400 }; 401 402 var shareStrategies = { 403 popup: function(args) { 404 return $("<a>").attr("href", "#") 405 .on("click", function() { 406 window.open(args.shareUrl, null, "width=600, height=400, location=0, menubar=0, resizeable=0, scrollbars=0, status=0, titlebar=0, toolbar=0"); 407 return false; 408 }); 409 }, 410 411 blank: function(args) { 412 return $("<a>").attr({ target: "_blank", href: args.shareUrl }); 413 }, 414 415 self: function(args) { 416 return $("<a>").attr({ target: "_self", href: args.shareUrl }); 417 } 418 }; 419 420 window.jsSocials = { 421 Socials: Socials, 422 shares: shares, 423 shareStrategies: shareStrategies, 424 setDefaults: setDefaults 425 }; 426 427}(window, jQuery)); 428 429 430(function(window, $, jsSocials, undefined) { 431 432 $.extend(jsSocials.shares, { 433 434 email: { 435 label: "E-mail", 436 logo: "fa fa-at", 437 shareUrl: "mailto:{to}?subject={text}&body={url}", 438 countUrl: "", 439 shareIn: "self" 440 }, 441 442 twitter: { 443 label: "Tweet", 444 logo: "fa
444b fa-twitter", 445 shareUrl: "https://twitter.com/share?url={url}&text={text}&via={via}&hashtags={hashtags}", 446 countUrl: "" 447 }, 448 449 facebook: { 450 label: "Like", 451 logo: "fab fa-facebook-f", 452 //shareUrl: "https://facebook.com/sharer/sharer.php?u={url}", 453 shareUrl: "https://facebook.com/share.php?u={url}", 454 countUrl: "https://graph.facebook.com/?id={url}", 455 getCount: function(data) { 456 return data.share && data.share.share_count || 0; 457 } 458 }, 459 460 vkontakte: { 461 label: "Like", 462 logo: "fab fa-vk", 463 shareUrl: "https://vk.com/share.php?url={url}&title={title}&description={text}", 464 countUrl: "https://vk.com/share.php?act=count&index=1&url={url}", 465 getCount: function(data) { 466 return parseInt(data.slice(15, -2).split(', ')[1]); 467 } 468 }, 469 470 googleplus: { 471 label: "+1", 472 logo: "fab fa-google", 473 shareUrl: "https://plus.google.com/share?url={url}", 474 countUrl: "" 475 }, 476 477 linkedin: { 478 label: "Share", 479 logo: "fab fa-linkedin", 480 shareUrl: "https://www.linkedin.com/shareArticle?mini=true&url={url}", 481 countUrl: "https://www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", 482 getCount: function(data) { 483 return data.count; 484 } 485 }, 486 487 pinterest: { 488 label: "Pin it", 489 logo: "fab fa-pinterest", 490 shareUrl: "https://pinterest.com/pin/create/bookmarklet/?media={media}&url={url}&description={text}", 491 countUrl: "https://api.pinterest.com/v1/urls/count.json?&url={url}&callback=?", 492 getCount: function(data) { 493 return data.count; 494 } 495 }, 496 497 stumbleupon: { 498 label: "Share", 499 logo: "fab fa-stumbleupon", 500 shareUrl: "http://www.stumbleupon.com/submit?url={url}&title={title}", 501 countUrl: "https://cors-anywhere.herokuapp.com/https://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}", 502 getCount: function(data) { 503 return data.result.views; 504 } 505 }, 506 507 telegram: { 508 label: "Telegram", 509 logo: "fa fa-paper-plane", 510 shareUrl: "tg://msg?text={url} {text}", 511 countUrl: "", 512 shareIn: "self" 513 }, 514 515 whatsapp: { 516 label: "WhatsApp", 517 logo: "fab fa-whatsapp", 518 shareUrl: "whatsapp://send?text={url} {text}", 519 countUrl: "", 520 shareIn: "self" 521 }, 522 523 line: { 524 label: "LINE", 525 logo: "fa fa-comment", 526 shareUrl: "http://line.me/R/msg/text/?{text} {url}", 527 countUrl: "" 528 }, 529 530 viber: { 531 label: "Viber", 532 logo: "fa fa-volume-control-phone", 533 shareUrl: "viber://forward?text={url} {text}", 534 countUrl: "", 535 shareIn: "self" 536 }, 537 538 pocket: { 539 label: "Pocket", 540 logo: "fab fa-get-pocket", 541 shareUrl: "https://getpocket.com/save?url={url}&title={title}", 542 countUrl: "" 543 }, 544 545 messenger: { 546 label: "Share", 547 logo: "fa fa-commenting", 548 shareUrl: "fb-messenger://share?link={url}", 549 countUrl: "", 550 shareIn: "self" 551 } 552 553 }); 554 555}(window, jQuery, window.jsSocials)); 556
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.