Commit d7387585 authored by JurriaanRoelofs's avatar JurriaanRoelofs Committed by Robert Ragas

Issue #2574277 by JurriaanRoelofs: ReferenceError: detectCKEditorInstances is not defined

parent dda432db
......@@ -84,9 +84,9 @@
}
});
// Check for CKEditor instances, with a max of 2500ms(= 25ms * 100).
var maxDetectTries = 100;
detectCKEditorInstances();
// Check for CKEditor instances, with a max of 2500ms(= 250ms * 10).
var maxDetectTries = 10;
detectCKEditorInstances(maxDetectTries, DrupalSource);
// If we have multiple text formats we have to detect the CKEditor
// on several occasions.
......@@ -94,40 +94,16 @@
// On text format change detect any CKEditor instances, if
// applicable ofcourse.
$('#' + settings.yoast_seo.textFormat).change(function() {
maxDetectTries = 100;
detectCKEditorInstances();
maxDetectTries = 10;
detectCKEditorInstances(maxDetectTries, DrupalSource);
});
// Detect CKEditor on 'switch to rich text editor' link click.
$('#' + settings.yoast_seo.textFormat).siblings('.ckeditor_links').click(function() {
maxDetectTries = 100;
detectCKEditorInstances();
maxDetectTries = 10;
detectCKEditorInstances(maxDetectTries, DrupalSource);
});
}
// Simple function to detect CKEditor instances for the body field.
function detectCKEditorInstances() {
var detected = false;
if (typeof CKEDITOR != "undefined" && CKEDITOR.instances.length != 0 && maxDetectTries > 0) {
if (typeof CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text] != "undefined") {
detected = true;
// On any change in the CKEditor instance we set the value of
// the CKEditor instance back into the textarea. At that point
// we also fire a new input event.
CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text].on('change', function() {
document.getElementById(YoastSEO.analyzerArgs.fields.text).value = CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text].getData();
// Dispatch input event so Yoast SEO knows something changed!
DrupalSource.triggerEvent(YoastSEO.analyzerArgs.fields.text);
});
}
}
// Retry if we haven't been able to detect a CKEditor yet.
if (!detected && maxDetectTries > 0) {
maxDetectTries--;
setTimeout(detectCKEditorInstances, 25);
}
};
}
else {
$('#' + settings.yoast_seo.targets.output).html('<p><strong>' + Drupal.t('It looks like something went wrong when we tried to load the Yoast SEO content analysis library. Please check it the module is installed correctly.') + '</strong></p>');
......@@ -138,6 +114,32 @@
}
})(jQuery);
// Simple function to detect CKEditor instances for the body field.
function detectCKEditorInstances(maxDetectTries, DrupalSource) {
var detected = false;
if (typeof CKEDITOR != "undefined" && CKEDITOR.instances.length != 0 && maxDetectTries > 0) {
if (typeof CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text] != "undefined") {
detected = true;
// On any change in the CKEditor instance we set the value of
// the CKEditor instance back into the textarea. At that point
// we also fire a new input event.
CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text].on('change', function() {
document.getElementById(YoastSEO.analyzerArgs.fields.text).value = CKEDITOR.instances[YoastSEO.analyzerArgs.fields.text].getData();
// Dispatch input event so Yoast SEO knows something changed!
DrupalSource.triggerEvent(YoastSEO.analyzerArgs.fields.text);
});
}
}
// Retry if we haven't been able to detect a CKEditor yet.
if (!detected && maxDetectTries > 0) {
maxDetectTries--;
setTimeout(function() {
detectCKEditorInstances(maxDetectTries, DrupalSource);
}, 250);
}
};
/**
* Inputgenerator generates a form for use as input.
* @param args
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment