| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <?php
- namespace Dcat\Admin\Layout;
- class Assets
- {
- /**
- * @var array
- */
- protected $script = [];
- /**
- * @var array
- */
- protected $style = [];
- /**
- * @var array
- */
- protected $css = [];
- /**
- * @var array
- */
- protected $js = [];
- /**
- * @var array
- */
- protected $headerJs = [
- 'vendors' => 'dcat-admin/vendors/js/vendors.min.js',
- 'dcat' => 'dcat-admin/dcat/js/app.js',
- ];
- /**
- * @var array
- */
- protected $baseCss = [
- 'vendors' => 'dcat-admin/vendors/css/vendors.min.css',
- 'bootstrap' => 'dcat-admin/css/bootstrap.css',
- 'bootstrap-extended' => 'dcat-admin/css/bootstrap-extended.css',
- 'toastr' => 'dcat-admin/vendors/css/extensions/toastr.css',
- 'colors' => 'dcat-admin/css/colors.css',
- 'components' => 'dcat-admin/css/components.css',
- 'palette-gradient' => 'dcat-admin/css/core/colors/palette-gradient.css',
- //'custom' => 'dcat-admin/css/custom-laravel.css',
- 'dcat' => 'dcat-admin/dcat/css/app.css',
- ];
- /**
- * @var array
- */
- protected $baseJs = [
- 'menu' => 'dcat-admin/js/core/app-menu.js',
- 'app' => 'dcat-admin/js/core/app.js',
- 'toastr' => 'dcat-admin/vendors/js/extensions/toastr.min.js',
- 'pjax' => 'dcat-admin/plugins/jquery-pjax/jquery.pjax.min.js',
- 'layer' => 'dcat-admin/plugins/layer/layer.js',
- ];
- /**
- * @var array
- */
- public $components = [];
- /**
- * @var string
- */
- public $fonts = 'https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,800,800i,900,900i';
- /**
- * @var bool
- */
- protected $isPjax = false;
- /**
- * @var bool
- */
- protected $usingFullPage = false;
- /**
- * Assets constructor.
- */
- public function __construct()
- {
- $this->isPjax = request()->pjax();
- }
- public function full(bool $value = true)
- {
- $this->usingFullPage = $value;
- return $this;
- }
- public function collect(string $name)
- {
- $this->js($this->components[$name]['js'] ?? null);
- $this->css($this->components[$name]['css'] ?? null);
- }
- public function css($css)
- {
- if (! $css) {
- return;
- }
- $this->css = array_merge($this->css, (array) $css);
- }
- public function baseCss(array $css)
- {
- $this->baseCss = $css;
- }
- public function js($js)
- {
- if (! $js) {
- return;
- }
- $this->js = array_merge($this->js, (array) $js);
- }
- public function headerJs($js)
- {
- if (! $js) {
- return;
- }
- $this->headerJs = array_merge($this->headerJs, (array) $js);
- }
- public function baseJs(array $js)
- {
- if (! $js) {
- return;
- }
- $this->baseJs = $js;
- }
- public function script($script)
- {
- if (! $script) {
- return;
- }
- $this->script = array_merge($this->script, (array) $script);
- }
- public function style($style)
- {
- if (! $style) {
- return;
- }
- $this->style = array_merge($this->style, (array) $style);
- }
- protected function addLayoutCss()
- {
- if ($this->usingFullPage) {
- return;
- }
- if (config('admin.layout.main_layout_type') === 'horizontal') {
- $this->baseCss[] = 'dcat-admin/css/core/menu/menu-types/horizontal-menu.css';
- }
- $this->baseCss[] = 'dcat-admin/css/core/menu/menu-types/vertical-menu.css';
- }
- protected function addThemeCss()
- {
- if (! $theme = config('admin.layout.theme')) {
- return;
- }
- $this->baseCss[] = "dcat-admin/css/themes/{$theme}.css";
- }
- protected function addFontCss()
- {
- $this->fonts && ($this->baseCss[] = $this->fonts);
- }
- protected function mergeBaseCss()
- {
- if ($this->isPjax) {
- return;
- }
- $this->addLayoutCss();
- $this->addThemeCss();
- $this->addFontCss();
- $this->css = array_merge($this->baseCss, $this->css);
- }
- public function renderCss()
- {
- $this->mergeBaseCss();
- $html = '';
- foreach (array_unique($this->css) as &$v) {
- $v = admin_asset($v);
- $html .= "<link rel=\"stylesheet\" href=\"{$v}\">";
- }
- return $html;
- }
- protected function mergeBaseJs()
- {
- if ($this->isPjax) {
- return;
- }
- $this->js = array_merge($this->baseJs, $this->js);
- }
- public function renderJs()
- {
- $this->mergeBaseJs();
- $html = '';
- foreach (array_unique($this->js) as &$v) {
- $v = admin_asset($v);
- $html .= "<script src=\"$v\"></script>";
- }
- return $html;
- }
- public function renderHeaderJs()
- {
- $html = '';
- foreach (array_unique($this->headerJs) as &$v) {
- $v = admin_asset($v);
- $html .= "<script src=\"$v\"></script>";
- }
- return $html;
- }
- public function renderScript()
- {
- $script = implode(';', array_unique($this->script));
- return "<script data-exec-on-popstate>Dcat.ready(function () { {$script} });</script>";
- }
- public function renderStyle()
- {
- $style = implode('', array_unique($this->style));
- return "<style>$style</style>";
- }
- }
|