Skip to content

Commit 8b841d2

Browse files
committed
Access JS globals from window object
Fixes TS2304 errors. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent a997d90 commit 8b841d2

19 files changed

Lines changed: 71 additions & 114 deletions

js/src/designer/history.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { DesignerConfig } from './config.ts';
1010
* @requires move.js
1111
*/
1212

13-
/* global themeImagePath */ // templates/javascript/variables.twig
14-
1513
var DesignerHistory = {};
1614

1715
/**
@@ -103,9 +101,9 @@ DesignerHistory.display = function (init, finit) {
103101
str += '<div class="block"> <table class="table table-sm w-auto mb-0">';
104102
str += '<thead><tr><td>';
105103
if (DesignerHistory.historyArray[i].getAndOr()) {
106-
str += '<img src="' + themeImagePath + 'designer/or_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="OR"></td>';
104+
str += '<img src="' + window.themeImagePath + 'designer/or_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="OR"></td>';
107105
} else {
108-
str += '<img src="' + themeImagePath + 'designer/and_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="AND"></td>';
106+
str += '<img src="' + window.themeImagePath + 'designer/and_icon.png" onclick="DesignerHistory.andOr(' + i + ')" title="AND"></td>';
109107
}
110108
str += '<td style="padding-left: 5px;" class="text-end">' + getImageTag('b_sbrowse', window.Messages.strColumnName) + '</td>' +
111109
'<td width="175" style="padding-left: 5px">' + $('<div/>').text(DesignerHistory.historyArray[i].getColumnName()).html() + '<td>';

js/src/designer/move.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { DesignerHistory } from './history.ts';
99
import { DesignerPage } from './page.ts';
1010
import { DesignerConfig } from './config.ts';
1111

12-
/* global themeImagePath */ // templates/javascript/variables.twig
13-
1412
var DesignerMove = {};
1513

1614
var change = 0; // variable to track any change in designer layout.
@@ -566,7 +564,7 @@ DesignerMove.addTableToTablesList = function (index, tableDom) {
566564
' db="' + dbEncoded + '"' +
567565
' table_name="' + tableEncoded + '"' +
568566
' class="scroll_tab_struct"' +
569-
' src="' + themeImagePath + 'designer/exec.png"/>' +
567+
' src="' + window.themeImagePath + 'designer/exec.png"/>' +
570568
' </td>' +
571569
' <td width="1px">' +
572570
' <input class="scroll_tab_checkbox"' +

js/src/gis_data_editor.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import { ajaxShowMessage } from './modules/ajax-message.ts';
1010
*
1111
*/
1212

13-
/* global addZoomPanControllers, storeGisSvgRef, selectVisualization, styleOSM, zoomAndPan */ // js/table/gis_visualization.js
14-
/* global themeImagePath */ // templates/javascript/variables.twig
15-
1613
window.gisEditorLoaded = false;
1714

1815
/**
@@ -76,14 +73,14 @@ function addDataPoint (pointNumber, prefix) {
7673
* Initialize the visualization in the GIS data editor.
7774
*/
7875
function initGISEditorVisualization () {
79-
storeGisSvgRef();
76+
window.storeGisSvgRef();
8077
// Loads either SVG or OSM visualization based on the choice
81-
selectVisualization();
78+
window.selectVisualization();
8279
// Adds necessary styles to the div that contains the openStreetMap
83-
styleOSM();
80+
window.styleOSM();
8481
// Adds controllers for zooming and panning
85-
addZoomPanControllers();
86-
zoomAndPan();
82+
window.addZoomPanControllers();
83+
window.zoomAndPan();
8784
}
8885

8986
/**
@@ -181,7 +178,7 @@ function openGISEditor () {
181178
$gisEditor.append(
182179
'<div id="gis_data_editor">' +
183180
'<img class="ajaxIcon" id="loadingMonitorIcon" src="' +
184-
themeImagePath + 'ajax_clock_small.gif" alt="">' +
181+
window.themeImagePath + 'ajax_clock_small.gif" alt="">' +
185182
'</div>'
186183
);
187184

js/src/import.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { Navigation } from './modules/navigation.ts';
55
import { CommonParams } from './modules/common.ts';
66
import { ajaxShowMessage } from './modules/ajax-message.ts';
77

8-
/* global themeImagePath */ // templates/javascript/variables.twig
9-
108
/**
119
* Functions used in the import tab
1210
*
@@ -171,7 +169,7 @@ AJAX.registerOnload('import.js', function () {
171169

172170
$('#upload_form_form').css('display', 'none');
173171

174-
const clockImage = '<img src="' + themeImagePath + 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock">';
172+
const clockImage = '<img src="' + window.themeImagePath + 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock">';
175173

176174
if (handler !== 'PhpMyAdmin\\Plugins\\Import\\Upload\\UploadNoplugin') {
177175
var finished = false;

js/src/makegrid.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import highlightSql from './modules/sql-highlight.ts';
77
import { ajaxShowMessage } from './modules/ajax-message.ts';
88
import { escapeHtml } from './modules/functions/escape.ts';
99

10-
/* global Sql */
11-
/* global firstDayOfCalendar */ // templates/javascript/variables.twig
12-
1310
/**
1411
* Create advanced table (resize, reorder, and show/hide columns; and also grid editing).
1512
* This function is designed mainly for table DOM generated from browsing a table in the database.
@@ -797,9 +794,9 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
797794
var whereClause = $td.parent('tr').find('.where_clause').val();
798795
/**
799796
* @var fieldName String containing the name of this field.
800-
* @see Sql.getFieldName()
797+
* @see window.Sql.getFieldName()
801798
*/
802-
var fieldName = Sql.getFieldName($(t), $td);
799+
var fieldName = window.Sql.getFieldName($(t), $td);
803800
/**
804801
* @var relationCurrValue String current value of the field (for fields that are foreign keyed).
805802
*/
@@ -1109,7 +1106,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
11091106
showMillisec: showMillisec,
11101107
showMicrosec: showMicrosec,
11111108
timeFormat: timeFormat,
1112-
firstDay: firstDayOfCalendar
1109+
firstDay: window.firstDayOfCalendar
11131110
});
11141111

