diff --git a/ckeditor/static/ckeditor/ckeditor-init.js b/ckeditor/static/ckeditor/ckeditor-init.js index de939a5..358a8a2 100644 --- a/ckeditor/static/ckeditor/ckeditor-init.js +++ b/ckeditor/static/ckeditor/ckeditor-init.js @@ -1,20 +1,23 @@ -$(function() { +;(function() { + var $ = $ || django.jQuery; + $(function() { initialiseCKEditor(); initialiseCKEditorInInlinedForms(); function initialiseCKEditorInInlinedForms() { - $(".add-row a, .grp-add-handler").click(function () { - initialiseCKEditor(); - return true; - }); + $(document).on("click", ".add-row a, .grp-add-handler", function () { + initialiseCKEditor(); + return true; + }); } -}); -function initialiseCKEditor() { - $('textarea[data-type=ckeditortype]').each(function(){ + function initialiseCKEditor() { + $('textarea[data-type=ckeditortype]').each(function(){ if($(this).data('processed') == "0" && $(this).attr('id').indexOf('__prefix__') == -1){ - $(this).data('processed',"1"); - CKEDITOR.replace($(this).attr('id'), $(this).data('config')); + $(this).data('processed',"1"); + CKEDITOR.replace($(this).attr('id'), $(this).data('config')); } - }); -} + }); + }; + }); +}()); diff --git a/ckeditor/urls.py b/ckeditor/urls.py index a88bb0d..e8a3d70 100644 --- a/ckeditor/urls.py +++ b/ckeditor/urls.py @@ -1,10 +1,11 @@ from django.conf.urls import patterns, url from django.contrib.admin.views.decorators import staff_member_required +from django.views.decorators.cache import never_cache from ckeditor import views urlpatterns = patterns( '', url(r'^upload/', staff_member_required(views.upload), name='ckeditor_upload'), - url(r'^browse/', staff_member_required(views.browse), name='ckeditor_browse'), + url(r'^browse/', never_cache(staff_member_required(views.browse)), name='ckeditor_browse'), ) diff --git a/ckeditor/views.py b/ckeditor/views.py index 336001b..3223581 100644 --- a/ckeditor/views.py +++ b/ckeditor/views.py @@ -98,7 +98,7 @@ def get_image_files(user=None, path=''): return for filename in storage_list[STORAGE_FILES]: - if os.path.splitext(filename)[0].endswith('_thumb'): + if os.path.splitext(filename)[0].endswith('_thumb') or os.path.basename(filename).startswith('.'): continue filename = os.path.join(browse_path, filename) yield filename diff --git a/ckeditor/widgets.py b/ckeditor/widgets.py index c322be8..bf68d59 100644 --- a/ckeditor/widgets.py +++ b/ckeditor/widgets.py @@ -8,10 +8,19 @@ from django.utils.encoding import force_text from django.utils.translation import get_language from django.core.exceptions import ImproperlyConfigured from django.forms.util import flatatt -import json + +from django.utils.functional import Promise +from django.utils.encoding import force_text +from django.core.serializers.json import DjangoJSONEncoder + +class LazyEncoder(DjangoJSONEncoder): + def default(self, obj): + if isinstance(obj, Promise): + return force_text(obj) + return super(LazyEncoder, self).default(obj) -json_encode = json.JSONEncoder().encode +json_encode = LazyEncoder().encode DEFAULT_CONFIG = { 'skin': 'moono',