1// File#: _1_social-sharing 2// Usage: codyhouse.co/license 3(function() { 4 function initSocialShare(button) { 5 button.addEventListener('click', function(event){ 6 event.preventDefault(); 7 var social = button.getAttribute('data-social'); 8 var url = getSocialUrl(button, social); 9 (social == 'mail') 10 ? window.location.href = url 11 : window.open(url, social+'-share-dialog', 'width=626,height=436'); 12 }); 13 }; 14 15 function getSocialUrl(button, social) { 16 var params = getSocialParams(social); 17 var newUrl = ''; 18 for(var i = 0; i < params.length; i++) { 19 var paramValue = button.getAttribute('data-'+params[i]); 20 if(params[i] == 'hashtags') paramValue = encodeURI(paramValue.replace(/\#| /g, '')); 21 if(paramValue) { 22 (social == 'facebook') 23 ? newUrl = newUrl + 'u='+encodeURIComponent(paramValue)+'&' 24 : newUrl = newUrl + params[i]+'='+encodeURIComponent(paramValue)+'&'; 25 } 26 } 27 if(social == 'linkedin') newUrl = 'mini=true&'+newUrl; 28 return button.getAttribute('href')+'?'+newUrl; 29 }; 30 31 function getSocialParams(social) { 32 var params = []; 33 switch (social) { 34 case 'twitter': 35 params = ['text', 'hashtags']; 36 break; 37 case 'facebook': 38 case 'linkedin': 39 params = ['url']; 40 break; 41 case 'pinterest': 42 params = ['url', 'media', 'description']; 43 break; 44 case 'mail': 45 params = ['subject', 'body']; 46 break; 47 } 48 return params; 49 }; 50 51 var socialShare = document.getElementsByClassName('js-social-share'); 52 if(socialShare.length > 0) { 53 for( var i = 0; i < socialShare.length; i++) { 54 (function(i){initSocialShare(socialShare[i])})(i); 55 } 56 } 57}());
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.