plugin.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. /**
  6. * @file Plugin for inserting files from IMCE without image dialog
  7. */
  8. ( function() {
  9. CKEDITOR.plugins.add( 'imce',
  10. {
  11. init: function( editor )
  12. {
  13. //adding button
  14. editor.ui.addButton( 'IMCE',
  15. {
  16. label: 'IMCE',
  17. command: 'IMCEWindow',
  18. icon: this.path + 'images/icon.png'
  19. });
  20. //opening imce window
  21. editor.addCommand( 'IMCEWindow', {
  22. exec : function () {
  23. var width = editor.config.filebrowserWindowWidth || '80%',
  24. height = editor.config.filebrowserWindowHeight || '70%';
  25. editor.popup(Drupal.settings.basePath + 'index.php?q=imce\x26app=ckeditor|sendto@ckeditor_setFile|&CKEditorFuncNum=' + editor._.filebrowserFnIMCE, width, height);
  26. }
  27. });
  28. //add editor function
  29. editor._.filebrowserFnIMCE = CKEDITOR.tools.addFunction( setFile, editor );
  30. //function which receive imce response
  31. window.ckeditor_setFile = function (file, win) {
  32. var cfunc = win.location.href.split('&');
  33. for (var x in cfunc) {
  34. if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) {
  35. cfunc = cfunc[x].split('=');
  36. break;
  37. }
  38. }
  39. CKEDITOR.tools.callFunction(cfunc[1], file);
  40. win.close();
  41. };
  42. }
  43. } );
  44. function setFile(file) {
  45. var sel = this.getSelection(),
  46. text = sel.getSelectedText();
  47. if (file.width != 0 && file.height != 0) {
  48. if (text) {
  49. this.insertHtml('<a href="' + document.location.protocol + '//'+ document.location.host + file.url + '">' + text + '</a>');
  50. } else {
  51. this.insertHtml('<img src="' + file.url + '" style="width:' + file.width + 'px;height:' + file.height + 'px;" alt="' + file.name + '" />');
  52. }
  53. } else {
  54. if (text) {
  55. this.insertHtml('<a href="' +document.location.protocol + '//'+ document.location.host + file.url + '">' + text + '</a>');
  56. } else {
  57. this.insertHtml('<a href="' + document.location.protocol + '//'+ document.location.host + file.url + '">' + file.name + '</a>');
  58. }
  59. }
  60. }
  61. } )();