Giter VIP home page Giter VIP logo

selection-sharer's Introduction

selection-sharer

Popover menu to share on Twitter or by email any text selected on the page with support for mobile devices (with a popunder).

selection sharer screenshot

How to add it to your site

This script requires jQuery so make sure you have it loaded on your page.

Add the stylesheet in the <head> of your page:

<link rel="stylesheet" href="dist/selection-sharer.css" />

and add the Javascript at the bottom of your page near the closing </body> tag:

<script src="dist/selection-sharer.js"></script>
<script>
$('p').selectionSharer();
</script>

If you want to add Facebook share, please make sure that your page has a Facebook App ID meta tag:

<meta property="fb:app_id" content="123456789" />

The url shared can be set using the og:url tag:

<meta property="og:url" content="http://your.url/to/share" />

Or if you are using requirejs, you can do:

require(["dist/selection-sharer"], function(SelectionSharer) {
  var sharer = new SelectionSharer();
  selectionSharer.setElements('p'); // bind mouseup event to all <p> elements
});

Or more simply:

require(["dist/selection-sharer!"]);

That's it.

For Webpack

Note : This package has a peer dependency on jQuery so it expects jQuery to already be available in your page or in your bundling step.

Without CSS bundling

var Selection = require('selection-sharer');
var selection = new Selection('p');

With CSS bundling

require('selection-sharer/dist/selection-sharer.css');
var Selection = require('selection-sharer');
var selection = new Selection('p');

For Browserify

var Selection = require('selection-sharer');
var selection = new Selection('p');

Note: Browserify does not do css bundling so you would have to resort to package like browserify-css

Please let me know if you install this script on your site. Just star this repo and ping me on Twitter @xdamman. Thank you!

Notes

  • Images are included inline in the CSS as SVG (perfect for Retina displays, loading time and to easily create new color schemes)
  • Total size gzipped minified: 3.5K (equally split between css and javascript)

Demos

There is a demos/ directory with some examples using jquery, requirejs or simple javascript.

You can also try it directly on my blog on http://xdamman.com.

Bookmarklet version

Add a new bookmark to your bookmark bar, edit its url and copy paste the following code:

javascript:(function(){var s=document.createElement('script');s.src="//xdamman.github.io/selection-sharer/lib/selection-sharer/dist/bookmarklet.js";document.body.appendChild(s);})()

Building

To recompile the minified versions of the css and javascript in the dist/ directory, simply run:

npm build

Other Builds

For Ruby On Rails applications you can use selection-sharer gem. We have a gem with selection-sharer js build and it is very easy to use. https://rubygems.org/gems/selection-sharer

gem 'selection-sharer'

Contribute

This is still early days so there is still a lot to do and I welcome contributions.

TODO:

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

selection-sharer's People

Contributors

ashishprajapati avatar byemke avatar clivewalkden avatar ishansharma avatar janrembold avatar jgrossi avatar kikobeats avatar omarlopesino avatar riaan-za avatar shri3k avatar wkirby avatar xdamman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selection-sharer's Issues

Remove "Quote from" and "From: " in email for better localization

For websites in languages other than English, or in multiple languages, these are the only two reminders that this plugin is strictly localized. I believe the email is still very understandable without these prefixes, especially if it's broken down into paragraphs ( #22 ).

Sharer not closing when losing focus

The sharer only closes if you click on a targeted element, not if the selection loses focus by clicking on an element that is not targeted by selection-sharer.

As a fix, I use:

if(!window.getSelection().length) {
    self.hide();
    return;
}

in this.selectionChanged, line 311, before checking self.isMobile.

Version tag, bower and npm

Last version tag is from 2 years - could you update it? Moreover, I can't install plugin with npm, because it doesn't find files in npm registry. I can install it with bower, but downloaded version is very old.

Include SASS/SCSS file with distribution

Would love to have a .scss file included so I can import into my projects. Currently I copy the .css file out and change the extension to .scss. Having the .scss included in the distribution ensures that I'm using the latest version.

Thanks!

How to make it work in IE

First of all, thank you for this module you made! It's wonderful. I wonder how to make it work in IE 9 please.

Thank you very much for your help!

Cheers

Facebook

Tried the new Facebook code, and even though I have og tags it still shows me the message: "This page does not have a valid Facebook Open Graph Meta tags". You've seen this happening as well?

Text translations

I would like to make the selection sharer translatable. Do you have any preferences about how this sould be done?

I actually need this feature for Drupal, where we must wrap the strings into the function Drupal.t().

To make the feature available also for other environments, I would suggest something like this:

if (typeof(selection_sharer_gettext) === 'undefined') {
    var selection_sharer_gettext = function (string) {
        return string;
    };
}

So, everyone using a translation framework can wrap it into this function.

Pull request for custom UTM params?

Would you accept a pull request for adding custom UTM parameters to this? I'm looking at adding this to a new blog through @jcvangent's wordpress plugin, and I could see that being a super useful feature.

Thanks!

[Feature] Custom messages

Add a possibility to use custom share texts for email (and subject!), twitter etc.
Only possibility to change it now is to modify plugin directly.

Share one word

The behaviour of Medium makes the popup appear when you select only one word. It's possible to adjust this plugin to do the same?

Thanks

Looking for new core maintainer

Sorry, haven't been following this project and I just realized it had all those stars (thank you!) and issues ¯_(ツ)_/¯

Happy to hand it over to someone else who would have the time to maintain it.

Let me know!

Line breaks in email

The email text doesn't contain any line break to separate the quote, the title and the URL. These should be separated by at least one blank line to ensure legibility.

Email link accessibility issue

The "Email" link has an SVG inside with no text value, nor does it have an aria-label attribute to it. This causes accessibility issues.

Proposed PR: #79

Workaround to get this working when placing scripts in the head of the page

Hello,

I am working on including your great script to an extension for a CMS.

This CMS allows me to add JS and CSS - but always to the heading of the page.

If I do $(function() {$('p').selectionSharer();}); the popover appears and lets me share via twitter and mail - but the script does not recognize the Facebook App tag.

As I can not hack the CMS, I have to find a workaround for this script.

Any help is highly appreciated.

Facebook

Don't show the select text to share. Show only the URL config on fb:ID and not the select text of page.

Thank you for the great tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.