share-dialog
Creates share dialogs for Facebook, Twitter, Pinterest, Google Plus, Tumblr and LinkedIn.
Install
npm i share-dialog --save
To use in a browser, browserify it.
Usage
See service methods below for specific service args.
var Dialog = // Example to share a link on Twittervar twitter = Dialog // Get the dialog URLvar url = twitter // Or open it in a new windowtwitter
Each of the service methods (e.g. Dialog.twitter
) returns a Dialog
instance. These instances are reusable:
var dialog = Dialogtumblrlink'http://example.com/' 'Some link' dialogdialogdialog
API
Dialog instances
dialog.params({ object }
)
Overwrite GET parameters of share URL.
dialog.params() Get current parameters.
dialog.config({ object }
)
Overwrite window configuration. The default configuration is:
toolbar: 0 status: 0 width: 650 // differs per service height: 306 { return screenavailHeight/2 - configheight/2 } { return screenavailWidth/2 - configwidth/2 }
dialog.config() Get current configuration.
dialog.get() Return the dialog URL.
dialog.open() Open the share dialog in a new window.
Service methods
The argument names listed for each service method below, are equal to the GET parameter names. This means..
Dialog
.. is the same as writing:
Dialog
Share dialog (facebook.com/dialog/share?app_id=..
)
Dialog.facebook(app_id, href, redirect_uri)
Legacy sharer.php (facebook.com/sharer/sharer.php?u=..
)
Dialog.facebook(u)
where u
is the URL to share. Does not require an app id.
Dialog.pinterest(url, media [, description])
Tumblr
Share a link:
Dialog.tumblr.link(url [, name, description])
Share a photo:
Dialog.tumblr.photo(source [, caption, clickthru])
Google Plus
Dialog.gplus(url)
Dialog.twitter(url [, text, via, in_reply_to, hashtags, related])
url
(string): the URL you want to share (required)text
(string): tweet text (optional)via
(string): username (optional)in_reply_to
(number or string): status ID of a tweet (optional)hashtags
(array): hashtags to append to tweet, e.g. ['food', 'monsters'] (optional)related
(array): related Twitter usernames (optional)
Dialog.linkedIn(url[, title, source, summary])
Todo
- testling browser tests