Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- initEditor: function (cont) {
- var langtemp = $(cont).attr("data-type");
- function loadLib(options) {
- if (!options.conditionObject) {
- if (options.csslink) {
- $('head').append('<link href="' + options.csslink + '" rel="stylesheet" />');
- }
- return $.ajax({
- dataType: "script",
- cache: options.isCacheable ? options.isCacheable : false,
- url: options.jslink,
- success: function () {
- if (options.callback) options.callback();
- }
- });
- } else {
- return new Promise(function (resolve) { if (options.callback) options.callback(); resolve(true); });
- }
- }
- var loadLint = false;
- function f() {
- // cont.attr('title', '123132')
- var item = $(cont);
- var editorInModal = item.closest('.modal').length > 0;
- var id = item.attr("id");
- if (item.attr("disableSearchButton") !== "1") {
- if (!item.prev().is(".as-codeEditorFind")) {
- $("<a href='#' class='as-codeEditorFind btn btn-light btn-sm' data-itemID='" + id + "' " +
- " title='Ctrl+F - Search, Ctrl+G - Next, Ctrl+Shift+G - Prev'><i class='fa fa-search'></i></a>").insertBefore(item);
- }
- }
- var height = item.attr('data-height');
- var lang = "";
- if (langtemp === "SQL")
- lang = "text/x-mssql";
- else if (langtemp === "JS")
- lang = "javascript";
- else if (langtemp === "CSS")
- lang = "text/x-scss";
- else if (langtemp === "HTML")
- lang = "text/html";
- else
- lang = langtemp;
- var theme = item.attr("data-theme");
- var editor = CodeMirror.fromTextArea(item[0], {
- lineNumbers: true,
- readOnly: $(cont).attr("disabled")==="disabled",
- autoRefresh: true,
- lineWrapping: false,
- lint: langtemp !== "SQL",
- extraKeys: {
- "Ctrl-Q": function (cm) {
- cm.foldCode(cm.getCursor());
- },
- "Ctrl-F11": function (cm) {
- cm.setOption("fullScreen", !cm.getOption("fullScreen"));
- },
- "Esc": function (cm) {
- if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
- }
- },
- foldGutter: true,
- gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
- mode: lang,
- theme: theme
- });
- editor.on("change", function () {
- if (editorInModal) {
- as.ark && as.ark.setNotSaveModalState(true);
- } else {
- as.ark && as.ark.setNotSavePageState(true);
- }
- });
- if (height) editor.setSize(null, height);
- setTimeout(function () {
- editor.refresh();
- }, 50);
- var pair = { id: id, editor: editor };
- as.codeEditor.items.push(pair);
- }
- var loading = loadLib({
- jslink: "/js/codeMirrorCustom.min.js",
- csslink: "/js/codeMirrorCustom.min.css",
- conditionObject: window.CodeMirror,
- isCacheable: true
- });
- if (!loadLint || langtemp === "SQL") {
- loading.then(function () {
- setTimeout(f, 50);
- });
- } else {
- loading.then(function () {
- return loadLib({
- jslink: "/js/codemirror/addon/lint/lint.js",
- csslink: "/js/codemirror/addon/lint/lint.css",
- conditionObject: window.CodeMirror.lint,
- isCacheable: true
- });
- }).then(function () {
- var promises = [];
- promises.push(function () { });
- if (langtemp === "JS") {
- promises.push(loadLib({
- jslink: "https://unpkg.com/jshint@2.9.6/dist/jshint.js",
- conditionObject: window.JSHINT,
- isCacheable: true
- }));
- }
- if (langtemp === "CSS") {
- promises.push(loadLib({
- jslink: "https://unpkg.com/csslint@1.0.5/dist/csslint.js",
- conditionObject: window.CSSLint,
- isCacheable: true
- }));
- }
- if (langtemp === "HTML") {
- promises.push(loadLib({
- jslink: "https://unpkg.com/htmlhint@0.14.2/dist/htmlhint.js",
- conditionObject: window.HTMLHint,
- isCacheable: true
- }));
- }
- return Promise.all(promises);
- }).then(function () {
- var promises = [];
- promises.push(function () { });
- if (langtemp === "CSS") {
- promises.push(loadLib({
- jslink: "/js/codemirror/addon/lint/css-lint.js",
- conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.css,
- isCacheable: true
- }));
- }
- if (langtemp === "HTML") {
- promises.push(loadLib({
- jslink: "/js/codemirror/addon/lint/html-lint.js",
- conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.html,
- isCacheable: true
- }));
- }
- if (langtemp === "JS") {
- promises.push(loadLib({
- jslink: "/js/codemirror/addon/lint/javascript-lint.js",
- conditionObject: window.CodeMirror.lint && window.CodeMirror.lint.javascript,
- isCacheable: true
- }));
- }
- return Promise.all(promises);
- }).then(function () {
- setTimeout(f, 50);
- });
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement