2.3.11 • Published 7 years ago

angular-socialshare v2.3.11

Weekly downloads
2,360
License
MIT
Repository
github
Last release
7 years ago

Angular Socialshare

Angular socialshare

Join the chat at https://gitter.im/720kb/angular-socialshare

Angular Socialshare is an angularjs directive for sharing urls and content on social networks such as (facebook, google+, twitter, pinterest and so on).

The Angular Socialshare is developed by 720kb.

Requirements

AngularJS v1.3+

Browser support

ChromeFirefoxIEOperaSafari
IE9 +

Load

To use the directive, include the angular socialshare's javascript file in your web page:

<!DOCTYPE HTML>
<html>
<body ng-app="app">
  //.....
  <script src="src/js/angular-socialshare.js"></script>
</body>
</html>

Installation

Bower

$ bower install angularjs-socialshare --save

npm

$ npm install angular-socialshare --save

then load it in your html

Add module dependency

Add the 720kb.socialshare module dependency

angular.module('app', [
  '720kb.socialshare'
 ]);

Call the directive wherever you want in your html page

<a href="#"
socialshare
socialshare-provider="twitter"
socialshare-text="720kb AngularJS Socialshare"
socialshare-hashtags="angularjs, angular-socialshare"
socialshare-url="http://720kb.net">
Share me
</a>

OR

Call the Socialshare service

  .controller('Ctrl', ['Socialshare', function testController(Socialshare) {

    Socialshare.share({
      'provider': 'facebook',
      'attrs': {
        'socialshareUrl': 'http://720kb.net'
      }
    });

Usage

Angular socialshare allows you to use sharing options via attribute data

Sharing Provider

You can set the social platform you want to share on using the socialshare-provider="" attribute.

Providers:

Please use them all in lowercase (socialshare-provider="delicious")

Doc

Facebook

(socialshare-provider="facebook")

As of April 2017 - If you want to share a photo and customize the previews you must use Open Graph Metas

simple sharer = Facebook simple share , share = Facebook Dialog Share, feed = Facebook Dialog Feed, send = Facebook Dialog Send

MethodOptionTypeDefaultDescription
share, feed, send, simple sharersocialshare-url=""page URLfalseSet the url/link to share
feed, send, sharesocialshare-type=""String('feed' or 'send' or 'share')simple sharerUse a simple sharer or Dialog Send or Dialog Share or Dialog Feed
feed, send, sharesocialshare-via=""StringfalseSet the FB APP ID value
feed, sendsocialshare-to=""StringfalseSet the to value
feedsocialshare-from=""StringfalseSet the from to value
feed, sendsocialshare-ref=""String('comma,separated')falseSet the ref value
feed, send, sharesocialshare-display=""String('popup')falseSet the display value
sharesocialshare-quote=""StringfalseSet the display text
sharesocialshare-hashtags=""StringfalseSet the display value along with # Eg:#facebook (one only hashtag)
feedsocialshare-source=""URLfalseSet the URL of a media file (either SWF or MP3) attached to this post
feed, sendsocialshare-redirect-uri=""URLfalseSet the redirect URI
sharesocialshare-mobileiframe=""booleanfalseIf set to true the share button will open the share dialog in an iframe on top of your website. This option is only available for mobile, not desktop.

Facebook Messenger

mobile only - (works only for <a> elements, it is a direct link)

(socialshare-provider="facebook-messenger")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share

Twitter

(socialshare-provider="twitter")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-via=""String('username')falseSet the via to share
sharersocialshare-hashtags=""String('hash,tag,hastag')falseSet the hashtags to share

Linkedin

(socialshare-provider="linkedin")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpageURLSet the url to share
sharersocialshare-text=""StringfalseSet the title value that you wish to use
sharersocialshare-description=""StringfalseSet the description value that you wish to use
sharersocialshare-source=""StringfalseSet the source of the content

Reddit

(socialshare-provider="reddit")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpageURLSet the url to share
sharersocialshare-text=""StringfalseSet the text content to share
sharersocialshare-subreddit=""String('technology')falseSet the subreddit to share on

Vk

(socialshare-provider="vk")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the title to share
sharersocialshare-description=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the image source to share

OK

(ok.ru)

(socialshare-provider="ok")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Digg

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

Delicious

(socialshare-provider="delicious")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

StumbleUpon

(socialshare-provider="stumbleupon")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

Pinterest

(socialshare-provider="pinterest")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

Google (Plus)

(socialshare-provider="google")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share

Tumblr

(socialshare-provider="tumblr")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

Buffer

(socialshare-provider="buffer")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share
sharersocialshare-via=""URLfalseSet the buffer via

Pocket

(socialshare-provider="pocket")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Flipboard

(socialshare-provider="flipboard")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Evernote

(socialshare-provider="evernote")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Hacker News

(socialshare-provider="hackernews")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Wordpress

(socialshare-provider="wordpress")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share

Xing

(socialshare-provider="xing")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-media=""URLfalseSet the media url to share
sharersocialshare-follow=""URLfalseSet the Xing page url which will be then suggested to you to follow

Whatsapp

mobile only - (works only for <a> elements, it is a direct link)

(socialshare-provider="whatsapp")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Telegram

(socialshare-provider="telegram")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Viber

mobile only - (works only for <a> elements, it is a direct link)

(socialshare-provider="viber")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Skype

(socialshare-provider="skype")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Email

(socialshare-provider="email")

MethodOptionTypeDefaultDescription
mailtosocialshare-subject=""StringfalseSet the subject for the email
mailtosocialshare-body=""StringfalseSet the body content for the email
mailtosocialshare-to=""StringfalseSet the Receiver / Receivers
mailtosocialshare-cc=""StringfalseSet the CC / CCs for the email
mailtosocialshare-bcc=""StringfalseSet the BCC / BCCs for the email

Sms

(works only for <a> elements, it is a direct link)

(socialshare-provider="sms")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share
sharersocialshare-to=""URLfalseSet the phone number of the contact

Weibo

(socialshare-provider="weibo")

MethodOptionTypeDefaultDescription
sharersocialshare-url=""URLpage URLSet the url to share
sharersocialshare-text=""StringfalseSet the content to share

Options

Sharing Popup Size

You can set a specific Height or Width for the sharing popup using the socialshare-popup-height="" and socialshare-popup-width="" attributes (sometimes, if if the popup is too small, it gets resized by third parties)

<a href="#"
socialshare
socialshare-provider="reddit"
socialshare-url="http://720kb.net"
socialshare-text="Sharing it!"
socialshare-popup-height="800"
socialshare-popup-width="800">
Share with a bigger popup
</a>

Sharing Event Trigger

You can choose to bind a different event trigger for showing up the sharer popup using the socialshare-trigger="" attribute (you can use any angular element.bind() event you want)

<a href="#"
socialshare
socialshare-provider="reddit"
socialshare-text="Sharing on mouseover"
socialshare-trigger="mouseover">
Share me when mouse is over
</a>

or a set of

<a href="#"
socialshare
socialshare-provider="reddit"
socialshare-text="Sharing on mouseover"
socialshare-trigger="focusout mouseleave">
Share me when focusout or mouseleave
</a>

Service

You may need to share from a controller (for example), this is how to use the Socialshare service:

  .controller('Ctrl', ['Socialshare', function testController(Socialshare) {

    Socialshare.share({
      'provider': 'facebook',
      'attrs': {
        'socialshareUrl': 'http://720kb.net'
      }
    });

    Socialshare.share({
      'provider': 'twitter',
      'attrs': {
        'socialshareUrl': 'http://720kb.net',
        'socialshareHashtags': '720kb, angular, socialshare'
      }
    });
    //every attrs must be in camel case as showed above
    //this will open the share popup immediately without any trigger event required

Some providers (specially mobile provider, such as: Viber, Whatsapp etc..) do not work with a Service call, because their API or Usage does not allow a trigger event on them

Globals

Provider setup

Sometimes you may need to set default values for all the sharing buttons, here is how to setup this:

.config(['socialshareConfProvider', function configApp(socialshareConfProvider) {

  socialshareConfProvider.configure([
    {
      'provider': 'twitter',
      'conf': {
        'url': 'http://720kb.net',
        'text': '720kb is enough',
        'via': 'npm',
        'hashtags': 'angularjs,socialshare,angular-socialshare',
        'trigger': 'click',
        'popupHeight': 800,
        'popupWidth' : 400
      }
    },
    {
      'provider': 'facebook',
      'conf': {
        'url': 'http://720kb.net',
        'trigger': 'mouseover',
        'popupHeight': 1300,
        'popupWidth' : 1000
      }
    }
  //and so on ...
  ]);
}]);

NB if you define the provider settings, but then you change the option value by html attributes, the html attribute value will be the final one (the one that will be used)

Live demo

Contributing

We will be much grateful if you help us making this project to grow up. Feel free to contribute by forking, opening issues, pull requests etc.

License

The MIT License (MIT)

Copyright (c) 2014 Filippo Oretti, Dario Andrei

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2.3.11

7 years ago

2.3.10

7 years ago

2.3.9

7 years ago

2.3.8

7 years ago

2.3.7

7 years ago

2.3.6

7 years ago

2.3.5

7 years ago

2.3.3

7 years ago

2.3.2

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.9

8 years ago

2.2.8

8 years ago

2.2.7

8 years ago

2.2.6

8 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.12

8 years ago

2.1.11

8 years ago

2.1.10

8 years ago

2.1.9

8 years ago

2.1.8

8 years ago

2.1.7

8 years ago

2.1.6

8 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

0.2.6-beta

8 years ago

0.2.5-beta

8 years ago

0.2.4-beta

8 years ago

0.2.3-beta

8 years ago

0.2.2-beta

8 years ago

0.2.1-beta

8 years ago

0.2.0-beta

8 years ago

0.1.20

8 years ago

0.1.19

8 years ago

0.1.18

8 years ago

0.1.17

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.14

9 years ago

0.1.13

9 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago