Skip to content

Commit

Permalink
finish plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Aug 3, 2021
1 parent 14f6066 commit 23219ee
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"issues": "http://github.com/dynamikaweb/yii2-cookieconsent-widget/issues",
"source": "http://github.com/dynamikaweb/yii2-cookieconsent-widget"
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"require": {
"php": ">=7.0",
"yiisoft/yii2": "*",
Expand Down
44 changes: 44 additions & 0 deletions src/CookieConsent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace dynamikaweb\cookieconsent;

use yii\helpers\Json;

class CookieConsent extends \yii\base\Widget
{
const ASSET_TYPE_CDN = 1;
const ASSET_TYPE_LOCAL = 2;

public $pluginOptions;

public $assetType = self::ASSET_TYPE_LOCAL;

/**
* Registers the needed assets.
*
* @param View $view The View object
*/
public function registerAssets($view)
{
if($this->assetType == self::ASSET_TYPE_LOCAL) {
CookieConsentAsset::register($view);
} else {
CookieConsentAssetCDN::register($view);
}

$view->registerJs(strtr('window.cookieconsent.initialise({pluginOptions});', [
'{pluginOptions}' => Json::encode($this->pluginOptions),
]),
$view::POS_END
);
}

/**
* @return null
*/
public function run()
{
$this->registerAssets($this->getView());
return null;
}
}
16 changes: 16 additions & 0 deletions src/CookieConsentAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace dynamikaweb\cookieconsent;

class CookieConsentAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@npm/cookieconsent/build';

public $css = [
'cookieconsent.min.css',
];

public $js = [
'cookieconsent.min.js',
];
}
14 changes: 14 additions & 0 deletions src/CookieConsentAssetCDN.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace dynamikaweb\cookieconsent;

class CookieConsentAssetCDN extends \yii\web\AssetBundle
{
public $css = [
'//cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css',
];

public $js = [
'//cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js',
];
}

0 comments on commit 23219ee

Please sign in to comment.