grav/system/src/Grav/Common/Assets/InlineJsModule.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2022-01-09 21:29:40 +01:00
<?php
/**
* @package Grav\Common\Assets
*
2024-01-05 12:43:52 +01:00
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
2022-01-09 21:29:40 +01:00
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Assets;
use Grav\Common\Utils;
/**
* Class InlineJs
* @package Grav\Common\Assets
*/
2022-01-09 23:51:00 +01:00
class InlineJsModule extends BaseAsset
2022-01-09 21:29:40 +01:00
{
/**
* InlineJs constructor.
* @param array $elements
* @param string|null $key
*/
public function __construct(array $elements = [], ?string $key = null)
{
$base_options = [
'asset_type' => 'js_module',
'attributes' => ['type' => 'module'],
'position' => 'after'
];
$merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
parent::__construct($merged_attributes, $key);
}
2022-01-09 23:51:00 +01:00
/**
* @return string
*/
public function render()
{
return '<script' . $this->renderAttributes(). ">\n" . trim($this->asset) . "\n</script>\n";
}
2022-01-09 21:29:40 +01:00
}