1/*! 2 * Social Share Kit v1.0.15 (http://socialsharekit.com) 3 * Copyright 2015 Social Share Kit / Kaspars Sprogis. 4 * @Licensed under Creative Commons Attribution-NonCommercial 3.0 license: 5 * https://github.com/darklow/social-share-kit/blob/master/LICENSE 6 * --- 7 */ 8var SocialShareKit = (function () { 9 var supportsShare = /(twitter|facebook|google-plus|pinterest|tumblr|vk|linkedin|buffer|email)/, 10 sep = '*|*', wrap, _wrap; 11 12 // Wrapper to support multiple instances per page by selector 13 _wrap = function (opts) { 14 var options = opts || {}, 15 selector = options.selector || '.ssk'; 16 this.nodes = $(selector); 17 this.options = options; 18 }; 19 20 // Instance related functions 21 _wrap.prototype = { 22 share: function () { 23 var els = this.nodes, 24 options = this.options, 25 urlsToCount = {}; 26 27 var _init = function () { 28 if (!els.length) 29 return; 30 31 each(els, function (el) { 32 var network = elSupportsShare(el), uniqueKey; 33 if (!network) { 34 return; 35 } 36 37 if (el.getAttribute('data-ssk-ready')) 38 if (options.reinitialize && el._skkListener) { 39 removeEventListener(el, 'click', el._skkListener); 40 } else 41 return; 42 43 el.setAttribute('data-ssk-ready', true); 44 addEventListener(el, 'click', onClick); 45 el._skkListener = onClick 46 47 // Gather icons with share counts 48 if (el.parentNode.className.indexOf('ssk-count') !== -1) { 49 network = network[0]; 50 uniqueKey = network + sep + getShareUrl(options, network, el); 51 if (!(uniqueKey in urlsToCount)) { 52 urlsToCount[uniqueKey] = []; 53 } 54 urlsToCount[uniqueKey].push(el); 55 } 56 }); 57 58 processShareCount(); 59 }; 60 61 if (options.forceInit === true) 62 _init(); 63 else 64 ready(_init); 65 66 67 function onClick(e) { 68 var target = preventDefault(e), 69 match = elSupportsShare(target), 70 network = match[0], 71 url; 72 73 if (!match) 74 return; 75 76 url = getUrl(options, network, target); 77 if (!url) 78 return; 79 80 // To use Twitter intent events, replace URL and use Twitter native share JS 81 if (window.twttr && target.getAttribute('href').indexOf('twitter.com/intent/') !== -1) { 82 target.setAttribute('href', url); 83 return; 84 } 85 86 if (network !== 'email') { 87 var width, height; 88 if (network === 'buffer') { 89 width = 800; 90 height = 680; 91 } else { 92 width = 575; 93 height = 400; 94 } 95 var win = winOpen(url, width, height); 96 97 if (options.onOpen) { 98 options.onOpen(target, network, url, win); 99 } 100 101 if (options.onClose) { 102 var closeInt = window.setInterval(function () { 103 if (win.closed !== false) { 104 window.clearInterval(closeInt); 105 options.onClose(target, network, url, win); 106 } 107 }, 250); 108 } 109 110 } else { 111 document.location = url; 112 } 113 } 114 115 function processShareCount() { 116 var a, ref; 117 for (a in urlsToCount) { 118 ref = a.split(sep); 119 (function (els) { 120 getCount(ref[0], ref[1], options, function (cnt) { 121 for (var c in els) 122 addCount(els[c], cnt); 123 }); 124 })(urlsToCount[a]); 125 } 126 } 127 128 return this.nodes; 129 } 130 }; 131 132 wrap = function (selector) { 133 return new _wrap(selector); 134 }; 135 136 function init(opts) { 137 return wrap(opts).share(); 138 } 139 140 function ready(fn) { 141 if (document.readyState != 'loading') { 142 fn(); 143 } else if (document.addEventListener) { 144 document.addEventListener('DOMContentLoaded', fn); 145 } else { 146 document.attachEvent('onreadystatechange', function () { 147 if (document.readyState != 'loading') 148 fn(); 149 }); 150 } 151 } 152 153 function $(selector) { 154 return document.querySelectorAll(selector); 155 } 156 157 function each(elements, fn) { 158 for (var i = 0; i < elements.length; i++) 159 fn(elements[i], i); 160 } 161 162 function addEventListener(el, eventName, handler) { 163 if (el.addEventListener) { 164 el.addEventListener(eventName, handler); 165 } else { 166 el.attachEvent('on' + eventName, function () { 167 handler.call(el); 168 }); 169 } 170 } 171 172 function removeEventListener(el, eventName, handler) { 173 if (el.removeEventListener) 174 el.removeEventListener(eventName, handler); 175 else 176 el.detachEvent('on' + eventName, handler); 177 } 178 179 function elSupportsShare(el) { 180 return el.className.match(supportsShare); 181 } 182 183 184 function preventDefault(e) { 185 var evt = e || window.event; // IE8 compatibility 186 if (evt.preventDefault) { 187 evt.preventDefault(); 188 } else { 189 evt.returnValue = false;
190 evt.cancelBubble = true; 191 } 192 return evt.currentTarget || evt.srcElement; 193 } 194 195 function winOpen(url, width, height) { 196 var win, left, top, opts; 197 if (width && height) { 198 left = (document.documentElement.clientWidth / 2 - width / 2); 199 top = (document.documentElement.clientHeight - height) / 2; 200 opts = 'status=1,resizable=yes' + 201 ',width=' + width + ',height=' + height + 202 ',top=' + top + ',left=' + left; 203 win = window.open(url, '', opts); 204 } else { 205 win = window.open(url); 206 } 207 win.focus(); 208 return win; 209 } 210 211 function getUrl(options, network, el) { 212 var url, dataOpts = getDataOpts(options, network, el), 213 shareUrl = getShareUrl(options, network, el, dataOpts), 214 title = typeof dataOpts['title'] !== 'undefined' ? dataOpts['title'] : getTitle(network), 215 text = typeof dataOpts['text'] !== 'undefined' ? dataOpts['text'] : getText(network), 216 image = dataOpts['image'] ? dataOpts['image'] : getMetaContent('og:image'), 217 via = typeof dataOpts['via'] !== 'undefined' ? dataOpts['via'] : getMetaContent('twitter:site'), 218 paramsObj = { 219 shareUrl: shareUrl, 220 title: title, 221 text: text, 222 image: image, 223 via: via, 224 options: options, 225 shareUrlEncoded: function () { 226 return encodeURIComponent(this.shareUrl); 227 } 228 }; 229 switch (network) { 230 case 'facebook': 231 url = 'https://www.facebook.com/share.php?u=' + paramsObj.shareUrlEncoded(); 232 break; 233 case 'twitter': 234 url = 'https://twitter.com/intent/tweet?url=' + paramsObj.shareUrlEncoded() + 235 '&text=' + encodeURIComponent(title + (text && title ? ' - ' : '') + text); 236 if (via) 237 url += '&via=' + via.replace('@', ''); 238 break; 239 case 'google-plus': 240 url = 'https://plus.google.com/share?url=' + paramsObj.shareUrlEncoded(); 241 break; 242 case 'pinterest': 243 url = 'https://pinterest.com/pin/create/button/?url=' + paramsObj.shareUrlEncoded() + 244 '&description=' + encodeURIComponent(text); 245 if (image) 246 url += '&media=' + encodeURIComponent(image); 247 break; 248 case 'tumblr': 249 url = 'https://www.tumblr.com/share/link?url=' + paramsObj.shareUrlEncoded() + 250 '&name=' + encodeURIComponent(title) + 251 '&description=' + encodeURIComponent(text); 252 break; 253 case 'linkedin': 254 url = 'https://www.linkedin.com/shareArticle?mini=true&url=' + paramsObj.shareUrlEncoded() + 255 '&title=' + encodeURIComponent(title) + 256 '&summary=' + encodeURIComponent(text); 257 break; 258 case 'vk': 259 url = 'https://vkontakte.ru/share.php?url=' + paramsObj.shareUrlEncoded(); 260 break; 261 case 'buffer': 262 url = 'https://buffer.com/add?source=button&url=' + paramsObj.shareUrlEncoded() + 263 '&text=' + encodeURIComponent(text); 264 break; 265 case 'email': 266 url = 'mailto:?subject=' + encodeURIComponent(title) + 267 '&body=' + encodeURIComponent(title + '\n' + shareUrl + '\n\n' + text + '\n'); 268 break; 269 } 270 271 paramsObj.networkUrl = url; 272 273 if (options.onBeforeOpen) { 274 options.onBeforeOpen(el, network, paramsObj) 275 } 276 277 return paramsObj.networkUrl; 278 } 279 280 function getShareUrl(options, network, el, dataOpts) { 281 dataOpts = dataOpts || getDataOpts(options, network, el); 282 return dataOpts['url'] || window.location.href; 283 } 284 285 function getTitle(network) { 286 var title; 287 if (network == 'twitter') 288 title = getMetaContent('twitter:title'); 289 return title || document.title; 290 } 291 292 function getText(network) { 293 var text; 294 if (network == 'twitter') 295 text = getMetaContent('twitter:description'); 296 return text || getMetaContent('description'); 297 } 298 299 function getMetaContent(tagName, attr) { 300 var text, 301 tag = $('meta[' + (attr ? attr : tagName.indexOf('og:') === 0 ? 'property' : 'name') + '="' + tagName + '"]'); 302 if (tag.length) { 303 text = tag[0].getAttribute('content') || ''; 304 } 305 return text || '' 306 } 307 308 function getDataOpts(options, network, el) {
309 var validOpts = ['url', 'title', 'text', 'image'], 310 opts = {}, optValue, optKey, dataKey, a, parent = el.parentNode; 311 network == 'twitter' && validOpts.push('via'); 312 for (a in validOpts) { 313 optKey = validOpts[a]; 314 dataKey = 'data-' + optKey; 315 optValue = el.getAttribute(dataKey) || parent.getAttribute(dataKey) || 316 (options[network] && typeof options[network][optKey] != 'undefined' ? options[network][optKey] : options[optKey]); 317 if (typeof optValue != 'undefined') { 318 opts[optKey] = optValue; 319 } 320 } 321 return opts; 322 } 323 324 325 function addCount(el, cnt) { 326 var newEl = document.createElement('div'); 327 newEl.innerHTML = cnt; 328 newEl.className = 'ssk-num'; 329 el.appendChild(newEl); 330 } 331 332 function getCount(network, shareUrl, options, onReady) { 333 var url, parseFunc, body, 334 shareUrlEnc = encodeURIComponent(shareUrl); 335 switch (network) { 336 case 'facebook': 337 url = 'https://graph.facebook.com/?id=' + shareUrlEnc; 338 parseFunc = function (r) { 339 return onReady(r.share ? r.share.share_count : 0); 340 }; 341 break; 342 case 'twitter': 343 if (options && options.twitter && options.twitter.countCallback) { 344 options.twitter.countCallback(shareUrl, onReady); 345 } 346 break; 347 case 'google-plus': 348 url = 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'; 349 body = "[{\"method\":\"pos.plusones.get\",\"id\":\"p\"," + 350 "\"params\":{\"id\":\"" + shareUrl + "\",\"userId\":\"@viewer\",\"groupId\":\"@self\",\"nolog\":true}," + 351 "\"jsonrpc\":\"2.0\",\"key\":\"p\",\"apiVersion\":\"v1\"}]"; 352 parseFunc = function (r) { 353 r = JSON.parse(r); 354 if (r.length) { 355 return onReady(r[0].result.metadata.globalCounts.count); 356 } 357 }; 358 ajax(url, parseFunc, body); 359 return; 360 case 'linkedin': 361 url = 'https://www.linkedin.com/countserv/count/share?url=' + shareUrlEnc; 362 parseFunc = function (r) { 363 return onReady(r.count); 364 }; 365 break; 366 case 'pinterest': 367 url = 'https://api.pinterest.com/v1/urls/count.json?url=' + shareUrlEnc; 368 parseFunc = function (r) { 369 return onReady(r.count); 370 }; 371 break; 372 case 'vk': 373 url = 'https://vk.com/share.php?act=count&url=' + shareUrlEnc; 374 parseFunc = function (r) { 375 return onReady(r); 376 }; 377 break; 378 case 'buffer': 379 url = 'https://api.bufferapp.com/1/links/shares.json?url=' + shareUrlEnc; 380 parseFunc = function (r) { 381 return onReady(r.shares); 382 }; 383 break; 384 } 385 url && parseFunc && JSONPRequest(network, url, parseFunc, body); 386 } 387 388 function ajax(url, callback, body) { 389 var request = new XMLHttpRequest(); 390 request.onreadystatechange = function () { 391 if (this.readyState === 4) { 392 if (this.status >= 200 && this.status < 400) { 393 callback(this.responseText); 394 } 395 } 396 }; 397 request.open('POST', url, true); 398 request.setRequestHeader('Content-Type', 'application/json'); 399 request.send(body); 400 } 401 402 function JSONPRequest(network, url, callback) { 403 var callbackName = 'cb_' + network + '_' + Math.round(100000 * Math.random()), 404 script = document.createElement('script'); 405 window[callbackName] = function (data) { 406 try { // IE8 407 delete window[callbackName]; 408 } catch (e) { 409 } 410 document.body.removeChild(script); 411 callback(data); 412 }; 413 if (network == 'vk') { 414 window['VK'] = { 415 Share: { 416 count: function (a, b) { 417 window[callbackName](b); 418 } 419 } 420 }; 421 } else if (network == 'google-plus') { 422 window['services'] = { 423 gplus: { 424 cb: window[callbackName] 425 } 426 }; 427 } 428 script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName; 429 document.body.appendChild(script); 430 return true; 431 } 432 433 return { 434 init: init 435 }; 436})(); 437 438window.SocialShareKit = SocialShareKit;
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.