insertHtml.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var dialog = window.parent;
  2. var editorWindow = dialog.InnerDialogLoaded();
  3. var editorInstance = editorWindow.FCK;
  4. var FCKConfig = editorWindow.FCKConfig;
  5. var FCKTools = editorWindow.FCKTools;
  6. var FCKBrowserInfo = editorWindow.FCKBrowserInfo;
  7. // onload
  8. window.onload = function()
  9. {
  10. var description, snippet;
  11. // Show snippets to choose from
  12. if (typeof(FCKConfig.insertHtml_snippets) == 'object')
  13. {
  14. var snippetsDiv, snippetDiv, numberOfSnippets = 0;
  15. snippetsDiv = document.createElement('div');
  16. snippetsDiv.id = 'snippets';
  17. for (description in FCKConfig.insertHtml_snippets)
  18. {
  19. snippetDiv = document.createElement('div');
  20. snippetDiv.innerHTML = description;
  21. snippetDiv.className = 'snippet';
  22. snippetDiv.snippet = FCKConfig.insertHtml_snippets[description];
  23. snippetDiv.onmouseover = function(){this.className += ' PopupSelectionBox'};
  24. snippetDiv.onmouseout = function(){this.className = this.className.replace(/\s?PopupSelectionBox\s?/, '')};
  25. if (FCKConfig.insertHtml_showTextarea)
  26. {
  27. snippetDiv.onclick = function(){
  28. document.getElementById('insertHtmlTextArea').value = this.snippet;
  29. };
  30. }
  31. else
  32. {
  33. snippetDiv.onclick = function(){
  34. editorInstance.InsertHtml(this.snippet);
  35. editorWindow.FCKUndo.SaveUndoStep();
  36. dialog.CloseDialog();
  37. };
  38. }
  39. snippetsDiv.appendChild(snippetDiv);
  40. numberOfSnippets++;
  41. }
  42. document.getElementById('content').appendChild(snippetsDiv);
  43. // Load the dialog
  44. }
  45. // Show the textarea
  46. if (FCKConfig.insertHtml_showTextarea || !FCKConfig.insertHtml_snippets || !numberOfSnippets)
  47. {
  48. insertHtmlTextArea = document.createElement('textarea');
  49. insertHtmlTextArea.id = 'insertHtmlTextArea';
  50. document.getElementById('content').appendChild(insertHtmlTextArea);
  51. // Set the size of the textarea
  52. insertHtmlTextArea.style.width = (FCKConfig.insertHtml_textareaWidth || 400) + 'px';
  53. insertHtmlTextArea.style.height = (FCKConfig.insertHtml_textareaHeight || 300) + 'px';
  54. // Load default content
  55. if (typeof(FCKConfig.insertHtml_snippets) == 'object')
  56. {
  57. for (description in FCKConfig.insertHtml_snippets)
  58. {
  59. snippet = FCKConfig.insertHtml_snippets[description];
  60. break;
  61. }
  62. }
  63. else
  64. {
  65. //snippet = FCKConfig.insertHtml_snippets;//Chamilo replaced by below (by now)
  66. snippet = ''; // Insert your text here
  67. }
  68. insertHtmlTextArea.value = snippet;
  69. }
  70. // Resize around snippets and/or textarea
  71. // For IE this must be done before translating the dialog or the dialog will be to wide; also IE needs an approximate resize before autofitting or the dialog width will be to large
  72. //if (FCKBrowserInfo.IsIE) dialog.Sizer.ResizeDialog(parseInt(FCKConfig.insertHtml_textareaWidth || 400), parseInt(FCKConfig.insertHtml_textareaHeight || 300) + 130);
  73. dialog.SetAutoSize(true);
  74. // Recenter the dialog
  75. //setTimeout(function(){ // after a dummy delay, needed for webkit
  76. // var topWindowSize = FCKTools.GetViewPaneSize(dialog.top.window);
  77. // dialog.frameElement.style.left = Math.round((topWindowSize.Width - dialog.frameElement.offsetWidth) / 2) + 'px';
  78. // dialog.frameElement.style.top = Math.round((topWindowSize.Height - dialog.frameElement.offsetHeight) / 2).toString() + 'px';;
  79. //}, 0);
  80. // Translate the dialog box texts
  81. editorWindow.FCKLanguageManager.TranslatePage(document);
  82. // Activate the "OK" button
  83. dialog.SetOkButton(true);
  84. }
  85. // Dialog's 'ok' button function to insert the Html
  86. function Ok()
  87. {
  88. if (insertHtmlTextArea.value)
  89. {
  90. editorInstance.InsertHtml(insertHtmlTextArea.value);
  91. editorWindow.FCKUndo.SaveUndoStep();
  92. return true; // Makes the dialog to close
  93. }
  94. }