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

Copyable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addScript() 0 20 1
A display() 0 12 1
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
}