Skip to content

Commit

Permalink
Replace markitup's inline JS to fix load order bug
Browse files Browse the repository at this point in the history
See: zsiciarz/django-markitup#25

django-markitup renders inline JS in each widget that configures the
widget. This JS requires jQuery and markitup.js to already be loaded,
which isn't the case if we're loading JS in the foot of the page.

So, override the template that generates that inline JS, with something
that generates a hidden tag containing only config. Then come back at
the end of the JS loading, and configure the widgets.

I'll do a similar PR upstream and hope that we can pull this out, later.
  • Loading branch information
stefanor committed Jan 31, 2018
1 parent 82f773c commit 844279d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions wafer/pages/templates/wafer.pages/page_form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'wafer/base.html' %}
{% load crispy_forms_tags %}
{% load i18n %}
{% load static from staticfiles %}
{% block extra_head %}
{{ form.media.css }}
{% endblock %}
Expand All @@ -12,4 +13,5 @@ <h1>{% trans "Edit Page" %}</h1>
{% endblock %}
{% block extra_foot %}
{{ form.media.js }}
<script type="text/javascript" src="{% static 'js/markitup.js' %}"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion wafer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
'django_medusa',
'crispy_forms',
'django_nose',
'markitup',
'rest_framework',
'easy_select2',
'wafer',
Expand All @@ -164,6 +163,7 @@
'wafer.tickets',
'wafer.compare',
# Django isn't finding the overridden templates
'markitup',
'registration',
'django.contrib.admin',
)
Expand Down
15 changes: 15 additions & 0 deletions wafer/static/js/markitup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'
$('.django-markitup-config').each(function(index) {
var element = $(this.getAttribute('data-element'));
var preview_url = this.getAttribute('data-preview-url');
var auto_preview = this.getAttribute('data-auto-preview');
if (!element.hasClass("markItUpEditor")) {
if (preview_url) {
mySettings["previewParserPath"] = preview_url;
}
element.markItUp(mySettings);
}
if (auto_preview) {
$('a[title="Preview"]').trigger('mouseup');
}
});
2 changes: 2 additions & 0 deletions wafer/talks/templates/wafer.talks/talk_form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'wafer/base.html' %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load static from staticfiles %}
{% block extra_head %}
{{ form.media.css }}
{% endblock %}
Expand Down Expand Up @@ -28,4 +29,5 @@ <h1>{% trans "Talk Submission" %}</h1>
{% endblock %}
{% block extra_foot %}
{{ form.media.js }}
<script type="text/javascript" src="{% static 'js/markitup.js' %}"></script>
{% endblock %}
4 changes: 4 additions & 0 deletions wafer/templates/markitup/editor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="django-markitup-config" style="display: none"
data-element="#{{ textarea_id }}"
data-preview-url="{{ preview_url }}"
data-auto-preview="{{ AUTO_PREVIEW|yesno:"1,0" }}"></div>

0 comments on commit 844279d

Please sign in to comment.