Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: django is not defined ( init_tinymce.js:38 ) #124

Closed
lives opened this issue Jul 29, 2015 · 19 comments
Closed

Uncaught ReferenceError: django is not defined ( init_tinymce.js:38 ) #124

lives opened this issue Jul 29, 2015 · 19 comments

Comments

@lives
Copy link

lives commented Jul 29, 2015

Django 1.8 and django-tinymce==2.1.0.dev0

Unable to use django-tinymce in custom forms.
Error : Uncaught ReferenceError: django is not defined ( init_tinymce.js:38 )

The "admin" test is ok, http://django-tinymce.readthedocs.org/en/latest/installation.html#testing

@Natim
Copy link
Collaborator

Natim commented Jul 30, 2015

Does this fixes your issue? #108 or #102 (comment)

@Natim
Copy link
Collaborator

Natim commented Jul 30, 2015

Could you try last master, if it works for you I will make a bugfix release

@lives
Copy link
Author

lives commented Aug 3, 2015

Natim, thank you for you answer.

Tested master 27407b3 , but same error.

@eson-schulz
Copy link

I am having the same issue also using Django 1.8. I downgraded to Django-TinyMCE 1.5.2 as recommended by http://stackoverflow.com/questions/28643823/tinymce-for-django-is-not-loading-throwing-error-in-init 1.5.2 fixes the issue.

@lives
Copy link
Author

lives commented Aug 4, 2015

Ok, it works with latest django-tinymce + a fix ( from master 27407b3)

--- init_tinymce_27407b3dea637900b2f8da9a553df858ac2f6c45.js    2015-08-04 13:14:00.911348163 +0200
+++ init_tinymce.js 2015-08-04 13:14:10.187348075 +0200
@@ -35,4 +35,4 @@
       }, 0);
     }, true);
   });
-}( function () { return django && django.jQuery || jQuery }()));
+}( function (django) { return django && django.jQuery || jQuery }()));

@Natim
Copy link
Collaborator

Natim commented Aug 4, 2015

I revert my commit, can you try current master? If it works I will release a new version of django-tinymce.

@eson-schulz
Copy link

Not sure about lives, but I pulled the current master; the code that was working with 1.5.2 stopped when I updated. The same "Uncaught ReferenceError: jQuery is not defined" issue.

@lives
Copy link
Author

lives commented Aug 5, 2015

Working ok with master 4d6e78f , thanks.

@Natim
Copy link
Collaborator

Natim commented Aug 6, 2015

Ok let's release a bugfix release and see how it goes.

@Natim
Copy link
Collaborator

Natim commented Aug 6, 2015

@eson-schulz Make sure you include jQuery in your page and try https://github.com/aljosa/django-tinymce/releases/tag/2.0.3

@hiltonc
Copy link

hiltonc commented Sep 17, 2015

I see this issue with django-tinymce 2.0.5. To repro:

  1. Download and unzip https://www.dropbox.com/s/84kgv2eqn1cnf6i/django-tinymce-2.0.5-non-admin-broken.zip?dl=0
  2. pip install -r requirements.txt
  3. Run it and view the root page in your browser

Expected: TinyMCE awesomeness
Actual: JavaScript console error: "Uncaught ReferenceError: django is not defined"

@mattarchie
Copy link

@Natim Has that bugfix been released? I have django-tinymce 2.0.5 and I'm still getting the "django is not defined" error; however, when I add the change from #108 it works correctly. I see that in commit 3f68de1, the fix was altered (this commit's change is reflected in the code I have that gives the error). I'm not sure if the fact I'm using an older version of Django (1.4.1) would cause an issue with this, but it seems like the issue was fixed and then unfixed.

@dco5
Copy link

dco5 commented Nov 6, 2015

Is this working with django 1.8 and django-tinymce 2.0.5?? I am getting
Uncaught ReferenceError: django is not defined init_tinymce.js:38

@Natim
Copy link
Collaborator

Natim commented Nov 6, 2015

Does somebody want to fix this and file a PR? I will merge it and release 2.0.6.

@mattarchie
Copy link

@Natim After further testing the change from #108 isn't perfect. The current version of init_tinymce.js, works with admin pages, but not with non-admin ones. After the reverting 3f68de1, the code works with non-admin pages, but not admin ones. Using your suggestion in #108 again makes only admin pages work.

The following two versions of init_tinymce.js:38 make admin pages work, but not non-admin ones:
}(django && django.jQuery || jQuery)); and }( function(django) { return django && django.jQuery || jQuery}(django)));
And this version makes non-admin pages work, but not admin ones:
}( function(django) { return django && django.jQuery || jQuery}()));
This gives the following error on the admin page in the test app provided by django-tinymce:

Uncaught TypeError: $ is not a function init_tinymce.js:18
(anonymous function) @ init_tinymce.js:18
(anonymous function) @ init_tinymce.js:38


**Update:** I found a StackOverflow post (http://stackoverflow.com/a/10584539/4725574) that adding these files in your html template or to the form media works.

django/contrib/admin/static/admin/js/jquery.init.js
django/contrib/admin/static/admin/js/jquery.js

I also found that if you change
}(django && django.jQuery || jQuery)); to }(jQuery || django && django.jQuery)); then there are no errors on either admin or non-admin pages, but I don't know if there's a reason the django && django.jQuery part comes first, such that changing the order is problematic.

@mattarchie
Copy link

Is the purpose of the django && django.jQuery to make sure that you use the jQuery version in the django namespace instead of the jQuery version pointed to by the global jQuery variable? Whether that's the case or not, this should work to replace }(django && django.jQuery || jQuery)); without breaking the preference for django.jQuery if it exists:

}((typeof django === 'undefined' || typeof django.jQuery === 'undefined') && jQuery || django && django.jQuery));

Although it's not pretty, I will create a PR with this version because it solves the issue for me and works on both admin and non-admin pages.

@Natim
Copy link
Collaborator

Natim commented Nov 12, 2015

A fix has been released as per django-tinymce 2.0.6 can you guys check it and validate that it fixes your problem?

Thanks @mattarchie for fixing this.

@hiltonc
Copy link

hiltonc commented Nov 23, 2015

I just had a chance to try this out. Works great, thank you!

@Natim
Copy link
Collaborator

Natim commented Nov 23, 2015

Thank you for the feedback @hiltonc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants