Skip to content

Commit

Permalink
Feature/resolve issue with minified css (#16) (#18)
Browse files Browse the repository at this point in the history
* Resolve issue that append with minified css

* Resolve issue with minified css and update copyright.

---------

Co-authored-by: Nathan Marcy <>
  • Loading branch information
nmarcy-del authored Jan 4, 2024
1 parent ef0f438 commit 8ab72ce
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/Field/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/

namespace Del001\AdminUiColorSwap\Block\Adminhtml\System\Config\Form\Field;
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/

namespace Del001\AdminUiColorSwap\Block\Adminhtml;
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/

namespace Del001\AdminUiColorSwap\Helper;
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/

namespace Del001\AdminUiColorSwap\Model\Config\Source;
Expand Down
5 changes: 5 additions & 0 deletions Test/Unit/Block/Adminhtml/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public function testGetCustomFontSecondaryColor(): void
{
$this->assertNull($this->theme->getCustomFontSecondaryColor());
}

public function testIsCssMinified(): void
{
$this->assertNull($this->theme->isCssMinified());
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "del001/admin-ui-color-swap",
"description": "A Magento 2 module to swap the admin UI colors",
"type": "magento2-module",
"version": "1.0.4",
"version": "1.0.5",
"license": [
"proprietary"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
2 changes: 1 addition & 1 deletion registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @category Admin
* @package Del001_AdminUiColorSwap
* @author https://github.com/nmarcy-del
* @copyright Copyright (c) 2023 https://github.com/nmarcy-del
* @copyright Copyright (c) 2024 https://github.com/nmarcy-del
*/

\Magento\Framework\Component\ComponentRegistrar::register(
Expand Down
36 changes: 28 additions & 8 deletions view/adminhtml/templates/theme.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ $fontMain = $escaper->escapeHtml($block->getCustomFontMainColor());
$fontSecondary = $escaper->escapeHtml($block->getCustomFontSecondaryColor());
?>
<script>
const loadCss = (url) => {
let linkElement = document.createElement('link')
linkElement.rel = 'stylesheet';
linkElement.type = 'text/css';
linkElement.href = url;
document.getElementsByTagName('head')[0].appendChild(linkElement);
}

// check if module is enabled
if ('<?= $escaper->escapeHtml($isEnabled) ?>' === '1') {
// Get default filename according to environment or get forced one
Expand All @@ -38,22 +46,34 @@ $fontSecondary = $escaper->escapeHtml($block->getCustomFontSecondaryColor());
cssFilename = '<?= $escaper->escapeHtml($selectedTheme) ?>'
}
}

if ('<?= $escaper->escapeHtml($block->isUsedCustomTheme())?>' === '1') {
cssFilename = 'custom_admin'
}

if (cssFilename) {
// load css stylesheet according to environment
let linkElement = document.createElement('link')
linkElement.rel = 'stylesheet';
linkElement.type = 'text/css';
linkElement.href = '<?= $escaper->escapeHtml($cssPath) ?>' + '/' + cssFilename + '.css'
document.getElementsByTagName('head')[0].appendChild(linkElement);
let generalUrl = '<?= $escaper->escapeHtml($cssPath) ?>' + '/' + cssFilename;

let cssUrl = generalUrl + '.css';
let cssMinifiedUrl = generalUrl + '.min.css';

fetch(cssUrl, { method: 'HEAD' }).then(function(response) {
if (response.ok) {
loadCss(cssUrl);
} else {
loadCss(cssMinifiedUrl);
}
}).catch(function(error) {
loadCss(cssMinifiedUrl);
});
}

if (cssFilename === 'custom_admin') {
// get the root element
let root = document.querySelector(':root');
// get the root element
let root = document.querySelector(':root');

let themeMain = '<?= $escaper->escapeHtml($mainColor) ?>'
let themeMain = '<?= $escaper->escapeHtml($mainColor) ?>'
if (themeMain) {
root.style.setProperty('--primarycolor', themeMain);
}
Expand Down

0 comments on commit 8ab72ce

Please sign in to comment.