Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a plugin that works perfectly with ckeditor v3. Problem is when there is no Ckeditor on the screen on admin panel I get following message in the console.
Uncaught ReferenceError: CKEDITOR is not defined - plugin.js?navohq:7
That's what I have on line 7
CKEDITOR.plugins.add('pluginName', {
How do I get rid of that error ?
Comments
Comment #1
TwoDWell, you could wrap it all in
if (window.CKEDITOR) { ...plugin code... }
, but you really shouldn't need to do that since your plugin file shouldn't be loaded unless an editor has been loaded first. At least that would be the case if you're implementing hook_wysiwyg_plugin() to present the plugin to Wysiwyg module.Are you using custom code to load this plugin?
Comment #2
atomicreach CreditAttribution: atomicreach commentedI am not sure what would be custom code but this is the method I am using in the module.
Here are the first few lines of the plugin.js file.
if(typeof(CKEDITOR)!== 'undefined') seems to fix the issue. However, I am not sure if this is the right way to fix this.
Thanks
Comment #3
TwoDThat looks good, but the question is why the plugin file would be included when there is no editor available.
Is the module using drupal_add_js() anywhere to include the file manually?
Could you give an example of where this error appears?
Comment #4
atomicreach CreditAttribution: atomicreach commentedModule is not including that file anywhere but from what I shared above. An example would be every admin page when there is no ckeditor on screen. i.e find content page or settings page.
Comment #5
TwoDIs
Drupal.settings.wysiwyg
set when there are no editors?Comment #6
atomicreach CreditAttribution: atomicreach commentedSorry, I don't understand? Can you provide more info on it.
Comment #7
TwoDOpen the browser's developer tools (usually Ctrl+Shift+I or J), switch to the console and enter
Drupal.settings.wysiwyg
to see if the Wysiwyg settings object was created. You could also check the Net[work] or Scripts sections to see if wysiwyg.js and/or wysiwyg.init.js were loaded.Comment #8
atomicreach CreditAttribution: atomicreach commentedokay thanks for the explanation. Now if I refer back to your question
so the answer is NO. When there is no editor, it returns 'undefined'.
Comment #9
TwoDOk, that suggests Wysiwyg is not the one including the plugin file, or it would likely be including its other scripts and the settings too.
Tracking exactly where the file gets included from is a bit difficult, but it should be in that module, since it's the only one, except for Wysiwyg, which "knows" the file exists.
Is JavaScript optimization/aggregation enabled on the performance page? Maybe it was included in an aggregated file by mistake...
Is the plugin file's script tag listed in the document header or in the body? (If it is listed at all and not included as part of aggregated scripts, always disable aggregation first when debugging things like this.) Wysiwyg includes all plugins in the header.