Repository: djds4rce/angular-socialshare Branch: master Commit: cde17481c79d Files: 8 Total size: 45.9 KB Directory structure: gitextract_aqwc0qfe/ ├── .gitignore ├── README.md ├── angular-socialshare.css ├── angular-socialshare.js ├── angular-socialshare.less ├── bower.json ├── gulpfile.js └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules ================================================ FILE: README.md ================================================ Angular Social Share ========= Angular Social Share is a collection of directives which lets you easily share your links various social networks. Currently Facebok, Google, Twitter and Linkdin are supported. Social Networks get the Meta data of the shared content like Title, Summary and Image from the Meta tags on the page by scraping. But Single Page Apps like Angular are unable to support crawling. But these dirictives use alternative so that Meta data is displayed where it is possible. Checkout the [Demo]. Change Log ---- As of Verstion 1 This directive supports two way binding of data, so now you can populate the data in the directive from a HTTP request. Future Plans ---- Support asyncronous loading of corresponding social plugin javascript assets. Getting Started ----- Install the library through bower. ```js bower install angular-socialshare ``` Include the script (and optional css file) in your html file. ```html ``` Add to your APP's dependency. ```js angular.module('testing',['djds4rce.angular-socialshare']) ``` IMPORTANT ---- For Correct Sharing of links and updating share count you must enable HTML5 Mode True for your application. i.e No `#` in URL'S . ```js angular.module('testing').config(function($locationProvider){ $locationProvider.html5Mode(true).hashPrefix('!'); }); ``` HTML5 Mode requires server configration [Explained Here] Share on Facebook ---- Facebook share uses facebook API which requires us to provide a APPID. Register a facebook app and Configure the APPID in your appplication. Note that you will get an error regarding 'not permitted URL' if you are testing this button in a localhost environment. ```js angular.module('testing').run(function($FB){ $FB.init('YOUR_APPID', 'COUNTRY_CODE'); // Country code format example: fr_FR }); ``` Use the Facebook Directive ```html {{ shares }} ``` As we are using Facebook share API and not the facebook share button, you will have to style your own Facebook button, or use the provided stylesheet that has styles for the horizontal count button. You also need to display the share count, which the directive fetches from a diffrent API. The directive has transclusion set to true. The latest Facebook share API only allows for a URL to be supplied, it will scrape the other data (image, title, description) from the supplied URL. The Attributes for the directives are ```js /* data-url: URL of the Shared Content data-shares: The Scope variable on which share count will be binded to. This lets you put multiple share buttons on a single page and bind the share count to the respective model object. data-callback: The Scope function which will receive [FB's Response object](https://developers.facebook.com/docs/javascript/reference/FB.ui) data-translate: To change the text of the button. EX: data-translate="'Partager'" */ ``` #### Share via Feed Dialog The feed dialog works in the same way as the normal share dialog, but also has some addittional attributes available ```html {{ shares }} ``` ```js /* data-url: URL of the Shared Content data-shares: The Scope variable on which share count will be binded to. This lets you put multiple share buttons on a single page and bind the share count to the respective model object. data-picture: The URL of a picture attached to the share. The picture must be at least 200px by 200px. data-source: The URL of a media file (either SWF or MP3) attached to this share. If SWF, you must also specify picture to provide a thumbnail for the video. data-name: The name of the link attachment. data-caption: The caption of the link (appears beneath the link name). If not specified, this field is automatically populated with the URL of the link. data-description: The description of the link (appears beneath the link caption). If not specified, this field is automatically populated by information scraped from the link, typically the title of the page. data-properties: A JSON object of key/value pairs which will appear in the stream attachment beneath the description, with each property on its own line. Keys must be strings, and values can be either strings or JSON objects with the keys text and href. data-actions: A JSON array containing a single object describing the action link which will appear next to the 'Comment' and 'Like' link under posts. The contained object must have the keys name and link. data-callback: The Scope function which will receive [FB's Response object](https://developers.facebook.com/docs/javascript/reference/FB.ui) data-translate: To change the text of the button. EX: data-translate="'Partager'" */ ``` Twitter ---- Include the twitter javascript in your HTML. ```html ``` Add Directive to the element where you want to display your Twitter Button ```html ``` The Attributes for the directives are ```js /* data-lang: Language of the tweet data-url: URL of the Shared Content data-count: Position of the share counter data-size: Size of the tweet button data-text: Content of the tweet data-via: User handle which will be tagged in the tweet For options checkout https://dev.twitter.com/docs/tweet-button */ ``` Linkedin ---- Although Linkedin has a share button and also a Javascript share API it does not take the title and the content as its parameters hence we will have to use the raw share URL to share the content. Use the Linkedin Directive ```html
',
link: function(scope, element, attr) {
var pintrestButtonRenderer = debounce(function() {
var pin_button = document.createElement("a");
pin_button.setAttribute("href", '//www.pinterest.com/pin/create/button/?url=' + encodeURIComponent(attr.href) + '&media=' + encodeURIComponent(attr.img) + '&description=' + encodeURIComponent(attr.description));
pin_button.setAttribute("pinDo", attr.pinDo || "buttonPin");
pin_button.setAttribute("pinConfig", attr.pinConfig || "beside");
element[0].innerHTML = '';
element.append(pin_button);
$timeout(function() {
$window.parsePins(element);
});
}, 100);
attr.$observe('href', pintrestButtonRenderer);
attr.$observe('img', pintrestButtonRenderer);
attr.$observe('description', pintrestButtonRenderer);
}
}
}]);
//Simple Debounce Implementation
//http://davidwalsh.name/javascript-debounce-function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this,
args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
//http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
/**
* RANDOM STRING GENERATOR
*
* Info: http://stackoverflow.com/a/27872144/383904
* Use: randomString(length [,"A"] [,"N"] );
* Default: return a random alpha-numeric string
* Arguments: If you use the optional "A", "N" flags:
* "A" (Alpha flag) return random a-Z string
* "N" (Numeric flag) return random 0-9 string
*/
function randomString(len, an) {
an = an && an.toLowerCase();
var str = "",
i = 0,
min = an == "a" ? 10 : 0,
max = an == "n" ? 10 : 62;
for (; i++ < len;) {
var r = Math.random() * (max - min) + min << 0;
str += String.fromCharCode(r += r > 9 ? r < 36 ? 55 : 61 : 48);
}
return str;
}
================================================
FILE: angular-socialshare.less
================================================
.facebookShare{
border: none;
visibility: visible;
width: auto;
height: 22px;
background: transparent;
overflow: hidden;
-webkit-text-size-adjust: none;
color: #333;
line-height: 1.28;
margin: 0;
padding: 0;
text-align: left;
direction: ltr;
cursor: pointer;
font-family: 'Helvetica Neue', Helvetica, Arial, 'lucida grande',tahoma,verdana,arial,sans-serif;
display: inline-block;
&:hover .facebookButton .pluginButton,
&:active .facebookButton .pluginButton,
&:focus .facebookButton .pluginButton{
background: #5b7bd5;
background: -moz-linear-gradient(top, #5b7bd5 0%, #4864b1 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#5b7bd5), color-stop(100%,#4864b1));
background: -webkit-linear-gradient(top, #5b7bd5 0%,#4864b1 100%);
background: -o-linear-gradient(top, #5b7bd5 0%,#4864b1 100%);
background: -ms-linear-gradient(top, #5b7bd5 0%,#4864b1 100%);
background: linear-gradient(to bottom, #5b7bd5 0%,#4864b1 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5b7bd5', endColorstr='#4864b1',GradientType=0 );
border-color: #5874c3 #4961a8 #41599f;
box-shadow: inset 0 0 1px #607fd6;
}
.facebookButton{
color:#3b5998;
text-decoration: none;
font-size: 11px;
text-align: left;
display: inline-block;
width:55px;
.pluginButton{
background: #4c69ba;
background: -moz-linear-gradient(top, #4c69ba 0%, #3b55a0 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c69ba), color-stop(100%,#3b55a0));
background: -webkit-linear-gradient(top, #4c69ba 0%,#3b55a0 100%);
background: -o-linear-gradient(top, #4c69ba 0%,#3b55a0 100%);
background: -ms-linear-gradient(top, #4c69ba 0%,#3b55a0 100%);
background: linear-gradient(to bottom, #4c69ba 0%,#3b55a0 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c69ba', endColorstr='#3b55a0',GradientType=0 );
border: none;
border-radius: 3px;
color: #fff;
cursor: pointer;
font-weight: bold;
height: 20px;
line-height: 20px;
padding: 0;
text-shadow: 0 -1px 0 #354c8c;
white-space: nowrap;
.pluginButtonContainer {
-webkit-font-smoothing: antialiased;
text-shadow: 1px 1px 1px rgba(255,255,255,0.004);
.pluginButtonImage {
display: inline-block;
}
}
button {
background: transparent;
border: 0;
color: inherit;
cursor: pointer;
font: inherit;
font-weight: bold;
margin: -1px;
outline: none;
padding: 0;
text-shadow: 0 -1px 0 #354c8c;
.pluginButtonIcon {
height: 14px;
left: 0;
margin: 0 4px 0 4px;
position: relative;
top: 3px;
vertical-align: top;
width: 14px;
}
.sp_plugin-button-2x {
background-image: url(https://fbstatic-a.akamaihd.net/rsrc.php/v2/y5/r/KxVPs0eEy36.png);
background-size: 30px 72px;
background-repeat: no-repeat;
display: inline-block;
height: 14px;
width: 14px;
}
.sx_plugin-button-2x_favblue {
background-position: 0 -42px;
}
i.img {
-ms-high-contrast-adjust: none;
_overflow: hidden;
}
}
.pluginButtonLabel {
padding: 0 5px 0 0;
position: relative;
vertical-align: top;
}
}
}
.facebookCount{
display: inline-block;
width: auto;
.pluginCountButton {
background: white;
border: 1px solid #bbb;
border-radius: 3px;
color: #6a7180;
display: inline-block;
font-size: 11px;
height: auto;
line-height: 18px;
margin-left: 6px;
min-width: 15px;
padding: 0 3px;
text-align: center;
white-space: nowrap;
span{
display: inline-block;
min-height:12px;
min-width:4px;
color:#333;
}
}
.pluginCountButtonNub {
height: 0;
left: 2px;
position: relative;
top: -15px;
width: 5px;
z-index: 2;
s,
i {
border-color: transparent #bbb;
border-style: solid;
border-width: 4px 5px 4px 0;
display: block;
position: relative;
top: 1px;
}
i {
border-right-color: #fff;
left: 2px;
top: -7px;
}
}
}
}
@-moz-document url-prefix() {
.facebookShare .facebookButton .pluginButton button .pluginButtonIcon{
margin:0 1px;
}
}
.linkedinShare{
line-height: 1;
vertical-align: baseline;
display: inline-block;
text-align: center;
width: auto;
padding:0;
margin: 0;
position: relative;
border:0;
text-decoration: none;
height:20px;
cursor: pointer;
&:hover .linkedinButton .pluginButtonLabel,
&:active .linkedinButton .pluginButtonLabel,
&:focus .linkedinButton .pluginButtonLabel{
border: 1px solid #000;
border-top-color: #ABABAB;
border-right-color: #9A9A9A;
border-bottom-color: #787878;
border-left-color: #04568B;
border-left: 0;
background: #ededed;
background: -moz-linear-gradient(top, #ededed 0%, #dedede 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ededed), color-stop(100%,#dedede));
background: -webkit-linear-gradient(top, #ededed 0%,#dedede 100%);
background: -o-linear-gradient(top, #ededed 0%,#dedede 100%);
background: -ms-linear-gradient(top, #ededed 0%,#dedede 100%);
background: linear-gradient(to bottom, #ededed 0%,#dedede 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ededed', endColorstr='#dedede',GradientType=0 );
}
.linkedinButton{
display: inline-block;
width: 59px;
height:20px;
padding: 0;
margin: 0;
.pluginButtonImage{
background-image: url(https://www.linkedin.com/scds/common/u/images/apps/connect/sprites/sprite_connect_v14.png);
background-position: 0px -276px;
background-repeat: no-repeat;
cursor: pointer;
border: 0;
text-indent: -9999em;
overflow: hidden;
padding: 0;
margin: 0;
position: absolute;
left: 0px;
top: 0px;
display: block;
width: 20px;
height: 20px;
border-radius: 2px;
color: #069;
}
.pluginButtonLabel{
color: #333;
cursor: pointer;
display: block;
white-space: nowrap;
float: left;
margin-left: 1px;
overflow: hidden;
text-align: center;
height: 18px;
padding: 0 4px 0 23px;
border: 1px solid #000;
border-top-color: #E2E2E2;
border-right-color: #BFBFBF;
border-bottom-color: #B9B9B9;
border-left-color: #E2E2E2;
border-left: 0;
text-shadow: #FFFFFF -1px 1px 0;
line-height: 20px;
border-radius: 2px;
background-color: #ECECEC;
background: -moz-linear-gradient(top, #fefefe 0%, #ececec 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fefefe), color-stop(100%,#ececec));
background: -webkit-linear-gradient(top, #fefefe 0%,#ececec 100%);
background: -o-linear-gradient(top, #fefefe 0%,#ececec 100%);
background: -ms-linear-gradient(top, #fefefe 0%,#ececec 100%);
background: linear-gradient(to bottom, #fefefe 0%,#ececec 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefefe', endColorstr='#ececec',GradientType=0 );
span{
color: #333;
font-size: 11px;
font-family: Arial, sans-serif;
font-weight: bold;
font-style: normal;
-webkit-font-smoothing: antialiased;
display: inline-block;
background: transparent none;
vertical-align: top;
height: 18px;
line-height: 20px;
float: none;
}
}
}
.linkedinCount{
padding: 0px;
margin: 0px;
text-indent: 0px;
display: inline-block;
vertical-align: baseline;
.pluginCountButton{
display: inline-block;
overflow: visible;
position: relative;
height: 18px;
padding-left: 2px;
.pluginCountButtonRight{
display: block;
float: left;
height: 18px;
padding-right: 4px;
background-image: url(https://www.linkedin.com/scds/common/u/images/apps/connect/sprites/sprite_connect_v14.png);
background-color: transparent;
background-repeat: no-repeat;
background-position: right -100px;
.pluginCountButtonLeft{
display: block;
float: left;
padding-left: 8px;
text-align: center;
background-image: url(https://www.linkedin.com/scds/common/u/images/apps/connect/sprites/sprite_connect_v14.png);
background-color: transparent;
background-repeat: no-repeat;
background-position: 0px -60px;
span{
display: inline;
font-size: 11px;
color: #04558B;
font-weight: bold;
font-family: Arial, sans-serif;
line-height: 18px;
padding: 0 2px;
}
}
}
}
}
}
================================================
FILE: bower.json
================================================
{
"name": "angular-socialshare",
"main": [
"angular-socialshare.js",
"angular-socialshare.css",
"angular-socialshare.less"
],
"version": "1.4.4",
"authors": [
"djds4rce