Code Monkey home page Code Monkey logo

localjo / quotable-toolbar Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 2 MB

๐Ÿ“ข A library to add buttons to quotes and text selection that make it quick and easy for your readers to share quotes from your website.

Home Page: https://iamlocaljo.com/projects/quotable/

License: GNU General Public License v2.0

TypeScript 79.09% JavaScript 11.48% CSS 9.43%
quotes twitter popup sharing social-buttons social-media typescript preact text-selection

quotable-toolbar's Introduction

quotable-toolbar ๐Ÿ“ข

A library to add buttons to quotes and text selection that make it quick and easy for your readers to share quotes from your website.

Banner Image

NPM

Quotable is a TypeScript library (distributed as a browser bundle and an ES6 module) that allows you to easily add a contextual popup to your web page for sharing selected text and quotes on Twitter (and soon, other networks).

Quotable is also available as a WordPress plugin.

Install

yarn add quotable-toolbar

Usage

Assuming an html page with a structure similar to this;

<div id="blog-container">
  <p>...</p>
  <blockquote>...</blockquote>
  <blockquote class="is-quotable">...</blockquote>
  <blockquote class="not-quotable">...</blockquote>
  <p>...</p>
  <blockquote>
    <p>...</p>
    <p>...</p>
  </blockquote>
  <p>...</p>
</div>

You can activate Quotable like this;

import Quotable from 'quotable-toolbar';

window.addEventListener('DOMContentLoaded', () => {
  const quotableToolbar = new Quotable({
    selector: `#blog-container`, // Wrapping element to activate Quotable on
    isActive: {
      blockquotes: true, // Whether to add Quotable links to blockquotes
      textSelection: true, // Whether to activate text selection popup
      include: ['.is-quotable'], // Blockquotes to always add links to
      exclude: ['.not-quotable'], // Blockquotes to never add links to
    },
    url: window.location.href, // URL to share, should be cannonical
    twitter: {
      via: 'JoFromAkron', // Twitter account to @
      related: 'JoFromAkron', // Twitter account to suggest after sharing
      hashtags: ['quotable', 'typescript'], // Hashtags to add to tweet
    },
  });
  quotableToolbar.activate();
});

Features

Quotable has two separate features you can activate, 1) add sharing links to blockquotes and 2) add a sharing link popup on text selection.

Blockquotes

Quotable will search for every blockquote in the container you select, and append a sharing link. If the blockquote contains paragraphs, the sharing link will be appended to each paragraph. Quotable also wraps the text content of the paragraph or blockquote with a span, used to highlight the text when the sharing link is hovered. You can also selectively add the sharing link to blockquotes by setting isActive.blockquotes: false and passing an array to include of selectors for elements you want to add sharing link to. Alternatively, you can selectively deactivate the sharing link when isActive.blockquotes: true by passing an array to exclude of selectors for the elements you don't want to add a sharing link to.

Screenshot

Text Selection

Quotable adds a popup for every text selection within the container you select. You can disable this with isActive.textSelection: false

Screenshot

Sharing Links

The url option determines which url will be shared, when the user clicks a sharing link. You can use window.location.href, but if that's not necessarily the canonical url you want people to share, you should set this manually with that value.

Right now, Quotable has support for a link to share content on Twitter. You can configure Twitter sharing options with the twitter options object. In the future, support will be added for other networks (Facebook, Reddit, Hacker News, etc), and each option will have it's own settings key in the options object.

Screenshot

quotable-toolbar's People

Contributors

localjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

quotable-toolbar's Issues

Add tests

This needs both unit tests and and browser tests

Add dark mode support

Right now, the style of the toolbar adapts well to light-mode themed websites, but I can make it more dynamic and add support for dark themed websites too.

Add support for other networks

Add support for sharing on:

  • Facebook
  • Reddit
  • Hackernews
  • Instagram (convert quote to sharable image?)
  • Others (feel free to comment with your suggestions)

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.