Skip to content

Commit

Permalink
Update markitup, support extra set
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Feb 25, 2014
1 parent 4cc8b9b commit c9ed7f4
Show file tree
Hide file tree
Showing 73 changed files with 465 additions and 293 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ db.sqlite3
dist
docs/_*
sitegen.egg-info
todo.txt
_
3 changes: 2 additions & 1 deletion ChangeLog.txt → Changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2014-02-25 horneds
2014-02-25 horneds dfeinzeig

* WARNING: `DJANGO_MARKDOWN_STYLE` settings renamed to `MARKDOWN_STYLE`
* Fix compress with yui compressor

2014-02-22 dfeinzeig

Expand Down
40 changes: 9 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Installation
Setup
=====

.. note:: 'django_markdown' require 'django.contrib.staticfiles' in INSTALLED_APPS

- Add 'django_markdown' to INSTALLED_APPS ::

INSTALLED_APPS += ( 'django_markdown', )
Expand All @@ -71,7 +73,7 @@ Use django_markdown

from django_markdown.widgets import MarkdownWidget
class MyCustomForm(forms.Form):
content = forms.CharField( widget=MarkdownWidget() )
content = forms.CharField(widget=MarkdownWidget())

#) Custom admins: ::

Expand All @@ -87,47 +89,19 @@ Use django_markdown
admin.autodiscover()
flatpages.register()
urlpatterns += [ url(r'^admin/', include(admin.site.urls)), ]

#) JavaScript API: ::

// Editors manager ``miu`` methods

// Initialize editor using default settings extended with ``extraSettings``
miu.init(textareaId, extraSettings);

// Get default mIu settings
miu.settings();

// Set default mIu settings
miu.settings(newSettings);
// Get all initialized aditors
miu.editors();
// Get certain editor
miu.editors(textareaId);
// Editor instance methods
// Dynamically add button at ``index`` position
editor.addButton(conf, index)
// Dynamically remove button at ``index`` position
editor.removeButton(index)

Settings
========

**MARKDOWN_EDITOR_SETTINGS** - holds the extra parameters set to be passed to textarea.markItUp()

**MARKDOWN_EDITOR_SKIN** - skin option, default value is ``markitup``

Example: `settings.py` ::

MARKDOWN_EDITOR_SKIN = 'simple'

**MARKDOWN_EDITOR_SETTINGS** - holds the extra parameters set to be passed to textarea.markItUp()

**MARKDOWN_EXTENSIONS** - optional list of extensions passed to Markdown, discussed at https://pythonhosted.org/Markdown/extensions/index.html#officially-supported-extensions

Example: `settings.py` ::
Expand All @@ -136,6 +110,10 @@ Example: `settings.py` ::

**MARKDOWN_STYLE** - path to preview styles. By default `django_markdown/preview.css`

**MARKDOWN_SET_PATH** - path to folder with sets. By default `django_markdown/sets`

**MARKDOWN_SET_NAME** - name for current set. By default `markdown`.


Examples
========
Expand Down
21 changes: 21 additions & 0 deletions django_markdown/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
""" Application settings. """

import posixpath

from django.conf import settings


MARKDOWN_EDITOR_SETTINGS = getattr(settings, 'MARKDOWN_EDITOR_SETTINGS', {})
MARKDOWN_EDITOR_SKIN = getattr(settings, 'MARKDOWN_EDITOR_SKIN', 'simple')
MARKDOWN_EXTENSIONS = getattr(settings, 'MARKDOWN_EXTENSIONS', [])
MARKDOWN_SET_PATH = getattr(settings, 'MARKDOWN_SET_PATH', posixpath.join(
'django_markdown', 'sets'
))
MARKDOWN_SET_NAME = getattr(
settings, 'MARKDOWN_SET_NAME',
'markdownextra' if 'extra' in MARKDOWN_EXTENSIONS else 'markdown')

MARKDOWN_STYLE = getattr(settings, 'MARKDOWN_STYLE', posixpath.join(
'django_markdown', 'preview.css'
))
STATIC_URL = settings.STATIC_URL or settings.MEDIA_URL
Binary file not shown.
35 changes: 35 additions & 0 deletions django_markdown/static/django_markdown/jquery.init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
// Starting from Django 1.6+, jQuery is only available as 'django' object attribute.
// Unfortunately, it's not compatible with markitup.js library because it needs global jQuery variable to be initialized.
jQuery = jQuery || django.jQuery;

(function($) {
// from http://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = $.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');

function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
crossDomain: false, // obviates need for sameOrigin test
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});

})(jQuery);
6 changes: 0 additions & 6 deletions django_markdown/static/django_markdown/jquery.markitup.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,6 @@
function remove() {
$$.unbind(".markItUp").removeClass('markItUpEditor');
$$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);

var relativeRef = $$.parent('div').parent('div.markItUp').parent('div');
if (relativeRef.length) {
relativeRef.replaceWith($$);
}

$$.data('markItUp', null);
}

Expand Down
21 changes: 0 additions & 21 deletions django_markdown/static/django_markdown/markdown.css

This file was deleted.

202 changes: 0 additions & 202 deletions django_markdown/static/django_markdown/markdown.js

This file was deleted.

Loading

0 comments on commit c9ed7f4

Please sign in to comment.