Scripts.php
1.61 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace ACP\Table;
use AC\Asset;
use AC\Asset\Style;
use AC\ColumnSize;
use AC\ListScreen;
use AC\ListScreenRepository\Storage;
use AC\Registerable;
use ACP\Asset\Script\Table;
use ACP\Search\SegmentRepository;
class Scripts implements Registerable
{
private $location;
private $user_storage;
private $list_storage;
private $storage;
private $segment_repository;
public function __construct(
Asset\Location\Absolute $location,
ColumnSize\UserStorage $user_storage,
ColumnSize\ListStorage $list_storage,
Storage $storage,
SegmentRepository $segment_repository
) {
$this->location = $location;
$this->user_storage = $user_storage;
$this->list_storage = $list_storage;
$this->storage = $storage;
$this->segment_repository = $segment_repository;
}
public function register(): void
{
add_action('ac/table_scripts', [$this, 'scripts']);
}
public function scripts(ListScreen $list_screen): void
{
if ( ! $list_screen->has_id()) {
return;
}
$assets = [
new Style('acp-table', $this->location->with_suffix('assets/core/css/table.css')),
new Table(
$this->location->with_suffix('assets/core/js/table.js'),
$list_screen,
$this->segment_repository,
$this->user_storage,
$this->list_storage,
$this->storage
),
];
foreach ($assets as $asset) {
$asset->enqueue();
}
}
}