Skip to content

Commit 796ed98

Browse files
author
Agus Makmun
committed
fix: editor unable to load in django admin inline
1 parent 6e31c71 commit 796ed98

8 files changed

+53
-47
lines changed

martor/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
__VERSION__ = "1.6.41"
4-
__RELEASE_DATE__ = "29-Mar-2024"
3+
__VERSION__ = "1.6.42"
4+
__RELEASE_DATE__ = "30-Mar-2024"
55
__AUTHOR__ = "Agus Makmun (Summon Agus)"
66
__AUTHOR_EMAIL__ = "[email protected]"

martor/static/martor/css/martor-admin.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.41
2+
* Name : Martor v1.6.42
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 29-Mar-2024
4+
* Release date : 30-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/css/martor.bootstrap.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.41
2+
* Name : Martor v1.6.42
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 29-Mar-2024
4+
* Release date : 30-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/css/martor.semantic.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.41
2+
* Name : Martor v1.6.42
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 29-Mar-2024
4+
* Release date : 30-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/js/martor.bootstrap.js

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* Name : Martor v1.6.41
2+
* Name : Martor v1.6.42
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 29-Mar-2024
4+
* Release date : 30-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
7+
* JS Minifier : https://jscompress.com
78
**/
89

910
(function ($) {
@@ -147,14 +148,14 @@
147148
var currentTab = $('.tab-pane#nav-preview-' + field_name);
148149
var editorTabButton = $('.nav-link#nav-editor-tab-' + field_name);
149150
var previewTabButton = $('.nav-link#nav-preview-tab-' + field_name);
150-
var toolbarButtons = $(this).closest('.tab-martor-menu').find('.martor-toolbar')
151+
var toolbarButtons = $(this).closest('.tab-martor-menu').find('.martor-toolbar');
151152

152153
editorTabButton.click(function () {
153154
// show the `.martor-toolbar` for this current editor if under preview.
154-
$(this).closest('.tab-martor-menu').find('.martor-toolbar').show();
155+
toolbarButtons.show();
155156
});
156157
previewTabButton.click(function () {
157-
$(this).closest('.tab-martor-menu').find('.martor-toolbar').hide();
158+
toolbarButtons.hide();
158159
});
159160

160161
var refreshPreview = function () {
@@ -207,7 +208,7 @@
207208
if (editorConfig.living !== 'true') {
208209
previewTabButton.click(function () {
209210
// hide the `.martor-toolbar` for this current editor if under preview.
210-
$(this).closest('.tab-martor-menu').find('.martor-toolbar').hide();
211+
toolbarButtons.hide();
211212
refreshPreview();
212213
});
213214
} else {
@@ -858,9 +859,7 @@
858859
});
859860

860861
// Set initial value if has the content before.
861-
if (textareaId.val() != '') {
862-
editor.setValue(textareaId.val(), -1);
863-
}
862+
editor.setValue(textareaId.val(), -1);
864863
});// end each `mainMartor`
865864
};
866865

@@ -870,15 +869,18 @@
870869

871870
if ('django' in window && 'jQuery' in window.django)
872871
django.jQuery(document).on('formset:added', function (event) {
873-
var row = $(event.target);
874-
row.find('.main-martor').each(function () {
875-
var id = row.attr('id');
876-
id = id.substr(id.lastIndexOf('-') + 1);
877-
// Notice here we are using our jQuery instead of Django's.
878-
// This is because plugins are only loaded for ours.
879-
var fixed = $(this.outerHTML.replace(/__prefix__/g, id));
880-
$(this).replaceWith(fixed);
881-
fixed.martor();
882-
});
872+
// add delay for formset to load
873+
setTimeout(function(){
874+
var row = $(event.target);
875+
row.find('.main-martor').each(function () {
876+
var id = row.attr('id');
877+
id = id.substr(id.lastIndexOf('-') + 1);
878+
// Notice here we are using our jQuery instead of Django's.
879+
// This is because plugins are only loaded for ours.
880+
var fixed = $(this.outerHTML.replace(/__prefix__/g, id));
881+
$(this).replaceWith(fixed);
882+
fixed.martor();
883+
});
884+
}, 1000);
883885
});
884886
})(jQuery);

martor/static/martor/js/martor.bootstrap.min.js

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/static/martor/js/martor.semantic.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* Name : Martor v1.6.41
2+
* Name : Martor v1.6.42
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 29-Mar-2024
4+
* Release date : 30-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
7+
* JS Minifier : https://jscompress.com
78
**/
89

910
(function ($) {
@@ -855,9 +856,7 @@
855856
});
856857

857858
// Set initial value if has the content before.
858-
if (textareaId.val() != '') {
859-
editor.setValue(textareaId.val(), -1);
860-
}
859+
editor.setValue(textareaId.val(), -1);
861860
});// end each `mainMartor`
862861
};
863862

@@ -867,14 +866,17 @@
867866

868867
if ('django' in window && 'jQuery' in window.django)
869868
django.jQuery(document).on('formset:added', function (event, $row) {
870-
$row.find('.main-martor').each(function () {
871-
var id = $row.attr('id');
872-
id = id.substr(id.lastIndexOf('-') + 1);
873-
// Notice here we are using our jQuery instead of Django's.
874-
// This is because plugins are only loaded for ours.
875-
var fixed = $(this.outerHTML.replace(/__prefix__/g, id));
876-
$(this).replaceWith(fixed);
877-
fixed.martor();
878-
});
869+
// add delay for formset to load
870+
setTimeout(function(){
871+
$row.find('.main-martor').each(function () {
872+
var id = $row.attr('id');
873+
id = id.substr(id.lastIndexOf('-') + 1);
874+
// Notice here we are using our jQuery instead of Django's.
875+
// This is because plugins are only loaded for ours.
876+
var fixed = $(this.outerHTML.replace(/__prefix__/g, id));
877+
$(this).replaceWith(fixed);
878+
fixed.martor();
879+
});
880+
}, 1000);
879881
});
880882
})(jQuery);

0 commit comments

Comments
 (0)