Advertisement
hecrus

Untitled

Jul 8th, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. initEditor: function (cont) {
  2. var langtemp = $(cont).attr("data-type");
  3. function loadLib(options) {
  4. if (!options.conditionObject) {
  5. if (options.csslink) {
  6. $('head').append('<link href="' + options.csslink + '" rel="stylesheet" />');
  7. }
  8. return $.ajax({
  9. dataType: "script",
  10. cache: options.isCacheable ? options.isCacheable : false,
  11. url: options.jslink,
  12. success: function () {
  13. if (options.callback) options.callback();
  14. }
  15. });
  16. } else {
  17. return new Promise(function (resolve) { if (options.callback) options.callback(); resolve(true); });
  18. }
  19. }
  20.  
  21. var loadLint = false;
  22.  
  23. function f() {
  24.  
  25. // cont.attr('title', '123132')
  26. var item = $(cont);
  27. var editorInModal = item.closest('.modal').length > 0;
  28.  
  29. var id = item.attr("id");
  30. if (item.attr("disableSearchButton") !== "1") {
  31. if (!item.prev().is(".as-codeEditorFind")) {
  32. $("<a href='#' class='as-codeEditorFind btn btn-light btn-sm' data-itemID='" + id + "' " +
  33. " title='Ctrl+F - Search, Ctrl+G - Next, Ctrl+Shift+G - Prev'><i class='fa fa-search'></i></a>").insertBefore(item);
  34. }
  35. }
  36. var height = item.attr('data-height');
  37.  
  38. var lang = "";
  39. if (langtemp === "SQL")
  40. lang = "text/x-mssql";
  41. else if (langtemp === "JS")
  42. lang = "javascript";
  43. else if (langtemp === "CSS")
  44. lang = "text/x-scss";
  45. else if (langtemp === "HTML")
  46. lang = "text/html";
  47. else
  48. lang = langtemp;
  49. var theme = item.attr("data-theme");
  50. var editor = CodeMirror.fromTextArea(item[0], {
  51. lineNumbers: true,
  52. readOnly: $(cont).attr("disabled")==="disabled",
  53. autoRefresh: true,
  54. lineWrapping: false,
  55. lint: langtemp !== "SQL",
  56. extraKeys: {
  57. "Ctrl-Q": function (cm) {
  58. cm.foldCode(cm.getCursor());
  59. },
  60. "Ctrl-F11": function (cm) {
  61. cm.setOption("fullScreen", !cm.getOption("fullScreen"));
  62. },
  63. "Esc": function (cm) {
  64. if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
  65. }
  66. },
  67. foldGutter: true,
  68. gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
  69. mode: lang,
  70. theme: theme
  71. });
  72. editor.on("change", function () {
  73.  
  74. if (editorInModal) {
  75. as.ark && as.ark.setNotSaveModalState(true);
  76. } else {
  77. as.ark && as.ark.setNotSavePageState(true);
  78. }
  79.  
  80. });
  81. if (height) editor.setSize(null, height);
  82. setTimeout(function () {
  83. editor.refresh();
  84. }, 50);
  85. var pair = { id: id, editor: editor };
  86. as.codeEditor.items.push(pair);
  87. }
  88.  
  89. var loading = loadLib({
  90. jslink: "/js/codeMirrorCustom.min.js",
  91. csslink: "/js/codeMirrorCustom.min.css",
  92. conditionObject: window.CodeMirror,
  93. isCacheable: true
  94. });
  95.  
  96. if (!loadLint || langtemp === "SQL") {
  97. loading.then(function () {
  98. setTimeout(f, 50);
  99. });
  100.  
  101. } else {
  102. loading.then(function () {
  103. return loadLib({
  104. jslink: "/js/codemirror/addon/lint/lint.js",
  105. csslink: "/js/codemirror/addon/lint/lint.css",
  106. conditionObject: window.CodeMirror.lint,
  107. isCacheable: true
  108. });
  109. }).then(function () {
  110. var promises = [];
  111. promises.push(function () { });
  112. if (langtemp === "JS") {
  113. promises.push(loadLib({
  114. jslink: "https://unpkg.com/jshint@2.9.6/dist/jshint.js",
  115. conditionObject: window.JSHINT,
  116. isCacheable: true
  117. }));
  118. }
  119. if (langtemp === "CSS") {
  120. promises.push(loadLib({
  121. jslink: "https://unpkg.com/csslint@1.0.5/dist/csslint.js",
  122. conditionObject: window.CSSLint,
  123. isCacheable: true
  124. }));
  125. }
  126. if (langtemp === "HTML") {
  127. promises.push(loadLib({
  128. jslink: "https://unpkg.com/htmlhint@0.14.2/dist/htmlhint.js",
  129. conditionObject: window.HTMLHint,
  130. isCacheable: true
  131. }));
  132. }
  133.  
  134. return Promise.all(promises);
  135. }).then(function () {
  136. var promises = [];
  137. promises.push(function () { });
  138. if (langtemp === "CSS") {
  139. promises.push(loadLib({
  140. jslink: "/js/codemirror/addon/lint/css-lint.js",
  141. conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.css,
  142. isCacheable: true
  143. }));
  144. }
  145.  
  146. if (langtemp === "HTML") {
  147. promises.push(loadLib({
  148. jslink: "/js/codemirror/addon/lint/html-lint.js",
  149. conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.html,
  150. isCacheable: true
  151. }));
  152. }
  153. if (langtemp === "JS") {
  154. promises.push(loadLib({
  155. jslink: "/js/codemirror/addon/lint/javascript-lint.js",
  156. conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.javascript,
  157. isCacheable: true
  158. }));
  159. }
  160.  
  161. return Promise.all(promises);
  162. }).then(function () {
  163. setTimeout(f, 50);
  164. });
  165. }
  166.  
  167.  
  168. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement