add hooks about loading assets
This commit is contained in:
parent
658a2d48f5
commit
7f966ce80d
@ -4,11 +4,9 @@ namespace App\Services;
|
||||
|
||||
use Event;
|
||||
use Closure;
|
||||
use App\Events;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Events\ConfigureRoutes;
|
||||
use App\Events\ConfigureUserMenu;
|
||||
use App\Events\ConfigureAdminMenu;
|
||||
|
||||
class Hook
|
||||
{
|
||||
@ -27,7 +25,7 @@ class Hook
|
||||
*/
|
||||
public static function addMenuItem($category, $position, array $menu)
|
||||
{
|
||||
$class = $category == "user" ? ConfigureUserMenu::class : ConfigureAdminMenu::class;
|
||||
$class = $category == "user" ? Events\ConfigureUserMenu::class : Events\ConfigureAdminMenu::class;
|
||||
|
||||
Event::listen($class, function ($event) use ($menu, $position, $category)
|
||||
{
|
||||
@ -55,9 +53,42 @@ class Hook
|
||||
*/
|
||||
public static function addRoute(Closure $callback)
|
||||
{
|
||||
Event::listen(ConfigureRoutes::class, function($event) use ($callback)
|
||||
Event::listen(Events\ConfigureRoutes::class, function($event) use ($callback)
|
||||
{
|
||||
return call_user_func($callback, $event->router);
|
||||
});
|
||||
}
|
||||
|
||||
public static function registerPluginTransScripts($id)
|
||||
{
|
||||
Event::listen(Events\RenderingFooter::class, function($event) use ($id)
|
||||
{
|
||||
$path = app('plugins')->getPlugin($id)->getPath().'/';
|
||||
$script = 'lang/'.config('app.locale').'/locale.js';
|
||||
|
||||
if (file_exists($path.$script)) {
|
||||
$event->addContent('<script src="'.plugin_assets($id, $script).'"></script>');
|
||||
}
|
||||
}, 999);
|
||||
}
|
||||
|
||||
public static function addStyleFileToPage($urls, $priority = 1)
|
||||
{
|
||||
Event::listen(Events\RenderingHeader::class, function($event) use ($urls)
|
||||
{
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<link rel=\"stylesheet\" href=\"$url\">");
|
||||
}
|
||||
}, $priority);
|
||||
}
|
||||
|
||||
public static function addScriptFileToPage($urls, $priority = 1)
|
||||
{
|
||||
Event::listen(Events\RenderingFooter::class, function($event) use ($urls)
|
||||
{
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<script src=\"$url\"></script>");
|
||||
}
|
||||
}, $priority);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user