Giter Site home page Giter Site logo

asialiugf / copy-to-clipboard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sudodoki/copy-to-clipboard

0.0 0.0 0.0 75 KB

Copy stuff into clipboard from your browser using JS

Home Page: http://sudodoki.github.io/copy-to-clipboard/example/

License: MIT License

JavaScript 70.36% CSS 4.71% HTML 24.93%

copy-to-clipboard's Introduction

Copy to clipboard Build Status

Simple module exposing copy function that will try to use execCommand with fallback to IE-specific clipboardData interface and finally, resort to usual prompt with proper text content and message.

Example

import copy from 'copy-to-clipboard';

copy('Text');

// Copy with options
copy('Text', {
  debug: true,
  message: 'Press #{key} to copy',
});

API

copy(text: string, options: object): boolean — tries to copy text to clipboard. Returns true if no additional keystrokes were required from user (so, execCommand, IE's clipboardData worked) or false.

Value Default Notes
options.debug false Boolean. Optional. Enable output to console.
options.message Copy to clipboard: #{key}, Enter String. Optional. Prompt message. *
options.format "text/html" String. Optional. Set the MIME type of what you want to copy as. Use text/html to copy as HTML, text/plain to avoid inherited styles showing when pasted into rich text editor.
options.onCopy null function onCopy(clipboardData: object): void. Optional. Receives the clipboardData element for adding custom behavior such as additional formats

* all occurrences of #{key} are replaced with ⌘+C for macOS/iOS users, and Ctrl+C otherwise.

Works everywhere where prompt* is available. Works best (i.e. without additional keystrokes) in Chrome, FF, Safari 10+, and, supposedly, IE/Edge.

Note: does not work on some older iOS devices.
* – even though Safari 8 has prompt, you cannot specify prefilled content for prompt modal – thus it doesn't work as expected.

Installation

  • Can be used as npm package and then leveraged using commonjs bundler/loader:
npm i --save copy-to-clipboard
  • Can be utilized using wzrd.in. Add following script to your page:
<script src="https://wzrd.in/standalone/copy-to-clipboard@latest" async></script>

You will have window.copyToClipboard exposed for you to use.

UI components based on this package:

See also:

Running Tests

This project has some automated tests, that will run using nightwatch on top of selenium.

npm i
npm test

Typescript

This library has built-in Typescript definitions.

import * as copy from 'copy-to-clipboard';

copy-to-clipboard's People

Contributors

deniscarriere avatar evenchange4 avatar julienw avatar ljharb avatar mariusandra avatar martynaszilinskas avatar nkbt avatar phiggins avatar pugnascotia avatar shvaikalesh avatar sloanesturz avatar sudodoki avatar wdlb avatar zombiej avatar

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.