Skip to content

Commit

Permalink
fix 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
surajsinghbisht054 committed Jan 8, 2025
1 parent d153395 commit c98ccb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions django_editorjs2/templates/django_editorjs2/widget/editorjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
{% with "editorJs_initial_json_"|add:widget.name as editorJs_initial_json %}
{{ widget.value|json_script:editorJs_initial_json }}
<script>
document.addEventListener('DOMContentLoaded', function () {
function callWhenReady(callback) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', callback);
} else {
callback();
}
}
callWhenReady(function () {
// Get CSRF token from cookie
function getCookie(name) {
let cookieValue = null;
Expand Down Expand Up @@ -44,7 +51,8 @@
}
).then(response => response.json())
}
const initial_json = JSON.parse(document.getElementById('{{editorJs_initial_json}}').textContent)|| {};
const initial_json = JSON.parse(document.getElementById('{{editorJs_initial_json}}').textContent) || {};
document.querySelector('[name="{{ widget.name }}"]').value = document.getElementById('{{editorJs_initial_json}}').textContent;
const editor = new EditorJS({
holder: 'editorjs-{{ widget.name }}',
autofocus: true,
Expand Down Expand Up @@ -112,13 +120,13 @@
},
onChange: function () {
editor.save().then((outputData) => {
console.log(outputData)
document.querySelector('[name="{{ widget.name }}"]').value = JSON.stringify(outputData);
}).catch((error) => {
console.error('Saving failed:', error);
});
},
});


})

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-editorjs2"
version = "0.3.5"
version = "0.3.6"
description = "A Django app that seamlessly integrates EditorJS, a powerful block-styled editor with a clean, intuitive interface."
authors = ["Suraj Singh Bisht <surajsinghbisht054@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit c98ccb4

Please sign in to comment.