-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change tinymce look based on browser theme
- Loading branch information
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Sets the dar/light mode based on the browser. | ||
// Copied minimal needed stuff from open-forms | ||
|
||
'use strict'; | ||
{ | ||
function initTinyMCE(el) { | ||
if (el.closest('.empty-form') === null) { | ||
// Don't do empty inlines | ||
var mce_conf = JSON.parse(el.dataset.mceConf); | ||
const useDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
|
||
mce_conf = { | ||
...mce_conf, | ||
...{ | ||
skin: useDarkMode ? 'oxide-dark' : 'oxide', | ||
content_css: useDarkMode ? 'dark' : 'default', | ||
}, | ||
}; | ||
|
||
const id = el.id; | ||
|
||
if (!tinyMCE.get(id)) { | ||
tinyMCE.init(mce_conf); | ||
} | ||
} | ||
} | ||
|
||
function ready(fn) { | ||
if (document.readyState !== 'loading') { | ||
fn(); | ||
} else { | ||
document.addEventListener('DOMContentLoaded', fn); | ||
} | ||
} | ||
|
||
function initializeTinyMCE(element, formsetName) { | ||
Array.from(element.querySelectorAll('.tinymce')).forEach(area => initTinyMCE(area)); | ||
} | ||
|
||
ready(function () { | ||
// initialize the TinyMCE editors on load | ||
initializeTinyMCE(document); | ||
}); | ||
} |