Merge pull request #1750 from pavel-mironchik/script

Allow to use the script component with modules' custom scripts.
This commit is contained in:
Cüneyt Şentürk 2021-01-12 17:46:16 +03:00 committed by GitHub
commit b77d9a01fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -15,6 +15,9 @@ class Script extends Component
/** @var string */
public $scriptFile;
/** @var string */
public $version;
public $items;
public $currencies;
@ -26,10 +29,11 @@ class Script extends Component
*
* @return void
*/
public function __construct(string $type = '', string $scriptFile = '', $items = [], $currencies = [], $taxes = [])
public function __construct(string $type = '', string $scriptFile = '', string $version = '', $items = [], $currencies = [], $taxes = [])
{
$this->type = $type;
$this->scriptFile = ($scriptFile) ? $scriptFile : 'public/js/common/documents.js';
$this->version = $this->getVersion($version);
$this->items = $items;
$this->currencies = $this->getCurrencies($currencies);
$this->taxes = $this->getTaxes($taxes);
@ -45,6 +49,19 @@ class Script extends Component
return view('components.documents.script');
}
protected function getVersion($version)
{
if (!empty($version)) {
return $version;
}
if ($alias = config('type.' . $this->type . '.alias')) {
return module_version($alias);
}
return version('short');
}
protected function getCurrencies($currencies)
{
if (!empty($currencies)) {

View File

@ -15,4 +15,4 @@
var document_taxes = {!! $taxes !!};
</script>
<script src="{{ asset( $scriptFile . '?v=' . version('short')) }}"></script>
<script src="{{ asset( $scriptFile . '?v=' . $version) }}"></script>