Skip to content

Commit 4fced22

Browse files
Add cdn, popperjs. (#4)
1 parent 9e05ff7 commit 4fced22

9 files changed

+301
-31
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,51 @@ BootstrapAsset::register($this);
6565

6666
declare(strict_types=1);
6767

68+
use Yii2\Asset\BootstrapCdnAsset;
69+
70+
BootstrapCdnAsset::register($this);
71+
```
72+
73+
```php
74+
<?php
75+
76+
declare(strict_types=1);
77+
6878
use Yii2\Asset\BootstrapPluginAsset;
6979

7080
BootstrapPluginAsset::register($this);
7181
```
7282

83+
```php
84+
<?php
85+
86+
declare(strict_types=1);
87+
88+
use Yii2\Asset\BootstrapPluginCdnAsset;
89+
90+
BootstrapPluginCdnAsset::register($this);
91+
```
92+
93+
```php
94+
<?php
95+
96+
declare(strict_types=1);
97+
98+
use Yii2\Asset\PopperAsset;
99+
100+
PopperAsset::register($this);
101+
```
102+
103+
```php
104+
<?php
105+
106+
declare(strict_types=1);
107+
108+
use Yii2\Asset\PopperCdnAsset;
109+
110+
PopperCdnAsset::register($this);
111+
```
112+
73113
## Testing
74114

75115
[Check the documentation testing](/docs/testing.md) to learn about testing.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"require": {
1414
"php": ">=8.1",
1515
"npm-asset/bootstrap": "^5.3",
16+
"npm-asset/popperjs--core": "^2.11",
1617
"oomphinc/composer-installers-extender": "^2.0",
1718
"yiisoft/yii2": "^2.2"
1819
},

src/BootstrapAsset.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public function init(): void
2121
parent::init();
2222

2323
$assetBootstrap = YII_ENV === 'prod'
24-
? ['bootstrap.min.css', 'bootstrap.min.css.map']
25-
: ['bootstrap.css', 'bootstrap.css.map'];
24+
? ['bootstrap.min.css', 'bootstrap.min.css.map'] : ['bootstrap.css', 'bootstrap.css.map'];
2625

2726
$this->css = $assetBootstrap;
2827
$this->publishOptions['only'] = $assetBootstrap;

src/BootstrapCdnAsset.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yii2\Asset;
6+
7+
use yii\web\AssetBundle;
8+
9+
/**
10+
* Twitter Bootstrap 5 CDN CSS bundle.
11+
*/
12+
final class BootstrapCdnAsset extends AssetBundle
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public $css = [
18+
'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
19+
];
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public $cssOptions = [
25+
'crossorigin' => 'anonymous',
26+
'integrity' => 'sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN',
27+
'rel' => 'stylesheet',
28+
];
29+
}

src/BootstrapPluginAsset.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public function init(): void
2828
parent::init();
2929

3030
$assetBootstrapPlugin = YII_ENV === 'prod'
31-
? ['bootstrap.bundle.min.js', 'bootstrap.bundle.min.js.map']
32-
: ['bootstrap.bundle.js', 'bootstrap.bundle.js.map'];
31+
? ['bootstrap.bundle.min.js', 'bootstrap.bundle.min.js.map'] : ['bootstrap.bundle.js', 'bootstrap.bundle.js.map'];
3332

3433
$this->js = $assetBootstrapPlugin;
3534
$this->publishOptions['only'] = $assetBootstrapPlugin;

src/BootstrapPluginCdnAsset.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yii2\Asset;
6+
7+
use yii\web\AssetBundle;
8+
9+
/**
10+
* Twitter Bootstrap 5 CDN JavaScript bundle.
11+
*/
12+
final class BootstrapPluginCdnAsset extends AssetBundle
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public $js = [
18+
'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js',
19+
];
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public $jsOptions = [
25+
'crossorigin' => 'anonymous',
26+
'integrity' => 'sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL',
27+
];
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public $depends = [
33+
BootstrapCdnAsset::class,
34+
];
35+
}

src/PopperAsset.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yii2\Asset;
6+
7+
use yii\web\AssetBundle;
8+
9+
/**
10+
* Popper JavaScript bundle.
11+
*/
12+
final class PopperAsset extends AssetBundle
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public $sourcePath = '@npm/popperjs--core/dist/umd';
18+
19+
public function init(): void
20+
{
21+
parent::init();
22+
23+
$assetPopper = YII_ENV === 'prod' ? ['popper.min.js', 'popper.min.js.map'] : ['popper.js', 'popper.js.map'];
24+
25+
$this->css = $assetPopper;
26+
$this->publishOptions['only'] = $assetPopper;
27+
}
28+
}

src/PopperCdnAsset.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yii2\Asset;
6+
7+
use yii\web\AssetBundle;
8+
9+
/**
10+
* Popper CDN JavaScript bundle.
11+
*/
12+
final class PopperCdnAsset extends AssetBundle
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public $js = [
18+
'https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js',
19+
];
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public $jsOptions = [
25+
'crossorigin' => 'anonymous',
26+
'integrity' => 'sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r',
27+
];
28+
}

0 commit comments

Comments
 (0)