Skip to content

Commit

Permalink
Merge branch 'VladlenaCravcenco-dark-theme'
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Apr 29, 2024
2 parents 24c1249 + e83e14b commit e3367a2
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 30 deletions.
2 changes: 1 addition & 1 deletion example_dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<link rel="stylesheet" type="text/css" href="webassets/ermac.css" />
</head>
<body>

<script type="text/javascript">
// a very simple env loader
var to_load = [
Expand All @@ -17,6 +16,7 @@
'src_js/third_party/selectize.js',
'src_js/third_party/selectize_preserve_on_blur.js',
'src_js/third_party/optimade_mpds_nlp.js',
'src_js/third_party/darkmode.js',
'src_js/wmsettings.js',
'src_js/wmcore.js',
'src_js/sliders.js',
Expand Down
1 change: 0 additions & 1 deletion example_prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<link rel="stylesheet" type="text/css" href="webassets/ermac.css" />
</head>
<body>

<script type="text/javascript" src="ermac.min.js"></script>
</body>
</html>
28 changes: 26 additions & 2 deletions src_js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ function register_events(){
return false;
});*/

// Keys press
// keys press
$(document).keydown(function(e){
var key = window.event ? e.keyCode : e.which;
if (key == 13){ // ENTER: input must trigger submit button via two parent divs!
Expand All @@ -1471,8 +1471,8 @@ function register_events(){

$(window).bind('hashchange', url_redraw_react);

// execute a command in all the active GUI windows (except the current) e.g. setting a new state
$(window).bind('storage', function(ev){
// This is to execute the command in all the active GUI windows (except the current) e.g. setting a new state
if (ev.originalEvent.key != wmgui.store_comm_exec_key)
return;

Expand Down Expand Up @@ -1503,4 +1503,28 @@ function register_events(){
wmgui.ptable.subphases_set(state);
}
});

// theme switcher
document.getElementById('darkmode_trigger').onclick = function(){
wmgui.darkmode.toggle();
document.getElementById('darkmode_trigger').innerHTML = wmgui.darkmode.isActivated() ? 'enabled' : 'disabled';
document.getElementById('comms').contentWindow.postMessage(JSON.stringify({darkmode: wmgui.darkmode.isActivated() ? 1 : 2}), '*');
}

// cross-site comms
window.addEventListener('message', function(message){
//if (message.origin === 'https://trusted.com') {
var received;
try {
received = JSON.parse(message.data);
} catch (ignore){}
var darkmode = received.darkmode;
if (darkmode !== undefined){
darkmode = (darkmode === 1);
if (darkmode !== wmgui.darkmode.isActivated()) wmgui.darkmode.toggle();
document.getElementById('darkmode_trigger').innerHTML = wmgui.darkmode.isActivated() ? 'enabled' : 'disabled';
}
//}
});
// EOF register_events
}
18 changes: 11 additions & 7 deletions src_js/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ function register_html(){
<div id="pd_legend" class="sim_col_ctx">
<div class="col_title">Color legend</div>
<ul>
<li>liquid or gas <span style="color:#fff;background:#9cf;padding:2px;">blue or violet</span></li>
<li>1-phase <span style="color:#fff;background:#d1cde6;padding:2px;">violet</span></li>
<li>2-phase <span style="color:#fff;background:#ddd;padding:2px;">gray or white</span></li>
<li>3-phase <span style="color:#fff;background:#fc6;padding:2px;">yellow</span></li>
<li>4-phase <span style="color:#fff;background:#FCD3C2;padding:2px;">red</span></li>
<li>5-phase <span style="color:#fff;background:#CCE7D4;padding:2px;">green</span></li>
<li><span style="background:#9cf;">liquid or gas</span></li>
<li><span style="background:#d1cde6;">1-phase</span></li>
<li><span style="background:#ddd;">2-phase</span></li>
<li><span style="background:#fc6;">3-phase</span></li>
<li><span style="background:#FCD3C2;">4-phase</span></li>
<li><span style="background:#CCE7D4;">5-phase</span></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -837,6 +837,10 @@ function register_html(){
</div>
</div>
<div id="footer">Editor-in-Chief: Pierre Villars. Section editors: Karin Cenzual, Ihor Savysyuk, Riccarda Caputo. <a href="https://github.com/mpds-io">Open-source</a> development by <a href="https://tilde.pro" target="_blank">Tilde MI</a>.</div>
<div id="footer">Editor-in-Chief: P. Villars. Section editors: K. Cenzual, I. Savysyuk, R. Caputo. <a href="https://github.com/mpds-io">Open-source</a> development by <a href="https://tilde.pro" target="_blank">Tilde MI</a>. Dark mode is <span id="darkmode_trigger" style="border-bottom:1px solid #555;cursor:pointer;"></span>.</div>
<!-- CROSS-SITE COMMS -->
<iframe id="comms" src="https://absolidix.com/comms.html" style="width:0;height:0;border:none;position:absolute;"></iframe>
<!-- iframe id="comms" src="http://localhost:5000/comms.html" style="width:0;height:0;border:none;position:absolute;"></iframe -->
`);
}
3 changes: 3 additions & 0 deletions src_js/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ function satisfy_requirements(){
$('#engines_a').prop('checked', wmgui.engines == 'a');
$('#engines_b').prop('checked', wmgui.engines == 'b');

wmgui.darkmode = new Darkmode({saveInCookies: false});
document.getElementById('darkmode_trigger').innerHTML = wmgui.darkmode.isActivated() ? 'enabled' : 'disabled';

//create_floating_slider('density', 42, 'Mg/m<sup>3</sup>', 10, 900, 10);
// EOF satisfy_requirements
}
270 changes: 270 additions & 0 deletions src_js/third_party/darkmode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
/* https://github.com/sandoche/Darkmode.js */
!(function (e, t) {
'object' == typeof exports && 'object' == typeof module
? (module.exports = t())
: 'function' == typeof define && define.amd
? define('darkmode-js', [], t)
: 'object' == typeof exports
? (exports['darkmode-js'] = t())
: (e['darkmode-js'] = t());
})('undefined' != typeof self ? self : this, function () {
return (function (e) {
var t = {};
function n(o) {
if (t[o]) return t[o].exports;
var r = (t[o] = { i: o, l: !1, exports: {} });
return e[o].call(r.exports, r, r.exports, n), (r.l = !0), r.exports;
}
return (
(n.m = e),
(n.c = t),
(n.d = function (e, t, o) {
n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: o });
}),
(n.r = function (e) {
'undefined' != typeof Symbol &&
Symbol.toStringTag &&
Object.defineProperty(e, Symbol.toStringTag, { value: 'Module' }),
Object.defineProperty(e, '__esModule', { value: !0 });
}),
(n.t = function (e, t) {
if ((1 & t && (e = n(e)), 8 & t)) return e;
if (4 & t && 'object' == typeof e && e && e.__esModule) return e;
var o = Object.create(null);
if (
(n.r(o),
Object.defineProperty(o, 'default', { enumerable: !0, value: e }),
2 & t && 'string' != typeof e)
)
for (var r in e)
n.d(
o,
r,
function (t) {
return e[t];
}.bind(null, r)
);
return o;
}),
(n.n = function (e) {
var t =
e && e.__esModule
? function () {
return e.default;
}
: function () {
return e;
};
return n.d(t, 'a', t), t;
}),
(n.o = function (e, t) {
return Object.prototype.hasOwnProperty.call(e, t);
}),
(n.p = ''),
n((n.s = 0))
);
})([
function (e, t, n) {
'use strict';
Object.defineProperty(t, '__esModule', { value: !0 }), (t.default = void 0);
var o = (function (e) {
if (e && e.__esModule) return e;
var t = {};
if (null != e)
for (var n in e)
if (Object.prototype.hasOwnProperty.call(e, n)) {
var o =
Object.defineProperty && Object.getOwnPropertyDescriptor
? Object.getOwnPropertyDescriptor(e, n)
: {};
o.get || o.set ? Object.defineProperty(t, n, o) : (t[n] = e[n]);
}
return (t.default = e), t;
})(n(1));
var r = o.default;
(t.default = r),
o.IS_BROWSER &&
(function (e) {
e.Darkmode = o.default;
})(window),
(e.exports = t.default);
},
function (e, t, n) {
'use strict';
function o(e, t) {
for (var n = 0; n < t.length; n++) {
var o = t[n];
(o.enumerable = o.enumerable || !1),
(o.configurable = !0),
'value' in o && (o.writable = !0),
Object.defineProperty(e, o.key, o);
}
}
Object.defineProperty(t, '__esModule', { value: !0 }), (t.default = t.IS_BROWSER = void 0);
var r = 'undefined' != typeof window;
t.IS_BROWSER = r;
var a = (function () {
function e(t) {
if (
((function (e, t) {
if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function');
})(this, e),
r)
) {
t = Object.assign(
{},
{
bottom: '32px',
right: '32px',
left: 'unset',
time: '0.3s',
mixColor: '#fff',
backgroundColor: '#fff',
buttonColorDark: '#100f2c',
buttonColorLight: '#fff',
label: '',
saveInCookies: !0,
autoMatchOsTheme: !0
},
t
);
var n = '\n .darkmode-layer {\n position: fixed;\n pointer-events: none;\n background: '
.concat(t.mixColor, ';\n transition: all ')
.concat(
t.time,
' ease;\n mix-blend-mode: difference;\n }\n\n .darkmode-layer--button {\n width: 2.9rem;\n height: 2.9rem;\n border-radius: 50%;\n right: '
)
.concat(t.right, ';\n bottom: ')
.concat(t.bottom, ';\n left: ')
.concat(
t.left,
';\n }\n\n .darkmode-layer--simple {\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n transform: scale(1) !important;\n }\n\n .darkmode-layer--expanded {\n transform: scale(100);\n border-radius: 0;\n }\n\n .darkmode-layer--no-transition {\n transition: none;\n }\n\n .darkmode-toggle {\n background: '
)
.concat(
t.buttonColorDark,
';\n width: 3rem;\n height: 3rem;\n position: fixed;\n border-radius: 50%;\n border:none;\n right: '
)
.concat(t.right, ';\n bottom: ')
.concat(t.bottom, ';\n left: ')
.concat(
t.left,
';\n cursor: pointer;\n transition: all 0.5s ease;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n\n .darkmode-toggle--white {\n background: '
)
.concat(
t.buttonColorLight,
';\n }\n\n .darkmode-toggle--inactive {\n display: none;\n }\n\n .darkmode-background {\n background: '
)
.concat(
t.backgroundColor,
';\n position: fixed;\n pointer-events: none;\n z-index: -10;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n }\n\n img, .darkmode-ignore {\n isolation: isolate;\n display: inline-block;\n }\n\n @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {\n .darkmode-toggle {display: none !important}\n }\n\n @supports (-ms-ime-align:auto), (-ms-accelerator:true) {\n .darkmode-toggle {display: none !important}\n }\n '
),
o = document.createElement('div'),
a = document.createElement('button'),
i = document.createElement('div');
(a.innerHTML = t.label),
a.classList.add('darkmode-toggle--inactive'),
o.classList.add('darkmode-layer'),
i.classList.add('darkmode-background');
var d = 'true' === window.localStorage.getItem('darkmode'),
s = t.autoMatchOsTheme && window.matchMedia('(prefers-color-scheme: dark)').matches,
l = null === window.localStorage.getItem('darkmode');
((!0 === d && t.saveInCookies) || (l && s)) &&
(o.classList.add(
'darkmode-layer--expanded',
'darkmode-layer--simple',
'darkmode-layer--no-transition'
),
a.classList.add('darkmode-toggle--white'),
document.body.classList.add('darkmode--activated')),
document.body.insertBefore(a, document.body.firstChild),
document.body.insertBefore(o, document.body.firstChild),
document.body.insertBefore(i, document.body.firstChild),
this.addStyle(n),
(this.button = a),
(this.layer = o),
(this.saveInCookies = t.saveInCookies),
(this.time = t.time);
}
}
var t, n, a;
return (
(t = e),
(n = [
{
key: 'addStyle',
value: function (e) {
var t = document.createElement('link');
t.setAttribute('rel', 'stylesheet'),
t.setAttribute('type', 'text/css'),
t.setAttribute('href', 'data:text/css;charset=UTF-8,' + encodeURIComponent(e)),
document.head.appendChild(t);
}
},
{
key: 'showWidget',
value: function () {
var e = this;
if (r) {
var t = this.button,
n = this.layer,
o = 1e3 * parseFloat(this.time);
t.classList.add('darkmode-toggle'),
t.classList.remove('darkmode-toggle--inactive'),
t.setAttribute('aria-label', 'Activate dark mode'),
t.setAttribute('aria-checked', 'false'),
t.setAttribute('role', 'checkbox'),
n.classList.add('darkmode-layer--button'),
t.addEventListener('click', function () {
var r = e.isActivated();
r
? (n.classList.remove('darkmode-layer--simple'),
t.setAttribute('disabled', !0),
setTimeout(function () {
n.classList.remove('darkmode-layer--no-transition'),
n.classList.remove('darkmode-layer--expanded'),
t.removeAttribute('disabled');
}, 1))
: (n.classList.add('darkmode-layer--expanded'),
t.setAttribute('disabled', !0),
setTimeout(function () {
n.classList.add('darkmode-layer--no-transition'),
n.classList.add('darkmode-layer--simple'),
t.removeAttribute('disabled');
}, o)),
t.classList.toggle('darkmode-toggle--white'),
document.body.classList.toggle('darkmode--activated'),
window.localStorage.setItem('darkmode', !r);
});
}
}
},
{
key: 'toggle',
value: function () {
if (r) {
var e = this.layer,
t = this.isActivated(),
n = this.button;
e.classList.toggle('darkmode-layer--simple'),
document.body.classList.toggle('darkmode--activated'),
window.localStorage.setItem('darkmode', !t),
n.setAttribute('aria-label', 'De-activate dark mode'),
n.setAttribute('aria-checked', 'true');
}
}
},
{
key: 'isActivated',
value: function () {
return r ? document.body.classList.contains('darkmode--activated') : null;
}
}
]) && o(t.prototype, n),
a && o(t, a),
e
);
})();
t.default = a;
}
]);
});
1 change: 1 addition & 0 deletions src_js/wmsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ wmgui.cliff_counter = null;
wmgui.sid = null;
wmgui.oauths = null;
wmgui.prod = true; // (window.location.host.indexOf('localhost') == -1);
wmgui.darkmode = null;

wmgui.cliffhangers = [
"binary compounds with negative thermal expansion",
Expand Down
Loading

0 comments on commit e3367a2

Please sign in to comment.