1/** 2 * AngularJS directives for social sharing buttons - Facebook Like, Google+, Twitter and Pinterest 3 * @author Jason Watmore <[email protected]> (http://jasonwatmore.com) 4 * @version 1.2.0 5 */ 6(function () { 7 angular.module('angulike', []) 8 9 .directive('fbLike', [ 10 '$window', '$rootScope', function ($window, $rootScope) { 11 return { 12 restrict: 'A', 13 scope: { 14 fbLike: '=?' 15 }, 16 link: function (scope, element, attrs) { 17 if (!$window.FB) { 18 // Load Facebook SDK if not already loaded 19 $.getScript('//connect.facebook.net/en_US/sdk.js', function () { 20 $window.FB.init({ 21 appId: $rootScope.facebookAppId, 22 xfbml: true, 23 version: 'v2.0' 24 }); 25 renderLikeButton(); 26 }); 27 } else { 28 renderLikeButton(); 29 } 30 31 var watchAdded = false; 32 function renderLikeButton() { 33 if (!!attrs.fbLike && !scope.fbLike && !watchAdded) { 34 // wait for data if it hasn't loaded yet 35 watchAdded = true; 36 var unbindWatch = scope.$watch('fbLike', function (newValue, oldValue) { 37 if (newValue) { 38 renderLikeButton(); 39 40 // only need to run once 41 unbindWatch(); 42 } 43 44 }); 45 return; 46 } else { 47 element.html('<div class="fb-like"' + (!!scope.fbLike ? ' data-href="' + scope.fbLike + '"' : '') + ' data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>'); 48 $window.FB.XFBML.parse(element.parent()[0]); 49 } 50 } 51 } 52 }; 53 } 54 ]) 55 56 .directive('googlePlus', [ 57 '$window', function ($window) { 58 return { 59 restrict: 'A', 60 scope: { 61 googlePlus: '=?' 62 }, 63 link: function (scope, element, attrs) { 64 if (!$window.gapi) { 65 // Load Google SDK if not already loaded 66 $.getScript('//apis.google.com/js/platform.js', function () { 67 renderPlusButton(); 68 }); 69 } else { 70 renderPlusButton(); 71 } 72 73 var watchAdded = false; 74 function renderPlusButton() { 75 if (!!attrs.googlePlus && !scope.googlePlus && !watchAdded) { 76 // wait for data if it hasn't loaded yet 77 watchAdded = true; 78 var unbindWatch = scope.$watch('googlePlus', function (newValue, oldValue) { 79 if (newValue) { 80 renderPlusButton(); 81 82 // only need to run once 83 unbindWatch(); 84 } 85 86 }); 87 return; 88 } else { 89 element.html('<div class="g-plusone"' + (!!scope.googlePlus ? ' data-href="' + scope.googlePlus + '"' : '') + ' data-size="medium"></div>'); 90 $window.gapi.plusone.go(element.parent()[0]); 91 } 92 } 93 } 94 }; 95 } 96 ]) 97 98 .directive('tweet', [ 99 '$window', '$location', 100 function ($window, $location) { 101 return { 102 restrict: 'A', 103 scope: { 104 tweet: '=', 105 tweetUrl: '=' 106 }, 107 link: function (scope, element, attrs) { 108 if (!$window.twttr) { 109 // Load Twitter SDK if not already loaded 110 $.getScript('//platform.twitter.com/widgets.js', function () { 111 renderTweetButton(); 112 }); 113 } else { 114 renderTweetButton(); 115 } 116 117 var watchAdded = false;
118 function renderTweetButton() { 119 if (!scope.tweet && !watchAdded) { 120 // wait for data if it hasn't loaded yet 121 watchAdded = true; 122 var unbindWatch = scope.$watch('tweet', function (newValue, oldValue) { 123 if (newValue) { 124 renderTweetButton(); 125 126 // only need to run once 127 unbindWatch(); 128 } 129 }); 130 return; 131 } else { 132 element.html('<a href="https://twitter.com/share" class="twitter-share-button" data-text="' + scope.tweet + '" data-url="' + (scope.tweetUrl || $location.absUrl()) + '">Tweet</a>'); 133 $window.twttr.widgets.load(element.parent()[0]); 134 } 135 } 136 } 137 }; 138 } 139 ]) 140 141 .directive('pinIt', [ 142 '$window', '$location', 143 function ($window, $location) { 144 return { 145 restrict: 'A', 146 scope: { 147 pinIt: '=', 148 pinItImage: '=', 149 pinItUrl: '=' 150 }, 151 link: function (scope, element, attrs) { 152 if (!$window.parsePins) { 153 // Load Pinterest SDK if not already loaded 154 (function (d) { 155 var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT'); 156 p.type = 'text/javascript'; 157 p.async = true; 158 p.src = '//assets.pinterest.com/js/pinit.js'; 159 p['data-pin-build'] = 'parsePins'; 160 p.onload = function () { 161 if (!!$window.parsePins) { 162 renderPinItButton(); 163 } else { 164 setTimeout(p.onload, 100); 165 } 166 }; 167 f.parentNode.insertBefore(p, f); 168 }($window.document)); 169 } else { 170 renderPinItButton(); 171 } 172 173 var watchAdded = false; 174 function renderPinItButton() { 175 if (!scope.pinIt && !watchAdded) { 176 // wait for data if it hasn't loaded yet 177 watchAdded = true; 178 var unbindWatch = scope.$watch('pinIt', function (newValue, oldValue) { 179 if (newValue) { 180 renderPinItButton(); 181 182 // only need to run once 183 unbindWatch(); 184 } 185 }); 186 return; 187 } else { 188 element.html('<a href="//www.pinterest.com/pin/create/button/?url=' + (scope.pinItUrl || $location.absUrl()) + '&media=' + scope.pinItImage + '&description=' + scope.pinIt + '" data-pin-do="buttonPin" data-pin-config="beside"></a>'); 189 $window.parsePins(element.parent()[0]); 190 } 191 } 192 } 193 }; 194 } 195 ]); 196 197})();
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.