fix ajax loading => add interval to wait for CKEDITOR to be loaded
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Thu, 23 Jun 2016 15:52:40 +0200
changeset 9 1ad1490c047f
parent 7 868de6d79658
child 10 4b74407a9b31
fix ajax loading => add interval to wait for CKEDITOR to be loaded closes #13521675
__init__.py
--- a/__init__.py	Tue Jun 07 14:17:56 2016 +0200
+++ b/__init__.py	Thu Jun 23 15:52:40 2016 +0200
@@ -17,7 +17,17 @@
         '//cdn.ckeditor.com/4.5.7/standard/ckeditor.js')
     self.add_js(ckeditor_url, localfile=False)
     self.add_js('initwysiwyg.js')
-    self.add_onload('buildWysiwygEditors()')
+    # we should wait CKEDITOR to be loaded before trying to use it
+    self.add_onload('''
+      var buildWysiwygEditorsInterval = setInterval(function() {
+        if (typeof CKEDITOR != "undefined") {
+          buildWysiwygEditors();
+          clearInterval(buildWysiwygEditorsInterval);
+        } else {
+          console.log('waiting for CKEDITOR to be loaded');
+        }
+      }, 200);
+    ''')
     self.html_headers.define_var('cklang', self.lang)
     self.html_headers.define_var('ckconfigpath',
                                  self.data_url('ckeditor-config.js'))