Skip to content

Commit f7addc2

Browse files
committed
Access bootstrap and CodeMirror globals from window object
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 084c211 commit f7addc2

12 files changed

Lines changed: 28 additions & 30 deletions

File tree

.eslintrc.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
"jquery": true
1616
},
1717
"globals": {
18-
"bootstrap": "readonly",
19-
"CodeMirror": "readonly",
2018
"Cookies": "readonly",
2119
"Functions": "readonly",
2220
"Messages": "readonly",

js/src/codemirror/addon/lint/sql-lint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
1+
window.CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
22
// Skipping check if text box is empty.
33
if (text.trim() === '') {
44
updateLinting(cm, []);
@@ -10,11 +10,11 @@ CodeMirror.sqlLint = function (text, updateLinting, options, cm) {
1010
for (var idx in response) {
1111
found.push({
1212
// eslint-disable-next-line new-cap
13-
from: CodeMirror.Pos(
13+
from: window.CodeMirror.Pos(
1414
response[idx].fromLine, response[idx].fromColumn
1515
),
1616
// eslint-disable-next-line new-cap
17-
to: CodeMirror.Pos(
17+
to: window.CodeMirror.Pos(
1818
response[idx].toLine, response[idx].toColumn
1919
),
2020
messageHTML: response[idx].message,

js/src/database/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const DatabaseEvents = {
156156
that.buttonOptions[Messages.strGo] = function () {
157157
// Move the data from the codemirror editor back to the
158158
// textarea, where it can be used in the form submission.
159-
if (typeof CodeMirror !== 'undefined') {
159+
if (typeof window.CodeMirror !== 'undefined') {
160160
that.syntaxHiglighter.save();
161161
}
162162
// Validate editor and submit request, if passed.

js/src/database/routines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const DatabaseRoutines = {
171171
that.buttonOptions[Messages.strGo] = function () {
172172
// Move the data from the codemirror editor back to the
173173
// textarea, where it can be used in the form submission.
174-
if (typeof CodeMirror !== 'undefined') {
174+
if (typeof window.CodeMirror !== 'undefined') {
175175
that.syntaxHiglighter.save();
176176
}
177177
// Validate editor and submit request, if passed.

js/src/database/triggers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const DatabaseTriggers = {
165165
that.buttonOptions[Messages.strGo] = function () {
166166
// Move the data from the codemirror editor back to the
167167
// textarea, where it can be used in the form submission.
168-
if (typeof CodeMirror !== 'undefined') {
168+
if (typeof window.CodeMirror !== 'undefined') {
169169
that.syntaxHiglighter.save();
170170
}
171171
// Validate editor and submit request, if passed.

js/src/functions.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Functions.handleRedirectAndReload = function (data) {
277277
*/
278278
Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
279279
var resizeType = resize;
280-
if ($textarea.length > 0 && typeof CodeMirror !== 'undefined') {
280+
if ($textarea.length > 0 && typeof window.CodeMirror !== 'undefined') {
281281
// merge options for CodeMirror
282282
var defaults = {
283283
lineNumbers: true,
@@ -289,11 +289,11 @@ Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
289289
lineWrapping: true
290290
};
291291

292-
if (CodeMirror.sqlLint) {
292+
if (window.CodeMirror.sqlLint) {
293293
$.extend(defaults, {
294294
gutters: ['CodeMirror-lint-markers'],
295295
lint: {
296-
'getAnnotations': CodeMirror.sqlLint,
296+
'getAnnotations': window.CodeMirror.sqlLint,
297297
'async': true,
298298
'lintOptions': lintOptions
299299
}
@@ -303,7 +303,7 @@ Functions.getSqlEditor = function ($textarea, options, resize, lintOptions) {
303303
$.extend(true, defaults, options);
304304

305305
// create CodeMirror editor
306-
var codemirrorEditor = CodeMirror.fromTextArea($textarea[0], defaults);
306+
var codemirrorEditor = window.CodeMirror.fromTextArea($textarea[0], defaults);
307307
// allow resizing
308308
if (! resizeType) {
309309
resizeType = 'vertical';
@@ -1374,7 +1374,7 @@ Functions.codeMirrorAutoCompleteOnInputRead = function (instance) {
13741374
string = token.string;
13751375
}
13761376
if (string.length > 0) {
1377-
CodeMirror.commands.autocomplete(instance);
1377+
window.CodeMirror.commands.autocomplete(instance);
13781378
}
13791379
};
13801380

@@ -1389,7 +1389,7 @@ Functions.removeAutocompleteInfo = () => {
13891389
Functions.bindCodeMirrorToInlineEditor = function () {
13901390
var $inlineEditor = $('#sql_query_edit');
13911391
if ($inlineEditor.length > 0) {
1392-
if (typeof CodeMirror !== 'undefined') {
1392+
if (typeof window.CodeMirror !== 'undefined') {
13931393
var height = $inlineEditor.css('height');
13941394
codeMirrorInlineEditor = Functions.getSqlEditor($inlineEditor);
13951395
codeMirrorInlineEditor.getWrapperElement().style.height = height;
@@ -1504,8 +1504,8 @@ Functions.highlightSql = function ($base) {
15041504
if ($pre.is(':visible')) {
15051505
var $highlight = $('<div class="sql-highlight cm-s-default"></div>');
15061506
$sql.append($highlight);
1507-
if (typeof CodeMirror !== 'undefined') {
1508-
CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
1507+
if (typeof window.CodeMirror !== 'undefined') {
1508+
window.CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
15091509
$pre.hide();
15101510
$highlight.find('.cm-keyword').each(Functions.documentationKeyword);
15111511
$highlight.find('.cm-builtin').each(Functions.documentationBuiltin);
@@ -1553,9 +1553,9 @@ Functions.updateCode = function ($base, htmlValue, rawValue) {
15531553
var $notHighlighted = $('<pre>' + htmlValue + '</pre>');
15541554

15551555
// Tries to highlight code using CodeMirror.
1556-
if (typeof CodeMirror !== 'undefined') {
1556+
if (typeof window.CodeMirror !== 'undefined') {
15571557
var $highlighted = $('<div class="' + type + '-highlight cm-s-default"></div>');
1558-
CodeMirror.runMode(rawValue, mode, $highlighted[0]);
1558+
window.CodeMirror.runMode(rawValue, mode, $highlighted[0]);
15591559
$notHighlighted.hide();
15601560
$code.html('').append($notHighlighted, $highlighted[0]);
15611561
} else {
@@ -2025,12 +2025,12 @@ Functions.prettyProfilingNum = function (number, accuracy) {
20252025
* @return {string} The formatted query
20262026
*/
20272027
Functions.sqlPrettyPrint = function (string) {
2028-
if (typeof CodeMirror === 'undefined') {
2028+
if (typeof window.CodeMirror === 'undefined') {
20292029
return string;
20302030
}
20312031

2032-
var mode = CodeMirror.getMode({}, 'text/x-mysql');
2033-
var stream = new CodeMirror.StringStream(string);
2032+
var mode = window.CodeMirror.getMode({}, 'text/x-mysql');
2033+
var stream = new window.CodeMirror.StringStream(string);
20342034
var state = mode.startState();
20352035
var token;
20362036
var tokens = [];
@@ -3631,7 +3631,7 @@ Functions.onloadCodeMirrorEditor = () => {
36313631
return;
36323632
}
36333633
if ($elm.length > 0) {
3634-
if (typeof CodeMirror !== 'undefined') {
3634+
if (typeof window.CodeMirror !== 'undefined') {
36353635
window.codeMirrorEditor = Functions.getSqlEditor($elm);
36363636
window.codeMirrorEditor.focus();
36373637
window.codeMirrorEditor.on('blur', Functions.updateQueryParameters);
@@ -3788,7 +3788,7 @@ Functions.createViewModal = function ($this) {
37883788
if (typeof data !== 'undefined' && data.success === true) {
37893789
Functions.ajaxRemoveMessage($msg);
37903790
$('#createViewModalGoButton').on('click', function () {
3791-
if (typeof CodeMirror !== 'undefined') {
3791+
if (typeof window.CodeMirror !== 'undefined') {
37923792
window.codeMirrorEditor.save();
37933793
}
37943794
$msg = Functions.ajaxShowMessage();

js/src/server/privileges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const EditUserGroup = {
5050
return;
5151
}
5252

53-
const modal = bootstrap.Modal.getInstance(editUserGroupModal);
53+
const modal = window.bootstrap.Modal.getInstance(editUserGroupModal);
5454
const modalBody = editUserGroupModal.querySelector('.modal-body');
5555
const saveButton = editUserGroupModal.querySelector('#editUserGroupModalSaveButton');
5656

js/src/server/status/monitor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
140140
// Codemirror is loaded on demand so we might need to initialize it
141141
if (! window.codeMirrorEditor) {
142142
var $elm = $('#sqlquery');
143-
if ($elm.length > 0 && typeof CodeMirror !== 'undefined') {
144-
window.codeMirrorEditor = CodeMirror.fromTextArea(
143+
if ($elm.length > 0 && typeof window.CodeMirror !== 'undefined') {
144+
window.codeMirrorEditor = window.CodeMirror.fromTextArea(
145145
$elm[0],
146146
{
147147
lineNumbers: true,

js/src/transformations/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ window.AJAX.registerOnload('transformations/json.js', function () {
1010
if ($pre.is(':visible')) {
1111
var $highlight = $('<div class="json-highlight cm-s-default"></div>');
1212
$json.append($highlight);
13-
CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
13+
window.CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
1414
$pre.hide();
1515
}
1616
});

js/src/transformations/json_editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
window.AJAX.registerOnload('transformations/json_editor.js', function () {
77
$('textarea.transform_json_editor').each(function () {
8-
CodeMirror.fromTextArea(this, {
8+
window.CodeMirror.fromTextArea(this, {
99
lineNumbers: true,
1010
matchBrackets: true,
1111
indentUnit: 4,

0 commit comments

Comments
 (0)