1.0.1 • Published 5 years ago

copy-and-play v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Copy And Play

A customizable, cross platform and easy to use text copying library.

Demo

https://ivanhoe-dev.github.io/copy-and-play/

Installation

npm install copy-and-play

Usage

  1. Import your Jquery and cap.js itself

    <script src="http://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="cap.js"></script>
  2. As cap.js contains ES6 code, if you want to support old browsers and IE, please import 'cap-es5.js' instead (e.g. babel.js) before it

  3. Call cap.init() if you want to apply settings globally

  4. By calling cap.copy(selector,[settings]), a text will be copied.

Parameter NameTypeDescription
selectorJquery selector stringthe target to be copied
settings (optional)JSONthe settings apply to this copy action locally

Settings JSON

An example of the setting JSON:

{
    	input: {
            visible: false,
            type: INPUT.TEXTAREA
        },
        successMessage: {
            enable: true,
            text: 'Copied to clipboard',
            position: null,
            timeout: 1000
        },
        lineBreak: true,
        onReady: null,
        onSuccess: null
}

Settings Details

OptionTypeDescriptionDefault value
input.visiblebooleanThe visibility of HTML input after copiedfalse
input.typeenumThe HTML input type: INPUT.TEXT INPUT.TEXTAREAINPUT.TEXTAREA
successMessage.enablebooleanEnable of successfully copied messagetrue
successMessage.textstringContent of success messageCopied to clipboard
successMessage.positionJquery selector stringThe position of the success messagenull
successMessage.timeoutintegerThe milliseconds of disappearing the successmessage -1 : not disappear1000
lineBreakbooleanenable of remaining line break of the target texttrue
onReadyfunctioncallback before the copy action performnull
onSuccessfunctioncallback after the copy action performnull

Line Break

Line break can be remained and copied by the option lineBreak However, as it only supports with a textarea, if you want to support copying line break, the library will set the input type as textarea by itself

Browser Support

The library is compatible with Safari 11(IOS11), IE 11, Mozilla Firefox 65.0, Google chrome 72.0

Author

ivanhoe-dev 2019-03-20