ckeditor.callback.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * elFinder Integration
  3. *
  4. * Copyright (c) 2010-2019, Alexey Sukhotin. All rights reserved.
  5. */
  6. function elfinder_ckeditor_callback(arg1) {
  7. var url = arg1;
  8. if (typeof arg1 == 'object') {
  9. url = arg1.url;
  10. }
  11. funcNum = window.location.search.replace(/^.*CKEditorFuncNum=(\d+).*$/, "$1");
  12. window.opener.CKEDITOR.tools.callFunction(funcNum, url, function() {
  13. // adapted from http://docs.ckeditor.com/#!/guide/dev_file_browser_api
  14. var dialog = this.getDialog();
  15. if (dialog.getName() == 'link') {
  16. var element = dialog.getContentElement('info', 'linkDisplayText');
  17. var display_text = null;
  18. if (element) {
  19. display_text = element.getValue();
  20. }
  21. // If display text is blank, insert the filename.
  22. if (element && !display_text) {
  23. element.setValue(arg1.name);
  24. }
  25. }
  26. });
  27. // Avoid beforeunload event when selecting an image.
  28. // See https://github.com/Studio-42/elFinder/issues/1340
  29. // Maybe remove this when elfinder js library gets updated.
  30. jQuery(window).off('beforeunload');
  31. window.close();
  32. }