When I move the scripts to the bottom of html.tpl.php (I have the line <?php print $scripts; ?> at the end of <body>) I'm getting the following JavaScript error on pages with CKEditor:

ReferenceError: Drupal is not defined

As others say in the related issue, moving the line <?php print $scripts; ?> to the <head> section fixes the problem.

This looks like a workaround, but not as a bugfix since the recommended practise is moving the scripts down into the page for performance reasons.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

belaustegui created an issue. See original summary.

Igor Mancos’s picture

+1 Confirm issue, wait fixed version of the module.

jordisan’s picture

The problem is in this file: https://git.drupalcode.org/project/ckeditor/-/blob/7.x-1.x/includes/cked...

If the scripts are loaded at the bottom of the page, then that code runs before the Drupal initialization, which causes the error.

WORKAROUND:
You can put all the code of that file inside this:

document.addEventListener("DOMContentLoaded", function(event) {
  // CURRENT CONTENT OF ckeditor.utils.js
});

That way it won't run until the full page is loaded, including the Drupal JS code.

vokiel’s picture

@jordisan could you please check if moving line 8 before line 5 https://git.drupalcode.org/project/ckeditor/-/blob/7.x-1.x/includes/cked... fixes the issue in your configuration?

jordisan’s picture

@vokiel , in that case you get this error in line 530:

Uncaught ReferenceError: jQuery is not defined

It's the same problem: neither Drupal nor jQuery are defined at that point; the workaround I mentioned at #3 does actually work.

vokiel’s picture

Status: Active » Needs review
FileSize
40.31 KB

Created patch, although I think you @jordisan have already tested it before :-)

  • vokiel committed 27c0d6a on 7.x-1.x
    Issue #2648232 by vokiel, jordisan: Drupal is not defined
    
vokiel’s picture

Status: Needs review » Fixed
vokiel’s picture

Status: Fixed » Closed (fixed)
vokiel’s picture

This fix breaks editor loaded from the <head> section.

Reverted in bbd0f7c

vokiel’s picture

Status: Closed (fixed) » Needs work