Opened 9 years ago
Closed 9 years ago
#13777 closed Bug (invalid)
Loading ckeditor with $.getScript or webpack fails: Is there a way to load the script on demand, only if it's needed?
Reported by: | pang | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | General | Version: | 4.5.3 |
Keywords: | getScript, on demand, webpack | Cc: |
Description
Goal
I'm building a SPA that needs rich text editing for a few formularies.
My goal is to load the heavy ckeditor only if it's required, and save the download and the loading time for the majority of visitors that do not need to edit rich text.
I'm also using webpack, but it's documented elsewhere that "require('ckeditor')" and such don't work either.
Steps to reproduce
1.If I want to turn on ckeditor for several textareas, I call:
ck.basic_editor(['id1', 'id2'])
where basic_editor is as follows:
ck.basic_editor = function(ls){ var load_when_lib_is_ready = function(){ var i; for(i=0;i<ls.length;i){ if (window.CKEDITOR.instances[ls[i]]==undefined){ window.CKEDITOR.replace( ls[i] , { customConfig : '../../js/plugins/ckeditor/ckeditor_config.js' }); } } }; if(window.CKEDITOR){ load_when_lib_is_ready(); }else{ $.getScript(BASE_URL + 'ckeditor/ckeditor.js', load_when_lib_is_ready); } }
- No matter where I place the above code, or the ckeditor script, I get errors like:
Uncaught SyntaxError: Unexpected token <
Uncaught TypeError: Cannot set property 'dir' of undefinedCKEDITOR.lang.load.f @ VM2040:212CKEDITOR.scriptLoader.load.g @ VM2040:214CKEDITOR.scriptLoader.load.l @ VM2040:214CKEDITOR.scriptLoader.load.s @ VM2040:214(anonymous function) @ VM2040:215
- I've tried other combinations, same result.
Expected result
Actual result
Other details (browser, OS, CKEditor version, installed plugins)
Using webpack, npm, bower, gulp (not much really): any solution that works for the stated goal is fine. I also have other heavy libs that most visitors don't need.
Tested on firefox and chromium, ckeditor 4.5.3, but it also happened with version 3, I don't recall the specific number.
Regards
Change History (2)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
My goodness! This time I wasn't loading the correct window.CKEDITOR_BASEPATH!! I fixed it, and it works!
Sorry for the inconvenience, and thanks a lot for releasing CKEEDITOR.