11151112
$inputField.on('keyup', function (e) {
@@ -1244,9 +1241,9 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
12441241

12451242
/**
12461243
* @var fieldName String containing the name of this field.
1247-
* @see Sql.getFieldName()
1244+
* @see window.Sql.getFieldName()
12481245
*/
1249-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1246+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
12501247

12511248
/**
12521249
* @var thisFieldParams Array temporary storage for the name/value of current field
@@ -1295,7 +1292,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
12951292
}
12961293
}
12971294
// check if edited field appears in WHERE clause
1298-
if (whereClause.indexOf(Sql.urlEncode(fieldName)) > -1) {
1295+
if (whereClause.indexOf(window.Sql.urlEncode(fieldName)) > -1) {
12991296
var fieldStr = '`' + g.table + '`.' + '`' + fieldName + '`';
13001297
for (var field in conditionArray) {
13011298
if (field.indexOf(fieldStr) > -1) {
@@ -1472,9 +1469,9 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
14721469

14731470
/**
14741471
* @var fieldName String containing the name of this field.
1475-
* @see Sql.getFieldName()
1472+
* @see window.Sql.getFieldName()
14761473
*/
1477-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1474+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
14781475

14791476
/**
14801477
* @var thisFieldParams Array temporary storage for the name/value of current field
@@ -1826,7 +1823,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
18261823
moveUp: function (e) {
18271824
e.preventDefault();
18281825
var $thisField = $(g.currentEditCell);
1829-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1826+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
18301827

18311828
var whereClause = $thisField.parents('tr').first().find('.where_clause').val();
18321829
if (typeof whereClause === 'undefined') {
@@ -1848,7 +1845,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
18481845

18491846
if (found && $prevRow) {
18501847
$prevRow.children('td').each(function () {
1851-
if (Sql.getFieldName($(g.t), $(this)) === fieldName) {
1848+
if (window.Sql.getFieldName($(g.t), $(this)) === fieldName) {
18521849
newCell = this;
18531850
}
18541851
});
@@ -1869,7 +1866,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
18691866
e.preventDefault();
18701867

18711868
var $thisField = $(g.currentEditCell);
1872-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1869+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
18731870

18741871
var whereClause = $thisField.parents('tr').first().find('.where_clause').val();
18751872
if (typeof whereClause === 'undefined') {
@@ -1896,7 +1893,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
18961893
var newCell;
18971894
if (found && $nextRow) {
18981895
$nextRow.children('td').each(function () {
1899-
if (Sql.getFieldName($(g.t), $(this)) === fieldName) {
1896+
if (window.Sql.getFieldName($(g.t), $(this)) === fieldName) {
19001897
newCell = this;
19011898
}
19021899
});
@@ -1917,7 +1914,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
19171914
e.preventDefault();
19181915

19191916
var $thisField = $(g.currentEditCell);
1920-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1917+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
19211918

19221919
var whereClause = $thisField.parents('tr').first().find('.where_clause').val();
19231920
if (typeof whereClause === 'undefined') {
@@ -1936,7 +1933,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
19361933
var cellFound = false;
19371934
if (found) {
19381935
$foundRow.children('td.grid_edit').each(function () {
1939-
if (Sql.getFieldName($(g.t), $(this)) === fieldName) {
1936+
if (window.Sql.getFieldName($(g.t), $(this)) === fieldName) {
19401937
cellFound = true;
19411938
}
19421939
if (! cellFound) {
@@ -1960,7 +1957,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
19601957
e.preventDefault();
19611958

19621959
var $thisField = $(g.currentEditCell);
1963-
var fieldName = Sql.getFieldName($(g.t), $thisField);
1960+
var fieldName = window.Sql.getFieldName($(g.t), $thisField);
19641961

19651962
var whereClause = $thisField.parents('tr').first().find('.where_clause').val();
19661963
if (typeof whereClause === 'undefined') {
@@ -1981,7 +1978,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
19811978
var nextCellFound = false;
19821979
if (found) {
19831980
$foundRow.children('td.grid_edit').each(function () {
1984-
if (Sql.getFieldName($(g.t), $(this)) === fieldName) {
1981+
if (window.Sql.getFieldName($(g.t), $(this)) === fieldName) {
19851982
cellFound = true;
19861983
}
19871984
if (cellFound) {

js/src/modules/functions.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import checkIndexName from './indexes/checkIndexName.ts';
1414
import mainMenuResizerCallback from './functions/mainMenuResizerCallback.ts';
1515
import isStorageSupported from './functions/isStorageSupported.ts';
1616

17-
/* global DatabaseStructure */ // js/database/structure.js
18-
/* global firstDayOfCalendar, themeImagePath */ // templates/javascript/variables.twig
19-
2017
/**
2118
* Object containing CodeMirror editor of the query editor in SQL tab.
2219
* @type {(object|boolean|null)}
@@ -94,7 +91,7 @@ function addDatepicker ($thisElement, type, options) {
9491
minute: currentDateTime.getMinutes(),
9592
second: currentDateTime.getSeconds(),
9693
showOn: 'button',
97-
buttonImage: themeImagePath + 'b_calendar.png',
94+
buttonImage: window.themeImagePath + 'b_calendar.png',
9895
buttonImageOnly: true,
9996
stepMinutes: 1,
10097
stepHours: 1,
@@ -192,7 +189,7 @@ function addDateTimePicker () {
192189
showMicrosec: showMicrosec,
193190
timeFormat: timeFormat,
194191
hourMax: hourMax,
195-
firstDay: firstDayOfCalendar
192+
firstDay: window.firstDayOfCalendar
196193
});
197194
// Add a tip regarding entering MySQL allowed-values
198195
// for TIME and DATE data-type
@@ -1838,7 +1835,7 @@ function onloadCreateTableEvents (): void {
18381835
$(tablesTable).sortTable('th');
18391836

18401837
// Adjust summary row
1841-
DatabaseStructure.adjustTotals();
1838+
window.DatabaseStructure.adjustTotals();
18421839
}
18431840

18441841
// Refresh navigation as a new table has been added

js/src/modules/functions/checkNumberOfFields.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import $ from 'jquery';
22
import { ajaxShowMessage } from '../ajax-message.ts';
33

4-
/* global maxInputVars */ // templates/javascript/variables.twig
5-
64
/**
75
* Check than forms have less fields than max allowed by PHP.
86
* @return {boolean}
97
*/
108
export default function checkNumberOfFields () {
11-
if (typeof maxInputVars === 'undefined') {
9+
if (typeof window.maxInputVars === 'undefined') {
1210
return false;
1311
}
14-
if (false === maxInputVars) {
12+
if (false === window.maxInputVars) {
1513
return false;
1614
}
1715
$('form').each(function () {
1816
var nbInputs = $(this).find(':input').length;
19-
if (nbInputs > maxInputVars) {
20-
var warning = window.sprintf(window.Messages.strTooManyInputs, maxInputVars);
17+
if (nbInputs > window.maxInputVars) {
18+
var warning = window.sprintf(window.Messages.strTooManyInputs, window.maxInputVars);
2119
ajaxShowMessage(warning);
2220
return false;
2321
}

js/src/modules/functions/createProfilingChart.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import $ from 'jquery';
22

3-
/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js
4-
53
/**
64
* Creates a Profiling Chart. Used in sql.js
75
* and in server/status/monitor.js
@@ -13,13 +11,13 @@ import $ from 'jquery';
1311
*/
1412
export default function createProfilingChart (target, data) {
1513
// create the chart
16-
var factory = new JQPlotChartFactory();
17-
var chart = factory.createChart(ChartType.PIE, target);
14+
var factory = new window.JQPlotChartFactory();
15+
var chart = factory.createChart(window.ChartType.PIE, target);
1816

1917
// create the data table and add columns
20-
var dataTable = new DataTable();
21-
dataTable.addColumn(ColumnType.STRING, '');
22-
dataTable.addColumn(ColumnType.NUMBER, '');
18+
var dataTable = new window.DataTable();
19+
dataTable.addColumn(window.ColumnType.STRING, '');
20+
dataTable.addColumn(window.ColumnType.NUMBER, '');
2321
dataTable.setData(data);
2422

2523
var windowWidth = $(window).width();

js/src/modules/sql-highlight.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import $ from 'jquery';
22

3-
/* global mysqlDocTemplate */ // templates/javascript/variables.twig
4-
53
/**
64
* Definition of links to MySQL documentation.
75
*/
@@ -375,12 +373,12 @@ const mysqlDocBuiltin = {
375373
* @param params
376374
*/
377375
function documentationAdd ($elm, params) {
378-
if (typeof mysqlDocTemplate === 'undefined') {
376+
if (typeof window.mysqlDocTemplate === 'undefined') {
379377
return;
380378
}
381379

382380
var url = window.sprintf(
383-
decodeURIComponent(mysqlDocTemplate),
381+
decodeURIComponent(window.mysqlDocTemplate),
384382
params[0]
385383
);
386384
if (params.length > 1) {

js/src/server/status/monitor.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import isStorageSupported from '../../modules/functions/isStorageSupported.ts';
1515
* @requires jQueryUI
1616
*/
1717

18-
/* global firstDayOfCalendar, themeImagePath */ // templates/javascript/variables.twig
19-
/* global variableNames */ // templates/server/status/monitor/index.twig
20-
2118
var runtime = {};
2219
var serverTimeDiff;
2320
var serverOs;
@@ -1041,7 +1038,7 @@ AJAX.registerOnload('server/status/monitor.js', function () {
10411038
});
10421039

10431040
$('#variableInput').autocomplete({
1044-
source: variableNames
1041+
source: window.variableNames
10451042
});
10461043

10471044
/* Initializes the monitor, called only once */
@@ -1477,13 +1474,13 @@ AJAX.registerOnload('server/status/monitor.js', function () {
14771474
showMillisec: false,
14781475
showMicrosec: false,
14791476
timeFormat: 'HH:mm:ss',
1480-
firstDay: firstDayOfCalendar
1477+
firstDay: window.firstDayOfCalendar
14811478
});
14821479
Functions.addDatepicker($dateEnd, 'datetime', {
14831480
showMillisec: false,
14841481
showMicrosec: false,
14851482
timeFormat: 'HH:mm:ss',
1486-
firstDay: firstDayOfCalendar
1483+
firstDay: window.firstDayOfCalendar
14871484
});
14881485
$dateStart.datepicker('setDate', min);
14891486
$dateEnd.datepicker('setDate', max);
@@ -1728,7 +1725,7 @@ AJAX.registerOnload('server/status/monitor.js', function () {
17281725
title: window.Messages.strAnalysingLogsTitle
17291726
});
17301727
$('#emptyDialog').html(window.Messages.strAnalysingLogs +
1731-
' <img class="ajaxIcon" src="' + themeImagePath +
1728+
' <img class="ajaxIcon" src="' + window.themeImagePath +
17321729
'ajax_clock_small.gif" alt="">');
17331730

17341731
var dlgBtns = {
@@ -2186,7 +2183,7 @@ AJAX.registerOnload('server/status/monitor.js', function () {
21862183

21872184
$('#queryAnalyzerDialog').find('div.placeHolder').html(
21882185
window.Messages.strAnalyzing + ' <img class="ajaxIcon" src="' +
2189-
themeImagePath + 'ajax_clock_small.gif" alt="">');
2186+
window.themeImagePath + 'ajax_clock_small.gif" alt="">');
21902187

21912188
$.post('index.php?route=/server/status/monitor/query', {
21922189
'ajax_request': true,

0 commit comments

Comments
 (0)