edit.ui.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. fileContentEditor = showContentEditor = null;
  2. window.initContentEditor = function()
  3. {
  4. require.config({
  5. paths: {vs: jsRoot + 'monaco-editor/min/vs'},
  6. 'vs/nls': {
  7. availableLanguages:{'*': clientLang}
  8. }
  9. });
  10. if(typeof(monaco) == 'object') return initMonacoEditor();
  11. require(['vs/editor/editor.main'], function (){initMonacoEditor()});
  12. }
  13. window.initMonacoEditor = function()
  14. {
  15. if(isShowContent)
  16. {
  17. showContentEditor = monaco.editor.create(document.getElementById('showContentEditor'),
  18. {
  19. value: showContent.toString(),
  20. language: language,
  21. readOnly: true,
  22. autoIndent: true,
  23. contextmenu: true,
  24. automaticLayout: true,
  25. minimap: {enabled: false},
  26. scrollBeyondLastLine: false,
  27. scrollbar: {
  28. verticalScrollbarSize: 10,
  29. horizontalScrollbarSize: 10
  30. }
  31. });
  32. }
  33. fileContentEditor = monaco.editor.create(document.getElementById('fileContentEditor'),
  34. {
  35. value: fileContent.toString(),
  36. language: language,
  37. readOnly: false,
  38. autoIndent: true,
  39. contextmenu: true,
  40. automaticLayout: true,
  41. minimap: {enabled: false},
  42. scrollBeyondLastLine: false,
  43. scrollbar: {
  44. verticalScrollbarSize: 10,
  45. horizontalScrollbarSize: 10
  46. }
  47. });
  48. setHeight();
  49. }
  50. window.syncFileContent = function()
  51. {
  52. $('#fileContent').val(fileContentEditor.getValue());
  53. };
  54. window.reloadExtendWin = function()
  55. {
  56. parent.$('#extendWin').attr('src', parent.$('#extendWin').data('url'));
  57. };
  58. window.setHeight = function()
  59. {
  60. let codeHeight = parent.$('#editWin').height();
  61. $('.panel').height(codeHeight);
  62. let headerHeight = $('.heading').height();
  63. let footerHeight = $('.form-actions').height();
  64. let nameBoxHeight = $('#fileNameBox').height() ? $('#fileNameBox').height() : 0;
  65. codeHeight -= headerHeight + footerHeight + nameBoxHeight + 52;
  66. if(isShowContent)
  67. {
  68. contentHeight = showContentEditor.getContentHeight();
  69. if(contentHeight > 300) contentHeight = 300;
  70. if(contentHeight < 200) contentHeight = 200;
  71. $('#showContentEditor').height(contentHeight);
  72. codeHeight -= contentHeight + 30;
  73. if(codeHeight < 300) codeHeight = 300;
  74. }
  75. $('#fileContentEditor').height(codeHeight - 70);
  76. };
  77. initContentEditor();
  78. setHeight();
  79. window.addEventListener('resize', function()
  80. {
  81. setHeight();
  82. });