| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace Dcat\Admin\Grid\Displayers;
- use Dcat\Admin\Admin;
- /**
- * Class Copyable.
- *
- * @see https://codepen.io/shaikmaqsood/pen/XmydxJ
- */
- class Copyable extends AbstractDisplayer
- {
- protected function addScript()
- {
- $script = <<<'JS'
- $('.grid-column-copyable').off('click').on('click', 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');
- });
- JS;
- Admin::script($script);
- }
- public function display()
- {
- $this->addScript();
- $content = $this->column->getOriginal();
- $html = <<<HTML
- <a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="{$content}" title="Copied!" data-placement="bottom">
- <i class="fa fa-copy"></i>
- </a> {$this->value}
- HTML;
- return $this->value ? $html : '-';
- }
- }
|