1/*global angular*/ 2/*eslint no-loop-func:0, func-names:0*/ 3 4(function withAngular(angular) { 5 'use strict'; 6 7 angular.module('720kb.socialshare', []) 8 .directive('socialshare', ['$window', '$location', 9 function manageDirective($window, $location) { 10 11 return { 12 'restrict': 'A', 13 'link': function linkingFunction($scope, element, attr) { 14 15 var key 16 , attributeName 17 , properties = {} 18 , propDefaults = { 19 'url': '', 20 'redirectUri': '', 21 'provider': '', 22 'type': '', 23 'text': '', 24 'caption': '', 25 'to': '', 26 'ref': '', 27 'display': '', 28 'from': '', 29 'media': '', 30 'hashtags': '', 31 'via': '', 32 'description': '', 33 'source': '', 34 'subreddit': '', 35 'popupHeight': 500, 36 'popupWidth': 500 37 }; 38 // observe the values in each of the properties so that if they're updated elsewhere, 39 // they are updated in this directive. 40 for (key in propDefaults) { 41 if (propDefaults.hasOwnProperty(key)) { 42 attributeName = 'socialshare' + key.substring(0, 1).toUpperCase() + key.substring(1); 43 (function observePropValues(keyName) { 44 attr.$observe(attributeName, function observeAttrs(value) { 45 if (value) { 46 properties[keyName] = value; 47 } 48 }); 49 }(key)); 50 if (properties[key] === undefined){ 51 properties[key] = propDefaults[key]; 52 } 53 } 54 } 55 56 properties.eventTrigger = attr.socialshareTrigger || 'click'; 57 58 $scope.facebookShare = function manageFacebookShare(data) { 59 60 if (data.type && data.type === 'feed') { 61 62 // if user specifies that they want to use the Facebook feed dialog (https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.4) 63 var urlString = 'https://www.facebook.com/dialog/feed?display=popup' + 64 '&app_id=' + encodeURI(data.via) + 65 '&redirect_uri=' + encodeURI(data.redirectUri); 66 67 if (data.url) { 68 urlString += '&link=' + encodeURIComponent(data.url); 69 } 70 71 if (data.to) { 72 urlString += '&to=' + encodeURIComponent(data.to); 73 } 74 if (data.display) { 75 urlString += '&display=' + encodeURIComponent(data.display); 76 } 77 78 if (data.ref) { 79 urlString += '&ref=' + encodeURIComponent(data.ref); 80 } 81 82 if (data.from) { 83 urlString += '&from=' + encodeURIComponent(data.from); 84 } 85 86 if (data.description) { 87 urlString += '&description=' + encodeURIComponent(data.description); 88 } 89 90 if (data.text) { 91 urlString += '&name=' + encodeURIComponent(data.text); 92 } 93 94 if (data.caption) { 95 urlString += '&caption=' + encodeURIComponent(data.caption); 96 } 97 98 if (data.media) { 99 urlString += '&picture=' + encodeURIComponent(data.media); 100 } 101 102 if (data.source) { 103 urlString += '&source=' + encodeURIComponent(data.source); 104 } 105 106 $window.open( 107 urlString, 108 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 109 110 } else { 111 112 //otherwise default to using sharer.php 113 $window.open( 114 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(data.url || $location.absUrl()) 115 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 116 } 117 }; 118 119 $scope.twitterShare = function manageTwitterShare(data) { 120 var urlString = 'https://www.twitter.com/intent/tweet?'; 121 122 if (data.text) { 123 urlString += 'text=' + encodeURIComponent(data.text); 124 } 125 126 if (data.via) { 127 urlString += '&via=' + encodeURI(data.via); 128 } 129 130 if (data.hashtags) { 131 urlString += '&hashtags=' + encodeURI(data.hashtags); 132 } 133 134 //default to the current page if a URL isn't specified 135 urlString += '&url=' + encodeURIComponent(data.url || $location.absUrl()); 136 137 $window.open( 138 urlString, 139 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight 140 ); 141 142 }; 143 144 $scope.googlePlusShare = function manageGooglePlusShare(data) { 145 146 $window.open( 147 'https://plus.google.com/share?url=' + encodeURIComponent(data.url || $location.absUrl()) 148 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 149 }; 150 151 $scope.redditShare = function manageRedditShare(data) { 152 var urlString = 'https://www.reddit.com/'; 153 154 if (data.subreddit) { 155 urlString += 'r/' + data.subreddit + '/submit?url='; 156 } else { 157 urlString += 'submit?url='; 158 } 159 160 /*- 161 * Reddit isn't responsive and at default width for our popups (500 x 500), everything is messed up. 162 * So, overriding the width if it is less than 900 (played around to settle on this) and height if 163 * it is less than 650px. 164 */ 165 if (data.popupWidth < 900) { 166 data.popupWidth = 900; 167 } 168 169 if (data.popupHeight < 650) { 170 data.popupHeight = 650; 171 } 172 173 $window.open( 174 urlString + encodeURIComponent(data.url || $location.absUrl()) + '&title=' + encodeURIComponent(data.text) 175 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 176 }; 177 178 $scope.stumbleuponShare = function manageStumbleuponShare(data) { 179 180 $window.open( 181 'https://www.stumbleupon.com/submit?url=' + encodeURIComponent(data.url || $location.absUrl()) + '&title=' + encodeURIComponent(data.text) 182 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 183 }; 184 185 $scope.linkedinShare = function manageLinkedinShare(data) { 186 187 $window.open( 188 'https://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(data.url || $location.absUrl()) + '&title=' + encodeURIComponent(data.text) 189 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 190 }; 191 192 $scope.pinterestShare = function managePinterestShare(data) { 193 194 $window.open( 195 'https://www.pinterest.com/pin/create/button/?url=' + encodeURIComponent(data.url || $location.absUrl()) + '&media=' + encodeURI(data.media) + '&description=' + encodeURIComponent(data.text) 196 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 197 }; 198 199 $scope.diggShare = function manageDiggShare(data) { 200 201 $window.open( 202 'https://www.digg.com/submit?url=' + encodeURIComponent(data.url || $location.absUrl()) + '&title=' + encodeURIComponent(data.text) 203 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 204 }; 205 206 $scope.tumblrShare = function manageTumblrShare(data) { 207 208 if (data.media) { 209 var urlString = 'https://www.tumblr.com/share/photo?source=' + encodeURIComponent(data.media); 210 211 if (data.text) { 212 urlString += '&caption=' + encodeURIComponent(data.text); 213 } 214 215 $window.open( 216 urlString, 217 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 218 } else { 219 220 $window.open( 221 'https://www.tumblr.com/share/link?url=' + encodeURIComponent(data.url) + '&description=' + encodeURIComponent(data.text) 222 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 223 } 224 }; 225 226 $scope.vkShare = function manageVkShare(data) { 227 228 $window.open( 229 'https://www.vk.com/share.php?url=' + encodeURIComponent(data.url || $location.absUrl()) 230 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 231 }; 232 233 $scope.deliciousShare = function manageDeliciousShare(data) { 234 235 $window.open( 236 'https://www.delicious.com/save?v=5&noui&jump=close&url=' + encodeURIComponent(data.url || $location.absUrl()) + '&title=' + encodeURIComponent(data.text) 237 , 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight); 238 }; 239 240 $scope.bufferShare = function manageBufferShare(data) { 241 var urlString = 'https://bufferapp.com/add?'; 242 243 if (data.text) { 244 urlString += 'text=' + encodeURIComponent(data.text); 245 } 246 247 if (data.via) { 248 urlString += '&via=' + encodeURI(data.via); 249 } 250 251 //default to the current page if a URL isn't specified 252 urlString += '&url=' + encodeURIComponent(data.url || $location.absUrl()); 253 254 $window.open( 255 urlString, 256 'sharer', 'toolbar=0,status=0,width=' + data.popupWidth + ',height=' + data.popupHeight 257 ); 258 }; 259 260 element.bind(properties.eventTrigger, function onEventTriggered() { 261 262 switch (properties.provider) { 263 case 'facebook': 264 265 $scope.facebookShare(properties); 266 break; 267 268 case 'google+': 269 270 $scope.googlePlusShare(properties); 271 break; 272 273 case 'twitter': 274 275 $scope.twitterShare(properties); 276 break; 277 278 case 'stumbleupon': 279 280 $scope.stumbleuponShare(properties); 281 break; 282 283 case 'reddit': 284 285 $scope.redditShare(properties); 286 break; 287 288 case 'pinterest': 289 290 $scope.pinterestShare(properties); 291 break; 292 293 case 'linkedin': 294 295 $scope.linkedinShare(properties); 296 break; 297 298 case 'digg': 299 300 $scope.diggShare(properties); 301 break; 302 303 case 'tumblr': 304 305 $scope.tumblrShare(properties); 306 break; 307 308 case 'delicious': 309 310 $scope.deliciousShare(properties); 311 break; 312 313 case 'vk': 314 315 $scope.vkShare(properties); 316 break; 317 318 case 'buffer': 319 320 $scope.bufferShare(properties); 321 break; 322 323 default: return; 324 } 325 }); 326 } 327 }; 328 }]); 329}(angular));
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.