Git Product home page Git Product logo

webclip's Introduction

WebClip

Plugable popup in browser. Inspired by PopClip and Medium

image

Demo

http://djyde.github.io/WebClip

Installtion

$ npm install webclip

Usage

import WebClip from 'webclip'
let webclip = new WebClip(document.querySelector('#your-container'))

const google = {
  name: 'Google',
  description: 'Search on Google',
  action(value) {
    // `value` is the selected content
    window.open(`https://www.google.com.hk/#safe=strict&q=${value}`)
  }
}

const bing = {
  name: 'Bing',
  description: 'Search on Bing',
  action(value) {
    window.open(`http://bing.com/search?q=${value}`)
  }
}

webclip.use([google, bing])

WebClip will pass the Range in action(). You can use it to do a lot, such as wrapping a highlight wrapper:

const highlight = {
  name: 'highlight',
  description: 'Highlight content',
  action(value, range) {
    const $highlight = document.createElement('span')
    $highlight.style.backgroundColor = 'rgba(92,255,160,.5)'
    // or just add a class
    // $highlight.classList.add('your-class')
    range.surroundContents($highlight)      
  }
}

webclip.use([highlight, google, bing])

You can config a font-awesome icon for a plugin, instead of the uppercase-first-character:

const highlight = {
  name: 'highlight',
  description: 'Highlight content',
  icon: 'pencil',
  action(value, range) {
    const $highlight = document.createElement('span')
    $highlight.style.backgroundColor = 'rgba(92,255,160,.5)'
    // or just add a class
    // $highlight.classList.add('your-class')
    range.surroundContents($highlight)      
  }
}

const remove = {
  name: 'remove',
  description: 'Remove content',
  icon: 'trash',
  action(value, range) {
    range.deleteContents()
  }
}

webclip.use([highlight, remove, google, bing])

License

MIT License

webclip's People

Contributors

djyde avatar

Stargazers

Mark avatar  avatar Tenvi avatar  avatar  avatar Ryzal Yusoff avatar Altair Wei avatar robot avatar Rahul Chowdhury avatar  avatar Titan avatar Andrew Burleson avatar dusunboy avatar Amine Al Kaderi avatar Jonathan Barratt avatar Jerzerak avatar Kevin Feng avatar  avatar David Danziger avatar buu avatar MR.LI /MR LEE avatar Kyle Dallafior avatar  avatar Misha Andreichenko avatar fxioi avatar  avatar Ze Chen avatar chardy avatar coval avatar  avatar michealzh avatar littlefan avatar Lento avatar Hady Mahmoud avatar Nikolay Kolev avatar Tom Planer avatar kanako avatar Pradeep Chauhan avatar H avatar Xiao Long avatar Wattana Ruengmucha avatar Kietil avatar Chew Chit Siang avatar Neal Shyam avatar Tang Weinan avatar Yuwei Sun avatar Giuem avatar Joe avatar Nyanpass avatar JustWPH avatar Montana Flynn avatar Aether avatar leo avatar Jacky Tang avatar Cloud Jiang avatar Timothy avatar Gitai avatar fanweiya avatar wangcong avatar  avatar Nguyen Trung Tin avatar ashfinal avatar 疾风Hua avatar LEON CHAN avatar Matthew Lee avatar 瓜牛 avatar Eric Liu avatar lifecolorist avatar Jeff Wen avatar Fan Bin avatar Robert Shaw avatar

Watchers

 avatar zhenizhui avatar  avatar

webclip's Issues

How to use with Browserify

I'm using Browserify to load webclip and build my js bundle. All is working, no errors but the action function is never called when text is selected. Can you provide any advice? Thanks in advance.

Here's my code:

"use strict";

var WebClip = require("webclip");
var clip;

module.exports = {
  //ui/share.js

  initialize: function() {
    var transcript = document.querySelector(".transcript");
    console.log("share init");

    //setup sharing feature
    if (transcript) {
      var search = {
        name: "Search",
        description: "Search this site",
        icon: "search",
        action: function(value) {
          location.href = "/search/?q=" + value;
        }
      };

      clip = new WebClip(transcript);
      clip.use(search);
    }
  }
};

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.