generated from dynamikaweb/yii2-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14f6066
commit 23219ee
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} |