feat: exportWindow
- global을 지저분하게 하지 않고, window에 출력만 해줌
This commit is contained in:
+17
-48
@@ -4,8 +4,10 @@ import { TemplateEngine } from "./util/TemplateEngine";
|
||||
import { escapeHtml } from "./legacy/escapeHtml";
|
||||
import { nl2br } from "./util/nl2br";
|
||||
import jQuery from "jquery";
|
||||
window.jQuery = jQuery;
|
||||
window.$ = jQuery;
|
||||
import { exportWindow } from "./util/exportWindow";
|
||||
|
||||
exportWindow(jQuery, '$');
|
||||
exportWindow(jQuery, 'jQuery');
|
||||
|
||||
jQuery(function ($) {
|
||||
initTooltip();
|
||||
@@ -19,55 +21,22 @@ jQuery(function ($) {
|
||||
}
|
||||
});
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
$: typeof jQuery;
|
||||
jQuery: typeof jQuery;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
escapeHtml: typeof escapeHtml;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
mb_strwidth: typeof mb_strwidth;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
isBrightColor: typeof isBrightColor;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
TemplateEngine: typeof TemplateEngine;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
getIconPath: typeof getIconPath;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
activeFlip: typeof activeFlip;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
errUnknown: typeof errUnknown;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
errUnknownToast: typeof errUnknownToast;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
quickReject: typeof quickReject;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
nl2br: typeof nl2br;
|
||||
/** @deprecated Module 사용할 것 */
|
||||
initTooltip: typeof initTooltip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {0}, {1}, {2}형태로 포맷해주는 함수
|
||||
* NOTE: TypeScript declare 충돌로 인해 우회 정의
|
||||
*/
|
||||
(String.prototype as unknown as {format:(...args:(string|number)[])=>string}).format = function(this:string, ...args){
|
||||
exportWindow(function(this:string, ...args:(string|number)[]){
|
||||
return this.replace(/{(\d+)}/g, function (match, number) {
|
||||
return (typeof args[number] != 'undefined') ? args[number].toString() : match;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
window.escapeHtml = escapeHtml;
|
||||
window.mb_strwidth = mb_strwidth;
|
||||
window.isBrightColor = isBrightColor;
|
||||
window.TemplateEngine = TemplateEngine;
|
||||
window.getIconPath = getIconPath;
|
||||
window.activeFlip = activeFlip;
|
||||
window.errUnknown = errUnknown;
|
||||
window.errUnknownToast = errUnknownToast;
|
||||
window.quickReject = quickReject;
|
||||
window.nl2br = nl2br;
|
||||
window.initTooltip = initTooltip;
|
||||
}, 'format', String.prototype);
|
||||
exportWindow(escapeHtml, 'escapeHtml');
|
||||
exportWindow(mb_strwidth, 'mb_strwidth');
|
||||
exportWindow(isBrightColor, 'isBrightColor');
|
||||
exportWindow(TemplateEngine, 'TemplateEngine');
|
||||
exportWindow(getIconPath, 'getIconPath');
|
||||
exportWindow(activeFlip, 'activeFlip');
|
||||
exportWindow(errUnknown, 'errUnknown');
|
||||
exportWindow(errUnknownToast, 'errUnknownToast');
|
||||
exportWindow(quickReject, 'quickReject');
|
||||
exportWindow(nl2br, 'nl2br');
|
||||
exportWindow(initTooltip, 'initTooltip');
|
||||
+2
-1
@@ -7,6 +7,7 @@ import axios from "axios";
|
||||
import { InvalidResponse } from "./defs";
|
||||
import { JQValidateForm, NamedRules } from "./util/jqValidateForm";
|
||||
import { convertFormData } from "./util/convertFormData";
|
||||
import { exportWindow } from "./util/exportWindow";
|
||||
|
||||
type ResponseScenarioItem = {
|
||||
year?: number,
|
||||
@@ -267,4 +268,4 @@ $(async function () {
|
||||
|
||||
})
|
||||
|
||||
window.$ = $;
|
||||
exportWindow($, '$');
|
||||
+2
-2
@@ -5,6 +5,7 @@ import { convColorValue, convertDictById, convertSet, stringFormat } from './com
|
||||
import { InvalidResponse } from './defs';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { convertFormData } from './util/convertFormData';
|
||||
import { exportWindow } from './util/exportWindow';
|
||||
|
||||
declare const serverNick: string;
|
||||
declare const serverID: string;
|
||||
@@ -16,7 +17,6 @@ type CityPositionMap = {
|
||||
declare global {
|
||||
interface Window {
|
||||
sam_toggleSingleTap?: boolean,
|
||||
reloadWorldMap: (option: loadMapOption, drawTarget?: string) => Promise<void>;
|
||||
getCityPosition: () => CityPositionMap;
|
||||
formatCityInfo: (city: MapCityParsedRaw)=>MapCityParsedRegionLevelText
|
||||
}
|
||||
@@ -782,7 +782,7 @@ export async function reloadWorldMap(option: loadMapOption, drawTarget = '.world
|
||||
}
|
||||
}
|
||||
|
||||
window.reloadWorldMap = reloadWorldMap;
|
||||
exportWindow(reloadWorldMap, 'reloadWorldMap');
|
||||
$(function ($) {
|
||||
if (is_touch_device()) {
|
||||
$('.map_body .map_toggle_single_tap').show();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export function exportWindow(obj:unknown, objName: string, targetWindow?: unknown):void{
|
||||
const target:unknown = targetWindow ?? window;
|
||||
(target as {[v: string]: unknown})[objName] = obj;
|
||||
}
|
||||
+4
-10
@@ -6,13 +6,7 @@ import { InvalidResponse } from '../hwe/ts/defs';
|
||||
import { setAxiosXMLHttpRequest } from '../hwe/ts/util/setAxiosXMLHttpRequest';
|
||||
import { unwrap_any } from '../hwe/ts/util/unwrap_any';
|
||||
import { convertFormData } from '../hwe/ts/util/convertFormData';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
changeSystem: (action: string) => Promise<void>;
|
||||
changeUserStatus: (action: string, userID: Element | number, param?: number) => Promise<void>;
|
||||
}
|
||||
}
|
||||
import { exportWindow } from './util/exportWindow';
|
||||
|
||||
type UserEntry = {
|
||||
userID: string,
|
||||
@@ -277,9 +271,6 @@ async function refreshAll() {
|
||||
|
||||
$(async function () {
|
||||
setAxiosXMLHttpRequest();
|
||||
window.changeSystem = changeSystem;
|
||||
window.changeUserStatus = changeUserStatus;
|
||||
|
||||
await refreshAll();
|
||||
|
||||
$('input[name=allow_join], input[name=allow_login]').on('change', async function () {
|
||||
@@ -287,3 +278,6 @@ $(async function () {
|
||||
await changeSystem(unwrap_any<string>($this.attr('name')), unwrap_any<string>($this.val()));
|
||||
})
|
||||
});
|
||||
|
||||
exportWindow(changeSystem, 'changeSystem');
|
||||
exportWindow(changeUserStatus, 'changeUserStatus');
|
||||
Reference in New Issue
Block a user