1/*********************************************** 2 needShareButton 3 - Version 1.0.0 4 - Copyright 2015 Dzmitry Vasileuski 5 - Licensed under MIT (http://opensource.org/licenses/MIT) 6***********************************************/ 7 8(function() { 9 10 // share dropdown class 11 window.needShareDropdown = function(elem, options) { 12 // create element reference 13 var root = this; 14 root.elem = elem; 15 root.elem.className += root.elem.className.length ? ' need-share-button' : 'need-share-button'; 16 17 /* Helpers 18 ***********************************************/ 19 20 // get title from html 21 root.getTitle = function() { 22 var content; 23 // check querySelector existance for old browsers 24 if (document.querySelector) { 25 if (content = document.querySelector('meta[property="og:title"]') || document.querySelector('meta[name="twitter:title"]')) { 26 return content.getAttribute('content'); 27 } else if (content = document.querySelector('title')) { 28 return content.innerText; 29 } else 30 return ''; 31 } else { 32 if (content = document.title) 33 return content.innerText; 34 else 35 return ''; 36 } 37 }; 38 39 // get image from html 40 root.getImage = function() { 41 var content; 42 // check querySelector existance for old browsers 43 if (document.querySelector) { 44 if (content = document.querySelector('meta[property="og:image"]') || document.querySelector('meta[name="twitter:image"]')) { 45 return content.getAttribute('content'); 46 } else 47 return ''; 48 } else 49 return ''; 50 }; 51 52 // get description from html 53 root.getDescription = function() { 54 var content; 55 // check querySelector existance for old browsers 56 if (document.querySelector) { 57 if (content = document.querySelector('meta[property="og:description"]') || document.querySelector('meta[name="twitter:description"]') || document.querySelector('meta[name="description"]')) { 58 return content.getAttribute('content'); 59 } else 60 return ''; 61 } else { 62 if (content = document.getElementsByTagName('meta').namedItem('description')) 63 return content.getAttribute('content'); 64 else 65 return ''; 66 } 67 }; 68 69 // share urls for all networks 70 root.share = { 71 'mailto' : function() { 72 var url = 'mailto:?subject=' + encodeURIComponent(root.options.title) + '&body=Pensé que te gustarÃa leer esto: ' + encodeURIComponent(root.options.url) + ' - ' + encodeURIComponent(root.options.description); 73 74 window.location.href = url; 75 }, 76 'twitter' : function() { 77 var url = root.options.protocol + 'twitter.com/intent/tweet?status='; 78 url += '&text=' + encodeURIComponent(root.options.title) 79 url += '&url=' + encodeURIComponent(root.options.url); 80 81 root.popup(url); 82 }, 83 'pinterest' : function() { 84 var url = root.options.protocol + 'pinterest.com/pin/create/bookmarklet/?is_video=false'; 85 url += '&media=' + encodeURIComponent(root.options.image); 86 url += '&url=' + encodeURIComponent(root.options.url); 87 url += '&description=' + encodeURIComponent(root.options.title); 88 89 root.popup(url); 90 }, 91 'facebook' : function() { 92 var url = root.options.protocol + 'www.facebook.com/sharer/sharer.php?'; 93 url += 'u=' + encodeURIComponent(root.options.url); 94 url += '&title=' + encodeURIComponent(root.options.title); 95 96 root.popup(url); 97 }, 98 99 'whatsapp' : function() { 100 var url = root.options.protocol + 'wa.me/?text=' + encodeURIComponent(root.options.title) + ': ' + encodeURIComponent(root.options.url); 101 102 root.popup(url); 103 }, 104 105 'telegram' : function() { 106 var url = root.options.protocol + 't.me/share/url?url=' + encodeURIComponent(root.options.url) + '&text=' + encodeURIComponent(root.options.title); 107 108 root.popup(url); 109 }, 110 111 'googleplus' : function() { 112 var url = root.options.protocol + 'plus.google.com/share?'; 113 url += 'url=' + encodeURIComponent(root.options.url); 114 115 root.popup(url); 116 }, 117 'reddit' : function() { 118 var url = root.options.protocol + 'www.reddit.com/submit?'; 119 url += 'url=' + encodeURIComponent(root.options.url); 120 url += '&title=' + encodeURIComponent(root.options.title); 121 122 root.popup(url); 123 }, 124 'delicious' : function() { 125 var url = root.options.protocol + 'del.icio.us/post?'; 126 url += 'url=' + encodeURIComponent(root.options.url); 127 url += '&title=' + encodeURIComponent(root.options.title); 128 url += '¬es=' + encodeURIComponent(root.options.description); 129 130 root.popup(url); 131 }, 132 'tapiture' : function() { 133 var url = root.options.protocol + 'tapiture.com/bookmarklet/image?'; 134 url += 'img_src=' + encodeURIComponent(root.options.image); 135 url += '&page_url=' + encodeURIComponent(root.options.url); 136 url += '&page_title=' + encodeURIComponent(root.options.title); 137 138 root.popup(url); 139 }, 140 'stumbleupon' : function() { 141 var url = root.options.protocol + 'www.stumbleupon.com/submit?'; 142 url += 'url=' + encodeURIComponent(root.options.url); 143 url += '&title=' + encodeURIComponent(root.options.title); 144 145 root.popup(url); 146 }, 147 'linkedin' : function() { 148 var url = root.options.protocol + 'www.linkedin.com/shareArticle?mini=true'; 149 url += '&url=' + encodeURIComponent(root.options.url); 150 url += '&title=' + encodeURIComponent(root.options.title); 151 url += '&source=' + encodeURIComponent(root.options.source); 152 153 root.popup(url); 154 }, 155 'slashdot' : function() { 156 var url = root.options.protocol + 'slashdot.org/bookmark.pl?'; 157 url += 'url=' + encodeURIComponent(root.options.url); 158 url += '&title=' + encodeURIComponent(root.options.title); 159 160 root.popup(url); 161 }, 162 'technorati' : function() { 163 var url = root.options.protocol + 'technorati.com/faves?'; 164 url += 'add=' + encodeURIComponent(root.options.url); 165 url += '&title=' + encodeURIComponent(root.options.title); 166 167 root.popup(url); 168 }, 169 'posterous' : function() { 170 var url = root.options.protocol + 'posterous.com/share?'; 171 url += 'linkto=' + encodeURIComponent(root.options.url); 172 173 root.popup(url); 174 }, 175 'tumblr' : function() { 176 var url = root.options.protocol + 'www.tumblr.com/share?v=3'; 177 url += '&u=' + encodeURIComponent(root.options.url); 178 url += '&t=' + encodeURIComponent(root.options.title); 179 180 root.popup(url); 181 }, 182 'googlebookmarks' : function() { 183 var url = root.options.protocol + 'www.google.com/bookmarks/mark?op=edit'; 184 url += '&bkmk=' + encodeURIComponent(root.options.url); 185 url += '&title=' + encodeURIComponent(root.options.title); 186 url += '&annotation=' + encodeURIComponent(root.options.description); 187 188 root.popup(url); 189 }, 190 'newsvine' : function() { 191 var url = root.options.protocol + 'www.newsvine.com/_tools/seed&save?'; 192 url += 'u=' + encodeURIComponent(root.options.url); 193 url += '&h=' + encodeURIComponent(root.options.title); 194 195 root.popup(url); 196 }, 197 'pingfm' : function() { 198 var url = root.options.protocol + 'ping.fm/ref/?'; 199 url += 'link=' + encodeURIComponent(root.options.url); 200 url += '&title=' + encodeURIComponent(root.options.title); 201 url += '&body=' + encodeURIComponent(root.options.description); 202 203 root.popup(url); 204 }, 205 'evernote' : function() { 206 var url = root.options.protocol + 'www.evernote.com/clip.action?'; 207 url += 'url=' + encodeURIComponent(root.options.url); 208 url += '&title=' + encodeURIComponent(root.options.title); 209 210 root.popup(url); 211 }, 212 'friendfeed' : function() { 213 var url = root.options.protocol + 'www.friendfeed.com/share?'; 214 url += 'url=' + encodeURIComponent(root.options.url); 215 url += '&title=' + encodeURIComponent(root.options.title); 216 217 root.popup(url); 218 }, 219 'vkontakte' : function() { 220 var url = root.options.protocol + 'vkontakte.ru/share.php?'; 221 url += 'url=' + encodeURIComponent(root.options.url); 222 url += '&title=' + encodeURIComponent(root.options.title); 223 url += '&description=' + encodeURIComponent(root.options.description); 224 url += '&image=' + encodeURIComponent(root.options.image); 225 url += '&noparse=true'; 226 227 root.popup(url); 228 }, 229 'odnoklassniki' : function() { 230 var url = root.options.protocol + 'www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1'; 231 url += '&st.comments=' + encodeURIComponent(root.options.description); 232 url += '&st._surl=' + encodeURIComponent(root.options.url); 233 234 root.popup(url); 235 }, 236 'mailru' : function() { 237 var url = root.options.protocol + 'connect.mail.ru/share?'; 238 url += 'url=' + encodeURIComponent(root.options.url); 239 url += '&title=' + encodeURIComponent(root.options.title); 240 url += '&description=' + encodeURIComponent(root.options.description); 241 url += '&imageurl=' + encodeURIComponent(root.options.image); 242 243 root.popup(url); 244 } 245 246 } 247 248 // open share link in a popup 249 root.popup = function(url) { 250 // set left and top position 251 var popupWidth = 500, 252 popupHeight = 400, 253 // fix dual screen mode 254 dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left, 255 dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top, 256 width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width, 257 height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height, 258 // calculate top and left position 259 left = ((width / 2) - (popupWidth / 2)) + dualScreenLeft, 260 top = ((height / 2) - (popupHeight / 2)) + dualScreenTop, 261 262 // show popup 263 shareWindow = window.open(url,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + popupWidth + ', height=' + popupHeight + ', top='
263+ top + ', left=' + left); 264 265 // Puts focus on the newWindow 266 if (window.focus) { 267 shareWindow.focus(); 268 } 269 } 270 271 // find closest 272 function closest(elem, parent) { 273 if (typeof(parent) == 'string') { 274 var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; 275 276 if (!!matchesSelector) { 277 while (elem) { 278 if (matchesSelector.bind(elem)(parent)) { 279 return elem; 280 } else { 281 elem = elem.parentElement; 282 } 283 } 284 } 285 return false; 286 } else { 287 while (elem) { 288 if (elem == parent) { 289 return elem; 290 } else { 291 elem = elem.parentElement; 292 } 293 } 294 return false; 295 } 296 } 297 298 /* Set options 299 ***********************************************/ 300 301 // create default options 302 root.options = { 303 shareButtonClass: false, // child selector of custom share button 304 iconStyle: 'default', // default or box 305 boxForm: 'horizontal', // horizontal or vertical 306 position: 'bottomCenter', // top / middle / bottom + Left / Center / Right 307 buttonText: 'Share', 308 protocol: ['http', 'https'].indexOf(window.location.href.split(':')[0]) === -1 ? 'https://' : '//', 309 url: window.location.href, 310 title: root.getTitle(), 311 image: root.getImage(), 312 description: root.getDescription(), 313 networks: 'Whatsapp,Telegram,Mailto,Twitter,Pinterest,Facebook,GooglePlus,Reddit,Delicious,Tapiture,StumbleUpon,Linkedin,Slashdot,Technorati,Posterous,Tumblr,GoogleBookmarks,Newsvine,Pingfm,Evernote,Friendfeed,Vkontakte,Odnoklassniki,Mailru' 314 } 315 316 // integrate custom options 317 for (var i in options) { 318 root.options[i] = options[i]; 319 } 320 321 // integrate data attribute options 322 for (var option in root.elem.dataset) { 323 // replace only 'share-' prefixed data-attributes 324 if (option.match(/share/)) { 325 var new_option = option.replace(/share/, ''); 326 if (!new_option.length) { 327 continue; 328 } 329 new_option = new_option.charAt(0).toLowerCase() + new_option.slice(1); 330 root.options[new_option] = root.elem.dataset[option]; 331 } 332 } 333 334 // convert networks string into array 335 root.options.networks = root.options.networks.toLowerCase().split(','); 336 337 /* Create layout 338 ***********************************************/ 339 340 // create dropdown button if not exists 341 if (root.options.shareButtonClass) { 342 for (var i = 0; i < root.elem.children.length; i++) { 343 if (root.elem.children[i].className.match(root.options.shareButtonClass)) 344 root.button = root.elem.children[i]; 345 } 346 } 347 if (!root.button) { 348 root.button = document.createElement('span'); 349 root.button.innerText = root.options.buttonText; 350 root.elem.appendChild(root.button); 351 } 352 root.button.className += ' need-share-button_button'; 353 354 // show and hide dropdown 355 root.button.addEventListener('click', function(event) { 356 event.preventDefault(); 357 if (!root.elem.className.match(/need-share-button-opened/)) { 358 root.elem.className += ' need-share-button-opened'; 359 } else { 360 root.elem.className = root.elem.className.replace(/\s*need-share-button-opened/g,''); 361 } 362 }); 363 364 // create dropdown 365 root.dropdown = document.createElement('span'); 366 root.dropdown.className = 'need-share-button_dropdown'; 367 root.elem.appendChild(root.dropdown); 368 369 // set dropdown row length 370 if (root.options.iconStyle == 'box' && root.options.boxForm == 'horizontal') 371 root.dropdown.className += ' need-share-button_dropdown-box-horizontal'; 372 else if (root.options.iconStyle == 'box' && root.options.boxForm == 'vertical') 373 root.dropdown.className += ' need-share-button_dropdown-box-vertical'; 374 375 // set dropdown position 376 setTimeout(function() { 377 switch (root.options.position) { 378 case 'topLeft': 379 root.dropdown.className += ' need-share-button_dropdown-top-left'; 380 break 381 case 'topRight': 382 root.dropdown.className += ' need-share-button_dropdown-top-right'; 383 break 384 case 'topCenter': 385 root.dropdown.className += ' need-share-button_dropdown-top-center'; 386 root.dropdown.style.marginLeft = - root.dropdown.offsetWidth / 2 + 'px'; 387 break 388 case 'middleLeft': 389 root.dropdown.className += ' need-share-button_dropdown-middle-left'; 390 root.dropdown.style.marginTop = - root.dropdown.offsetHeight / 2 + 'px'; 391 break 392 case 'middleRight': 393 root.dropdown.className += ' need-share-button_dropdown-middle-right'; 394 root.dropdown.style.marginTop = - root.dropdown.offsetHeight / 2 + 'px'; 395 break 396 case 'bottomLeft': 397 root.dropdown.className += ' need-share-button_dropdown-bottom-left'; 398 break 399 case 'bottomRight': 400 root.dropdown.className += ' need-share-button_dropdown-bottom-right'; 401 break 402 case 'bottomCenter': 403 root.dropdown.className += ' need-share-button_dropdown-bottom-center'; 404 root.dropdown.style.marginLeft = - root.dropdown.offsetWidth / 2 + 'px'; 405 break 406 default: 407 root.dropdown.className += ' need-share-button_dropdown-bottom-center'; 408 root.dropdown.style.marginLeft = - root.dropdown.offsetWidth / 2 + 'px'; 409 break 410 } 411 },1); 412 413
414 // fill fropdown with buttons 415 var iconClass = root.options.iconStyle == 'default' ? 'need-share-button_link need-share-button_' : 'need-share-button_link-' + root.options.iconStyle + ' need-share-button_link need-share-button_'; 416 for (var network in root.options.networks) { 417 var link = document.createElement('span'); 418 network = root.options.networks[network]; 419 link.className = iconClass + network; 420 link.dataset.network = network; 421 root.dropdown.appendChild(link); 422 423 // add share function to event listener 424 link.addEventListener('click', function() { 425 root.share[this.dataset.network](); 426 }); 427 } 428 429 // close on click outside 430 document.addEventListener('click', function(event) { 431 if (!closest(event.target.parentNode, root.elem)) { 432 root.elem.className = root.elem.className.replace(/\s*need-share-button-opened/g,''); 433 } 434 }); 435 436 } 437 438})();
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.