forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.go
43 lines (34 loc) · 917 Bytes
/
copy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package display
import (
"html/template"
"github.com/kotovmak/go-admin/template/types"
)
type Copyable struct {
types.BaseDisplayFnGenerator
}
func init() {
types.RegisterDisplayFnGenerator("copyable", new(Copyable))
}
func (c *Copyable) Get(args ...interface{}) types.FieldFilterFn {
return func(value types.FieldModel) interface{} {
return template.HTML(`
<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="` + value.Value + `"
title="Copied!" data-placement="bottom">
<i class="fa fa-copy"></i>
</a> ` + value.Value + `
`)
}
}
func (c *Copyable) JS() template.HTML {
return template.HTML(`
$('body').on('click','.grid-column-copyable',(function (e) {
var content = $(this).data('content');
var temp = $('<input>');
$("body").append(temp);
temp.val(content).select();
document.execCommand("copy");
temp.remove();
$(this).tooltip('show');
}));
`)
}