Merge pull request #1750 from pavel-mironchik/script
Allow to use the script component with modules' custom scripts.
This commit is contained in:
commit
b77d9a01fc
@ -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)) {
|
||||
|
@ -15,4 +15,4 @@
|
||||
var document_taxes = {!! $taxes !!};
|
||||
</script>
|
||||
|
||||
<script src="{{ asset( $scriptFile . '?v=' . version('short')) }}"></script>
|
||||
<script src="{{ asset( $scriptFile . '?v=' . $version) }}"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user