* Fix Runkit tags not being activated when comment is added * Runkit tag activation was ran once, on page load. I've changed it to run on on comment preview and submit. * It was necessary to add a check to skip already activated Runkit tags. The code didn't take into account that a tag could be already processed, and would just crash. * Fix Runkit tags and add tests * Add test for previewing article with Runkit tag * "Fix CodeClimate not finding waitForRunkitAndActivateTags() * Refactor a test for readability * Make Rubocop happy * Improve test for previewing article with Runkit tag * Use one method for determining active Runkit tags * Defer loading of JS from embed.runkit.com * Add utility function dynamicallyLoadScript(url) * Switch to dynamic loading of Runkit * parsed content code block is also hidden now to avoid displaying <code /> block before runkit iframe loads. * Fix Runkit test * Remove Runkit script caching in v2 form * Use <%== instead of .html_safe in v2 form * Update app/assets/javascripts/utilities/dynamicallyLoadScript.js Co-authored-by: Nick Taylor <nick@iamdeveloper.com> Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
10 lines
214 B
JavaScript
10 lines
214 B
JavaScript
|
|
|
|
function dynamicallyLoadScript(url) {
|
|
if (document.querySelector(`script[src='${url}']`)) return;
|
|
|
|
const script = document.createElement('script');
|
|
script.src = url;
|
|
|
|
document.head.appendChild(script);
|
|
}
|