Completed
Push — master ( 442005...226d76 )
by Song
02:22
created

Copyable::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
use Encore\Admin\Facades\Admin;
6
7
/**
8
 * Class Copyable
9
 * @package Encore\Admin\Grid\Displayers
10
 *
11
 * @see https://codepen.io/shaikmaqsood/pen/XmydxJ
12
 */
13
class Copyable extends AbstractDisplayer
14
{
15
    protected function addScript()
16
    {
17
        $script = <<<SCRIPT
18
$('.grid-column-copyable').click(function (e) {
19
    
20
    var content = $(this).data('content');
21
    
22
    var \$temp = $('<input>');
23
    
24
    \$("body").append(\$temp);
25
    \$temp.val(content).select();
26
    document.execCommand("copy");
27
    \$temp.remove();
28
    
29
    $(this).tooltip('show');
30
});
31
SCRIPT;
32
33
        Admin::script($script);
34
    }
35
36
    public function display()
37
    {
38
        $this->addScript();
39
40
        $content = $this->getColumn()->getOriginal();
41
42
        return <<<HTML
43
<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="{$content}" title="Copied!" data-placement="bottom">
44
    <i class="fa fa-copy"></i>
45
</a>&nbsp;&nbsp;{$this->getValue()}
46
HTML;
47
    }
48
}