Answer the question
In order to leave comments, you need to log in
Help with Django pagedown?
I am making a comment system, I use pagedown for the text editor, although a specific editor, it seems to me, has a secondary solution in this matter. There are many forms in the template, under each comment there is a response form, because of this I get the following error: Pagedown editor already attached to element: <#id_comment>. Because of it, only the top input form on the page is displayed correctly. Tried other editors, same problem. Please tell me how to be. I see 2 approaches, try to enter from the side of django forms, but even I have little idea how, or fix the js editor. In js, it is even weaker than in django, I will post a piece of editor code that is responsible for displaying an error. Tell me, can you just fix something in it quickly and that's all?
var DjangoPagedown = DjangoPagedown | {};
DjangoPagedown = (function() {
var converter,
editors,
elements;
var that = this;
var isPagedownable = function(el) {
if ( (' ' + el.className + ' ').indexOf(' wmd-input ') > -1 ) {
return true;
}
return false;
};
var createEditor = function(el) {
if ( isPagedownable(el) ) {
if ( ! that.editors.hasOwnProperty(el.id) ) {
var selectors = {
input : el.id,
button : el.id + "_wmd_button_bar",
preview : el.id + "_wmd_preview",
};
that.editors[el.id] = new Markdown.Editor(that.converter, "", selectors);
that.editors[el.id].run();
return true;
} else {
console.log("Pagedown editor already attached to element: <#" + el.id + ">");
}
}
return false;
};
var destroyEditor = function(el) {
if ( that.editors.hasOwnProperty(el.id)) {
delete that.editors[el.id];
return true;
}
return false;
};
var init = function() {
that.converter = Markdown.getSanitizingConverter();
Markdown.Extra.init(that.converter, {
extensions: "all"
});
that.elements = document.getElementsByTagName("textarea");
that.editors = {};
for (var i = 0; i < that.elements.length; ++i){
if ( isPagedownable(that.elements[i]) ) {
createEditor(that.elements[i]);
}
}
};
return {
init: function() {
return init();
},
createEditor: function(el) {
return createEditor(el);
},
destroyEditor: function(el) {
return destroyEditor(el);
},
};
})();
window.onload = DjangoPagedown.init;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question