Commit 6f2bd698 authored by Ad Schellevis's avatar Ad Schellevis

(theme) add support for custom theme.js hook

parent d82608e1
...@@ -41,6 +41,12 @@ $di->set('view', function () use ($config) { ...@@ -41,6 +41,12 @@ $di->set('view', function () use ($config) {
'compiledPath' => $config->application->cacheDir, 'compiledPath' => $config->application->cacheDir,
'compiledSeparator' => '_' 'compiledSeparator' => '_'
)); ));
// register additional volt template functions
$volt->getCompiler()->addFunction('javascript_include_when_exists', function($local_url) {
$chk_path = "str_replace('/ui/','/usr/local/opnsense/www/',".$local_url.")";
$js_tag = "'<script type=\"text/javascript\" src=\"'.$local_url.'\"></script>'";
return "file_exists(".$chk_path.") ? ".$js_tag." :''";
});
return $volt; return $volt;
}, },
......
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>{{title|default("OPNsense") }}</title> <title>{{title|default("OPNsense") }}</title>
{% set theme_name = ui_theme|default('opnsense') %}
<!-- include (theme) style --> <!-- include (theme) style -->
<link href="/ui/themes/{{ui_theme|default('opnsense')}}/build/css/main.css" rel="stylesheet"> <link href="/ui/themes/{{theme_name}}/build/css/main.css" rel="stylesheet">
<!-- TODO: move to theme style --> <!-- TODO: move to theme style -->
<style> <style>
...@@ -30,13 +31,13 @@ ...@@ -30,13 +31,13 @@
</style> </style>
<!-- Favicon --> <!-- Favicon -->
<link href="/ui/themes/{{ui_theme|default('opnsense')}}/build/images/favicon.png" rel="shortcut icon"> <link href="/ui/themes/{{theme_name}}/build/images/favicon.png" rel="shortcut icon">
<!-- Stylesheet for fancy select/dropdown --> <!-- Stylesheet for fancy select/dropdown -->
<link rel="stylesheet" type="text/css" href="/ui/themes/{{ui_theme|default('opnsense')}}/build/css/bootstrap-select.css"> <link rel="stylesheet" type="text/css" href="/ui/themes/{{theme_name}}/build/css/bootstrap-select.css">
<!-- bootstrap dialog --> <!-- bootstrap dialog -->
<link href="/ui/themes/{{ui_theme|default('opnsense')}}/build/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" /> <link href="/ui/themes/{{theme_name}}/build/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
<!-- Font awesome --> <!-- Font awesome -->
<link rel="stylesheet" href="/ui/css/font-awesome.min.css"> <link rel="stylesheet" href="/ui/css/font-awesome.min.css">
...@@ -179,6 +180,7 @@ ...@@ -179,6 +180,7 @@
<script type="text/javascript" src="/ui/js/opnsense.js"></script> <script type="text/javascript" src="/ui/js/opnsense.js"></script>
<script type="text/javascript" src="/ui/js/opnsense_ui.js"></script> <script type="text/javascript" src="/ui/js/opnsense_ui.js"></script>
<script type="text/javascript" src="/ui/js/opnsense_bootgrid_plugin.js"></script> <script type="text/javascript" src="/ui/js/opnsense_bootgrid_plugin.js"></script>
{{javascript_include_when_exists('/ui/themes/' ~ theme_name ~ '/build/js/theme.js')}}
</head> </head>
<body> <body>
...@@ -187,8 +189,8 @@ ...@@ -187,8 +189,8 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="/"> <a class="navbar-brand" href="/">
<img class="brand-logo" src="/ui/themes/{{ui_theme|default('opnsense')}}/build/images/default-logo.png" height="30" alt="logo"/> <img class="brand-logo" src="/ui/themes/{{theme_name}}/build/images/default-logo.png" height="30" alt="logo"/>
<img class="brand-icon" src="/ui/themes/{{ui_theme|default('opnsense')}}/build/images/icon-logo.png" height="30" alt="icon"/> <img class="brand-icon" src="/ui/themes/{{theme_name}}/build/images/icon-logo.png" height="30" alt="icon"/>
</a> </a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
......
...@@ -237,4 +237,9 @@ $pagetitle .= sprintf(' | %s.%s', $config['system']['hostname'], $config['system ...@@ -237,4 +237,9 @@ $pagetitle .= sprintf(' | %s.%s', $config['system']['hostname'], $config['system
}); });
//]]> //]]>
</script> </script>
<?php
if (file_exists("/usr/local/opnsense/www/themes/".$themename."/build/js/theme.js")):?>
<script type="text/javascript" src="/ui/themes/<?=$themename?>/build/js/theme.js"></script>
<?php
endif;?>
</head> </head>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment