File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ $ ( document ) . ready ( function ( ) {
2
+ $ ( '[data-toggle="tooltip"]' ) . tooltip ( ) ;
3
+ } ) ;
4
+
5
+ $ ( '#clipboardTooltip' ) . tooltip ( { placement : 'bottom' , trigger : 'manual' } ) ;
6
+
1
7
$ ( '#short' ) . submit ( function ( event ) {
2
8
var urlText = $ ( '#urlField' ) . val ( ) ;
3
9
var config = {
@@ -8,8 +14,23 @@ $('#short').submit(function(event){
8
14
. then ( function ( response ) {
9
15
var shortUrl = response . data ;
10
16
$ ( '#shortUrl' ) . text ( shortUrl ) ;
17
+ $ ( '#clipboardTooltip' ) . tooltip ( 'hide' )
18
+ . attr ( 'data-original-title' , 'Copy to Clipboard' )
19
+ . tooltip ( 'show' ) ;
11
20
} )
12
21
. catch ( function ( error ) {
13
22
console . log ( error ) ;
14
23
} ) ;
15
24
} ) ;
25
+
26
+ function clipboardCopy ( ) {
27
+ var copyText = document . getElementById ( "shortUrl" ) . innerText ;
28
+ var $temp = $ ( "<input>" ) ;
29
+ $ ( "body" ) . append ( $temp ) ;
30
+ $temp . val ( copyText ) . select ( ) ;
31
+ document . execCommand ( "copy" ) ;
32
+ $temp . remove ( ) ;
33
+ $ ( '#clipboardTooltip' ) . tooltip ( 'hide' )
34
+ . attr ( 'data-original-title' , 'Link Copied!' )
35
+ . tooltip ( 'show' ) ;
36
+ }
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ <h5>SlashURL</h5>
31
31
< button type ="submit " class ="btn btn-primary "> Shorten It!</ button >
32
32
</ form >
33
33
< br >
34
- < i > < span id ="shortUrl "> </ span > </ i >
34
+ < i id =" clipboardTooltip " rel =" tooltip " data-original-title =" Copy to Clipboard " > < span onclick =" clipboardCopy() " id ="shortUrl "> </ span > </ i >
35
35
</ div >
36
36
</ div >
37
37
</ div >
You can’t perform that action at this time.
0 commit comments