File tree 5 files changed +149
-0
lines changed
5 files changed +149
-0
lines changed Original file line number Diff line number Diff line change
1
+ node_modules /*
Original file line number Diff line number Diff line change
1
+ # copy.js
2
+
3
+ copy-simple.js is a painless copy helper for JavaScript.
4
+
5
+ # Usage
6
+
7
+ There are different functions to copy values. All methods will return true or false;
8
+
9
+ ## import the library
10
+
11
+ ``` javascript
12
+ import copy from ' copy-simple' ;
13
+ ```
14
+
15
+ ## Copy Element Value - val()
16
+
17
+ ``` html
18
+ <input id =" testVal" type =" text" value =" Test 2-3-4" >
19
+ ```
20
+
21
+ ``` javascript
22
+ var copiedValue = copy (" #testVal" ).val ()
23
+ ```
24
+
25
+ ## Copy Element Text - text()
26
+
27
+ ``` html
28
+ <div id =" test" >Test Content</div >
29
+ ```
30
+
31
+ ``` javascript
32
+ var copiedText = copy (" #test" ).text ()
33
+ ```
34
+
35
+ ## Copy Element HTML - html()
36
+
37
+ ``` html
38
+ <div id =" test2" >Test Content2</div >
39
+ ```
40
+
41
+ ``` javascript
42
+ var copiedHtml = copy (" #test2" ).html ()
43
+ ```
44
+
45
+ ## Copy Current URL - url()
46
+
47
+ ``` javascript
48
+ var copiedUrl = copy ().url ()
49
+ ```
50
+
51
+ ## Copy Selected Text - selected()
52
+
53
+ ``` html
54
+ <div >My Text</div >
55
+ ```
56
+
57
+ ``` javascript
58
+ var copiedSelected = copy ().selected ()
59
+ ```
Original file line number Diff line number Diff line change
1
+ const copy = require ( './src/copy-simple' ) ;
2
+
3
+ module . exports = copy ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " copy-simple" ,
3
+ "version" : " 1.0.2" ,
4
+ "description" : " Painless copy helper for JavaScript" ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " "
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/aligoren/copy-simple.git"
12
+ },
13
+ "keywords" : [
14
+ " copy" ,
15
+ " copy" ,
16
+ " event" ,
17
+ " copy" ,
18
+ " selected" ,
19
+ " copy" ,
20
+ " text" ,
21
+ " copy" ,
22
+ " value" ,
23
+ " copy" ,
24
+ " html"
25
+ ],
26
+ "author" : " Ali GOREN" ,
27
+ "license" : " ISC" ,
28
+ "bugs" : {
29
+ "url" : " https://github.com/aligoren/copy-simple/issues"
30
+ },
31
+ "homepage" : " https://github.com/aligoren/copy-simple#readme"
32
+ }
Original file line number Diff line number Diff line change
1
+ function copy ( el ) {
2
+ var e = document . querySelector ( el ) ;
3
+
4
+ function saveClipBoard ( data ) {
5
+ var dummy = document . createElement ( 'input' ) ;
6
+ var text = data ;
7
+
8
+ document . body . appendChild ( dummy ) ;
9
+ dummy . value = text ;
10
+ dummy . select ( ) ;
11
+ var success = document . execCommand ( 'copy' ) ;
12
+ document . body . removeChild ( dummy ) ;
13
+
14
+ return success ;
15
+ }
16
+ function val ( ) {
17
+ var v = e . value
18
+ return saveClipBoard ( v )
19
+ }
20
+
21
+ function text ( ) {
22
+ var t = e . innerText
23
+
24
+ return saveClipBoard ( t )
25
+ }
26
+
27
+ function html ( ) {
28
+ var h = e . outerHTML
29
+
30
+ return saveClipBoard ( h )
31
+ }
32
+
33
+ function url ( ) {
34
+ var u = window . location . href
35
+
36
+ return saveClipBoard ( u )
37
+ }
38
+
39
+ function selected ( ) {
40
+ var s = window . getSelection ( ) . toString ( )
41
+
42
+ return saveClipBoard ( s )
43
+ }
44
+
45
+ return {
46
+ val : val ,
47
+ text : text ,
48
+ html : html ,
49
+ url : url ,
50
+ selected : selected
51
+ }
52
+ }
53
+
54
+ module . exports = copy
You can’t perform that action at this time.
0 commit comments