Coder Social home page Coder Social logo

zacharyprice / simplejscopy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryanpcmcquen/cheval

0.0 2.0 0.0 33 KB

:clipboard: A super small (~1kB) JS library for copying to the clipboard or selecting text and prompting the user. A full solution for all browsers and all devices.

Home Page: https://ryanpcmcquen.org/simpleJsCopy/

License: GNU General Public License v2.0

HTML 12.28% JavaScript 87.72%

simplejscopy's Introduction

simpleJsCopy ๐Ÿ“‹

Just include the library (v0.2.3, ~1kB!):

<script src="https://cdn.rawgit.com/ryanpcmcquen/simpleJsCopy/3639e551f1fb1b93821c70856dacce5f2318c37d/simpleJsCopy.min.js"></script>

https://cdn.rawgit.com/ryanpcmcquen/simpleJsCopy/3639e551f1fb1b93821c70856dacce5f2318c37d/simpleJsCopy.min.js

Then use the following elements:

  1. <textarea> with the class text-to-copy (can be readonly but not disabled)
  2. <button> with the class js-copy-btn

The library takes cares of the rest. :shipit:

๐Ÿ“ฐ You don't have to write any JavaScript to use it!

=====

So what?! Where does it work?

Almost everywhere!

Desktop:

  • Chrome/Chromium 42+
  • Firefox 41+
  • Internet Explorer 9+
  • Opera 29+

Android:

  • Chrome 42+
  • Firefox 41+
What about other browsers?

Everywhere else (meaning iOS), it will select the text. The library detects iDevices and will change the inital button text to Select text (to avoid confusing the user). After clicking it will say either Now tap 'Copy' (iPhone) or Now tap the text, then 'Copy' (iPad), to account for the strange behavioral differences of these devices.

On desktop Safari (any version), the button will change to Press Command + C to copy.

On failure the button will say Please copy manually.

=====

โš ๏ธ If you want your textarea to be invisible for some reason, use this CSS:

.text-to-copy {
  opacity: 0;
  position: absolute;
}

Because it will not work with display: none; or visibility: hidden;. ๐Ÿ‘

Note that you should also supplement that CSS with something like this helper library, otherwise people on iOS will not be able to copy at all since Safari doesn't support cool stuff:

https://gist.github.com/ryanpcmcquen/1229119ffcf5098543c0

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.