ugie-cake / cakephp-content-blocks

User editable content for CakePHP templates
BSD 3-Clause "New" or "Revised" License
1 stars 4 forks source link

CKEditor script potentially runs too early #4

Closed epetousis closed 1 year ago

epetousis commented 1 year ago

On our site, we define our script block at the bottom of the page to make sure the webpage appears before JavaScript begins executing. Unfortunately, this conflicts with the way the edit template is written, as CKEditor is instantiated in the middle of the template.

We can fix this with a custom template, but it might be overkill for anyone else using the plugin. Any chance this CKEditor code could be defined inside the script view block instead? I'm happy to submit a pull request for this if it's something you're interested in.

pserwylo commented 1 year ago

Good catch. A PR would be more than welcome (once accepted, we can tag a new release and Packagist/Composer will pick it up instantly and publish a new version ready to use).

Quick question - can we depend on every website having a script view block?

If not, the other alternative is to do something like:

document.addEventListener("DOMContentLoaded", (event) => {
  // Load CKEditor here.
});

Then we can plonk that anywhere and it will execute once the HTML is parsed and all scripts have downloaded and executed.

epetousis commented 1 year ago

A DOMContentLoaded event listener makes far more sense, not sure how it escaped my mind. I can get a pull request sorted in the next day or two when I have a spare moment.