Closed tyctor closed 5 months ago
Hi @tyctor you can simply use the Mutation Observer interface (https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe)
Example:
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === "attributes") {
const theme = $('html').attr('data-bs-theme'); // light | dark
// do something useful
}
});
});
observer.observe($('html')[0], {
attributes: true //configure it to listen to attribute changes
});
thanks very much for your example
it works like a charm when i replace $
with django.jQuery
it not work with $
, because i have problem with jQuery reference in $
, i have django admin jquery included in page, and when i put console.log
on the end of that file, window.$
is there, but when page loads, and i try to print $
in chrome developer console, i get undefined
dont you have any suggestion why $
is lost?
looking forward to your answer
Hi @tyctor is the expected behavior to have jQuery namespaced inside django object
ok, but in every external script is used $
, IMHO i cannot update external dependencies to use django.JQuery
i am not sure why or when it is stopped working, i am upgrading from django 3.2
with django-suit
to django 4.2
with django-baton
so mainly what changed was replacing django-suit
with django-baton
i found this https://github.com/otto-torino/django-baton/issues/256
cannot be lost of $
reference related to django-baton
?
ok, it seems that it is going with django 4.2, previous versions has $
Hi
i wonder if we could have signal triggered on theme (dark/light) switching i am using TinyMCE as WYSIWYG for django TextField, and i am able to re-init editor in javascript so such signal will be ideal solution for my use case.
or if you have some hint about WYSIWYG which can do this in coexistence with baton, i would like to try it
looking forward to your reply