From d441e27239b8a15462b439199a8c57c5fb47f00f Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Fri, 17 Oct 2014 14:25:52 -0400 Subject: [PATCH] Set $ to django.jQuery if $ not defined, organize ckeditor-init.js, replace .click(...) with delegated .on(...) in case elements do not exist when code is run --- ckeditor/static/ckeditor/ckeditor-init.js | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) 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')); } - }); -} + }); + }; + }); +}());