Access bootstrap and CodeMirror globals from window object

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2022-06-30 17:32:28 -03:00
parent 084c21103b
commit f7addc22e4
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
12 changed files with 28 additions and 30 deletions

View File

@ -15,8 +15,6 @@
"jquery": true
},
"globals": {
"bootstrap": "readonly",
"CodeMirror": "readonly",
"Cookies": "readonly",
"Functions": "readonly",
"Messages": "readonly",

View File

@ -1,4 +1,4 @@
CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
window.CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
// Skipping check if text box is empty.
if (text.trim() === '') {
updateLinting(cm, []);
@ -10,11 +10,11 @@ CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
for (var idx in response) {
found.push({
// eslint-disable-next-line new-cap
from: CodeMirror.Pos(
from: window.CodeMirror.Pos(
response[idx].fromLine, response[idx].fromColumn
),
// eslint-disable-next-line new-cap
to: CodeMirror.Pos(
to: window.CodeMirror.Pos(
response[idx].toLine, response[idx].toColumn
),
messageHTML: response[idx].message,

View File

@ -156,7 +156,7 @@ const DatabaseEvents = {
that.buttonOptions[Messages.strGo] = function () {
// Move the data from the codemirror editor back to the
// textarea, where it can be used in the form submission.
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
that.syntaxHiglighter.save();
}
// Validate editor and submit request, if passed.

View File

@ -171,7 +171,7 @@ const DatabaseRoutines = {
that.buttonOptions[Messages.strGo] = function () {
// Move the data from the codemirror editor back to the
// textarea, where it can be used in the form submission.
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
that.syntaxHiglighter.save();
}
// Validate editor and submit request, if passed.

View File

@ -165,7 +165,7 @@ const DatabaseTriggers = {
that.buttonOptions[Messages.strGo] = function () {
// Move the data from the codemirror editor back to the
// textarea, where it can be used in the form submission.
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
that.syntaxHiglighter.save();
}
// Validate editor and submit request, if passed.

View File

@ -277,7 +277,7 @@ Functions.handleRedirectAndReload = function (data) {
*/
Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
var resizeType = resize;
if ($textarea.length > 0 && typeof CodeMirror !== 'undefined') {
if ($textarea.length > 0 && typeof window.CodeMirror !== 'undefined') {
// merge options for CodeMirror
var defaults = {
lineNumbers: true,
@ -289,11 +289,11 @@ Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
lineWrapping: true
};
if (CodeMirror.sqlLint) {
if (window.CodeMirror.sqlLint) {
$.extend(defaults, {
gutters: ['CodeMirror-lint-markers'],
lint: {
'getAnnotations': CodeMirror.sqlLint,
'getAnnotations': window.CodeMirror.sqlLint,
'async': true,
'lintOptions': lintOptions
}
@ -303,7 +303,7 @@ Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
$.extend(true, defaults, options);
// create CodeMirror editor
var codemirrorEditor = CodeMirror.fromTextArea($textarea[0], defaults);
var codemirrorEditor = window.CodeMirror.fromTextArea($textarea[0], defaults);
// allow resizing
if (! resizeType) {
resizeType = 'vertical';
@ -1374,7 +1374,7 @@ Functions.codeMirrorAutoCompleteOnInputRead = function (instance) {
string = token.string;
}
if (string.length > 0) {
CodeMirror.commands.autocomplete(instance);
window.CodeMirror.commands.autocomplete(instance);
}
};
@ -1389,7 +1389,7 @@ Functions.removeAutocompleteInfo = () => {
Functions.bindCodeMirrorToInlineEditor = function () {
var $inlineEditor = $('#sql_query_edit');
if ($inlineEditor.length > 0) {
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
var height = $inlineEditor.css('height');
codeMirrorInlineEditor = Functions.getSqlEditor($inlineEditor);
codeMirrorInlineEditor.getWrapperElement().style.height = height;
@ -1504,8 +1504,8 @@ Functions.highlightSql = function ($base) {
if ($pre.is(':visible')) {
var $highlight = $('<div class="sql-highlight cm-s-default"></div>');
$sql.append($highlight);
if (typeof CodeMirror !== 'undefined') {
CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
if (typeof window.CodeMirror !== 'undefined') {
window.CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
$pre.hide();
$highlight.find('.cm-keyword').each(Functions.documentationKeyword);
$highlight.find('.cm-builtin').each(Functions.documentationBuiltin);
@ -1553,9 +1553,9 @@ Functions.updateCode = function ($base, htmlValue, rawValue) {
var $notHighlighted = $('<pre>' + htmlValue + '</pre>');
// Tries to highlight code using CodeMirror.
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
var $highlighted = $('<div class="' + type + '-highlight cm-s-default"></div>');
CodeMirror.runMode(rawValue, mode, $highlighted[0]);
window.CodeMirror.runMode(rawValue, mode, $highlighted[0]);
$notHighlighted.hide();
$code.html('').append($notHighlighted, $highlighted[0]);
} else {
@ -2025,12 +2025,12 @@ Functions.prettyProfilingNum = function (number, accuracy) {
* @return {string} The formatted query
*/
Functions.sqlPrettyPrint = function (string) {
if (typeof CodeMirror === 'undefined') {
if (typeof window.CodeMirror === 'undefined') {
return string;
}
var mode = CodeMirror.getMode({}, 'text/x-mysql');
var stream = new CodeMirror.StringStream(string);
var mode = window.CodeMirror.getMode({}, 'text/x-mysql');
var stream = new window.CodeMirror.StringStream(string);
var state = mode.startState();
var token;
var tokens = [];
@ -3631,7 +3631,7 @@ Functions.onloadCodeMirrorEditor = () => {
return;
}
if ($elm.length > 0) {
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
window.codeMirrorEditor = Functions.getSqlEditor($elm);
window.codeMirrorEditor.focus();
window.codeMirrorEditor.on('blur', Functions.updateQueryParameters);
@ -3788,7 +3788,7 @@ Functions.createViewModal = function ($this) {
if (typeof data !== 'undefined' && data.success === true) {
Functions.ajaxRemoveMessage($msg);
$('#createViewModalGoButton').on('click', function () {
if (typeof CodeMirror !== 'undefined') {
if (typeof window.CodeMirror !== 'undefined') {
window.codeMirrorEditor.save();
}
$msg = Functions.ajaxShowMessage();

View File

@ -50,7 +50,7 @@ const EditUserGroup = {
return;
}
const modal = bootstrap.Modal.getInstance(editUserGroupModal);
const modal = window.bootstrap.Modal.getInstance(editUserGroupModal);
const modalBody = editUserGroupModal.querySelector('.modal-body');
const saveButton = editUserGroupModal.querySelector('#editUserGroupModalSaveButton');

View File

@ -140,8 +140,8 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
// Codemirror is loaded on demand so we might need to initialize it
if (! window.codeMirrorEditor) {
var $elm = $('#sqlquery');
if ($elm.length > 0 && typeof CodeMirror !== 'undefined') {
window.codeMirrorEditor = CodeMirror.fromTextArea(
if ($elm.length > 0 && typeof window.CodeMirror !== 'undefined') {
window.codeMirrorEditor = window.CodeMirror.fromTextArea(
$elm[0],
{
lineNumbers: true,

View File

@ -10,7 +10,7 @@ window.AJAX.registerOnload('transformations/json.js', function () {
if ($pre.is(':visible')) {
var $highlight = $('<div class="json-highlight cm-s-default"></div>');
$json.append($highlight);
CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
window.CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
$pre.hide();
}
});

View File

@ -5,7 +5,7 @@
*/
window.AJAX.registerOnload('transformations/json_editor.js', function () {
$('textarea.transform_json_editor').each(function () {
CodeMirror.fromTextArea(this, {
window.CodeMirror.fromTextArea(this, {
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,

View File

@ -10,7 +10,7 @@ window.AJAX.registerOnload('transformations/xml.js', function () {
if ($pre.is(':visible')) {
var $highlight = $('<div class="xml-highlight cm-s-default"></div>');
$json.append($highlight);
CodeMirror.runMode($json.text(), 'application/xml', $highlight[0]);
window.CodeMirror.runMode($json.text(), 'application/xml', $highlight[0]);
$pre.hide();
}
});

View File

@ -5,7 +5,7 @@
*/
window.AJAX.registerOnload('transformations/xml_editor.js', function () {
$('textarea.transform_xml_editor').each(function () {
CodeMirror.fromTextArea(this, {
window.CodeMirror.fromTextArea(this, {
lineNumbers: true,
indentUnit: 4,
mode: 'application/xml',