Add all files
This commit is contained in:
50
extensions/Others/ForceTheme/ForceTheme.php
Normal file
50
extensions/Others/ForceTheme/ForceTheme.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\ForceTheme;
|
||||
|
||||
use App\Classes\Extension\Extension;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class ForceTheme extends Extension
|
||||
{
|
||||
public function getConfig($values = [])
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => 'mode',
|
||||
'label' => 'Theme Mode',
|
||||
'type' => 'select',
|
||||
'options' => ['light' => 'Light', 'dark' => 'Dark'],
|
||||
'default' => 'light',
|
||||
'required' => true,
|
||||
'validation' => 'in:light,dark',
|
||||
],
|
||||
[
|
||||
'name' => 'local_storage_key',
|
||||
'label' => 'Local Storage Key',
|
||||
'type' => 'text',
|
||||
'default' => '_x_darkMode',
|
||||
'required' => true,
|
||||
'validation' => 'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
View::prependLocation(__DIR__ . '/resources/views/overrides');
|
||||
|
||||
Event::listen('head', function () {
|
||||
$mode = $this->config('mode') ?: 'light';
|
||||
$key = $this->config('local_storage_key') ?: '_x_darkMode';
|
||||
$modeJs = e($mode);
|
||||
$keyJs = e($key);
|
||||
$script = "<script>(function(){try{var m='" . $modeJs . "';var k='" . $keyJs . "';var def='_x_darkMode';var v=(m==='dark')?'true':'false';localStorage.setItem(k, v);if(k!==def){localStorage.setItem(def, v);} }catch(e){}})();</script>";
|
||||
return ['view' => new HtmlString($script)];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user