Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline rendering failure #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions suit_redactor/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,40 @@ def __init__(self, attrs=None, editor_options={}):

def render(self, name, value, attrs=None):
output = super(RedactorWidget, self).render(name, value, attrs)
output += mark_safe(
'<script type="text/javascript">$("#id_%s").redactor(%s);</script>'
% (name, json.dumps(self.editor_options)))
blank_element = '-__prefix__-'
editor_options = json.dumps(self.editor_options)
if blank_element in name:
try:
prefix, suffix = name.split(blank_element)
except KeyError:
return output
dom_id = r'/id_{}-\d+-{}/g'.format(prefix, suffix)
output += mark_safe("""
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
Suit.after_inline.register('%s', function (prefix, row) {
if(row === undefined || row[0] === undefined || !row[0].childNodes){
return;
}
row[0].childNodes.forEach(function(child) {
if(!child.childNodes){
return;
}
child.childNodes.forEach(function(subChild) {
if(subChild.id){
var id = subChild.id.match(%s);
if(id !== null && id[0] !== undefined){
$('#' + id[0]).redactor(%s);
};
}
});
});
});
});
</script>
""" % (prefix, dom_id, editor_options))
else:
output += mark_safe(
'<script type="text/javascript">$("#id_%s").redactor(%s);</script>'
% (name, editor_options))
return output