Skip to content

Commit f5a5983

Browse files
committed
Declare some js globals as Window properties
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent edc4a0d commit f5a5983

15 files changed

Lines changed: 127 additions & 26 deletions

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"wrap-iife": "error",
6868
"@typescript-eslint/ban-ts-comment": "off",
6969
"@typescript-eslint/no-empty-function": "off",
70+
"@typescript-eslint/no-explicit-any": "off",
7071
"@typescript-eslint/no-unused-vars": "off",
7172
"@typescript-eslint/no-this-alias": "off"
7273
}

js/global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ declare var maxInputVars: number;
99

1010
declare function sprintf(format: string, ...values: (string|number)[]): string;
1111

12+
interface Window {
13+
ol: any;
14+
15+
drawOpenLayers: () => any;
16+
}
17+
1218
interface JQuery {
1319
getPostData: () => string;
1420

@@ -27,4 +33,6 @@ interface JQuery {
2733

2834
interface JQueryStatic {
2935
timepicker: JQueryUI.Datepicker;
36+
37+
jqplot: any;
3038
}

js/src/chart.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var ChartType = {
1313
TIMELINE: 'timeline',
1414
SCATTER: 'scatter'
1515
};
16-
window.ChartType = ChartType;
1716

1817
/**
1918
* Column type enumeration
@@ -24,7 +23,6 @@ var ColumnType = {
2423
BOOLEAN: 'boolean',
2524
DATE: 'date'
2625
};
27-
window.ColumnType = ColumnType;
2826

2927
/**
3028
* Abstract chart factory which defines the contract for chart factories
@@ -211,8 +209,6 @@ var DataTable = function () {
211209
};
212210
};
213211

214-
window.DataTable = DataTable;
215-
216212
/** *****************************************************************************
217213
* JQPlot specific code
218214
******************************************************************************/
@@ -729,4 +725,16 @@ JQPlotChartFactory.prototype.createChart = function (type, elementId) {
729725
return chart;
730726
};
731727

728+
declare global {
729+
interface Window {
730+
ChartType: typeof ChartType;
731+
ColumnType: typeof ColumnType;
732+
DataTable: typeof DataTable;
733+
JQPlotChartFactory: typeof JQPlotChartFactory;
734+
}
735+
}
736+
737+
window.ChartType = ChartType;
738+
window.ColumnType = ColumnType;
739+
window.DataTable = DataTable;
732740
window.JQPlotChartFactory = JQPlotChartFactory;

js/src/designer/history.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,12 @@ DesignerHistory.buildQuery = function () {
887887
});
888888
};
889889

890-
// @ts-ignore
890+
declare global {
891+
interface Window {
892+
DesignerHistory: typeof DesignerHistory;
893+
}
894+
}
895+
891896
window.DesignerHistory = DesignerHistory;
892897

893898
export { DesignerHistory };

js/src/designer/init.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ AJAX.registerTeardown('designer/init.js', function () {
319319
$('.trigger').off('click');
320320
});
321321

322+
declare global {
323+
interface Window {
324+
designerConfig: {
325+
db: string;
326+
scriptTables: { j_tabs: any[], h_tabs: any[] };
327+
scriptContr: any[];
328+
server: number;
329+
scriptDisplayField: any[];
330+
displayPage: number;
331+
tablesEnabled: boolean;
332+
};
333+
}
334+
}
335+
322336
AJAX.registerOnload('designer/init.js', function () {
323337
$('.trigger').on('click', function () {
324338
$('.panel').toggle('fast');
@@ -328,7 +342,6 @@ AJAX.registerOnload('designer/init.js', function () {
328342
return false;
329343
});
330344

331-
// @ts-ignore
332345
const configValues = window.designerConfig;
333346

334347
DesignerConfig.jTabs = configValues.scriptTables.j_tabs;

js/src/error_report.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { AJAX } from './modules/ajax.ts';
33
import { CommonParams } from './modules/common.ts';
44
import { ajaxShowMessage } from './modules/ajax-message.ts';
55
import getImageTag from './modules/functions/getImageTag.ts';
6+
import type * as TraceKit from 'tracekit/tracekit.d.ts';
7+
8+
declare global {
9+
interface Window {
10+
TraceKit: typeof TraceKit;
11+
}
12+
}
613

714
/**
815
* general function, usually for data manipulation pages

js/src/gis_data_editor.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ function loadJSAndGISEditor (value, field, type, inputName) {
126126
window.gisEditorLoaded = true;
127127
}
128128

129-
window.loadJSAndGISEditor = loadJSAndGISEditor;
130-
131129
/**
132130
* Loads the GIS editor via AJAX
133131
*
@@ -157,8 +155,6 @@ function loadGISEditor (value, field, type, inputName) {
157155
}, 'json');
158156
}
159157

160-
window.loadGISEditor = loadGISEditor;
161-
162158
/**
163159
* Opens up the dialog for the GIS data editor.
164160
*/
@@ -189,8 +185,6 @@ function openGISEditor () {
189185
$gisEditor.fadeIn('fast');
190186
}
191187

192-
window.openGISEditor = openGISEditor;
193-
194188
/**
195189
* Prepare and insert the GIS data in Well Known Text format
196190
* to the input field.
@@ -402,3 +396,16 @@ AJAX.registerOnload('gis_data_editor.js', function () {
402396
$noOfGeomsInput.val(noOfGeoms + 1);
403397
});
404398
});
399+
400+
declare global {
401+
interface Window {
402+
gisEditorLoaded: boolean;
403+
loadJSAndGISEditor: typeof loadJSAndGISEditor;
404+
loadGISEditor: typeof loadGISEditor;
405+
openGISEditor: typeof openGISEditor;
406+
}
407+
}
408+
409+
window.loadJSAndGISEditor = loadJSAndGISEditor;
410+
window.loadGISEditor = loadGISEditor;
411+
window.openGISEditor = openGISEditor;

js/src/modules/config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function getIdPrefix (element) {
213213
let validate = {};
214214

215215
// form validator list
216-
window.validators = {
216+
const validators = {
217217
// regexp: numeric value
218218
regExpNumeric: /^[0-9]+$/,
219219
// regexp: extract parts from PCRE expression
@@ -842,6 +842,14 @@ const Config = {
842842
on: on,
843843
};
844844

845+
declare global {
846+
interface Window {
847+
validators: typeof validators;
848+
Config: typeof Config;
849+
}
850+
}
851+
852+
window.validators = validators;
845853
window.Config = Config;
846854

847855
export { Config };

js/src/modules/console.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,4 +1565,10 @@ var ConsoleDebug = {
15651565
}
15661566
};
15671567

1568+
declare global {
1569+
interface Window {
1570+
Console: typeof Console;
1571+
}
1572+
}
1573+
15681574
export { Console };

js/src/modules/functions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,13 @@ $.fn.confirm = Functions.confirm;
38533853
$.fn.sortTable = Functions.sortTable;
38543854
$.fn.getPostData = Functions.getPostData;
38553855

3856+
declare global {
3857+
interface Window {
3858+
codeMirrorEditor: CodeMirror.EditorFromTextArea | boolean | null;
3859+
Functions: typeof Functions;
3860+
}
3861+
}
3862+
38563863
window.Functions = Functions;
38573864

38583865
export { Functions };

0 commit comments

Comments
 (0)