forked from zsiciarz/django-markitup
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure MarkItUp editors from a script after document ready
Rather than using inline scripts, just apply some attributes to the widget, so we can locate it later in the DOM. This means jQuery doesn't have to be loaded before the MarkItUpWidget or markitup_editor tag is rendered on a page, all scripts can be loaded in the document foot. Fixes: zsiciarz#25
- Loading branch information
Showing
6 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
(function($) { | ||
// Configure a MarkItUp editor on element | ||
// Config comes from data attributes on config | ||
function configure_markitup_editor(element, config) { | ||
var preview_url = config.attr('data-preview-url'); | ||
var auto_preview = config.attr('data-auto-preview') == '1'; | ||
if (!element.hasClass("markItUpEditor")) { | ||
if (preview_url) { | ||
mySettings["previewParserPath"] = preview_url; | ||
} | ||
element.markItUp(mySettings); | ||
} | ||
if (auto_preview) { | ||
$('a[title="Preview"]').trigger('mouseup'); | ||
} | ||
}; | ||
|
||
$(function() { | ||
$('.django-markitup-widget').each(function(index) { | ||
var element = $(this); | ||
configure_markitup_editor(element, element); | ||
}); | ||
|
||
$('.django-markitup-editor-config').each(function(index) { | ||
var config = $(this); | ||
var element = $(config.attr('data-element')); | ||
configure_markitup_editor(element, config); | ||
}); | ||
}); | ||
})(jQuery || django.jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
<script type="text/javascript"> | ||
(function($) { | ||
$(document).ready(function() { | ||
var element = $("#{{ textarea_id }}"); | ||
if(!element.hasClass("markItUpEditor")) { | ||
{% if preview_url %}mySettings["previewParserPath"] = "{{ preview_url }}";{% endif %} | ||
element.markItUp(mySettings); | ||
} | ||
{% if AUTO_PREVIEW %}$('a[title="Preview"]').trigger('mouseup');{% endif %} | ||
}); | ||
})(jQuery); | ||
</script> | ||
<div class="django-markitup-editor-config" style="display: none" | ||
data-element="#{{ textarea_id }}" | ||
data-preview-url="{{ preview_url }}" | ||
data-auto-preview="{{ AUTO_PREVIEW|yesno:"1,0" }}"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters