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 { escapeHtml } from "./legacy/escapeHtml";
|
||||||
import { nl2br } from "./util/nl2br";
|
import { nl2br } from "./util/nl2br";
|
||||||
import jQuery from "jquery";
|
import jQuery from "jquery";
|
||||||
window.jQuery = jQuery;
|
import { exportWindow } from "./util/exportWindow";
|
||||||
window.$ = jQuery;
|
|
||||||
|
exportWindow(jQuery, '$');
|
||||||
|
exportWindow(jQuery, 'jQuery');
|
||||||
|
|
||||||
jQuery(function ($) {
|
jQuery(function ($) {
|
||||||
initTooltip();
|
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}형태로 포맷해주는 함수
|
* {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 this.replace(/{(\d+)}/g, function (match, number) {
|
||||||
return (typeof args[number] != 'undefined') ? args[number].toString() : match;
|
return (typeof args[number] != 'undefined') ? args[number].toString() : match;
|
||||||
});
|
});
|
||||||
};
|
}, 'format', String.prototype);
|
||||||
|
exportWindow(escapeHtml, 'escapeHtml');
|
||||||
|
exportWindow(mb_strwidth, 'mb_strwidth');
|
||||||
window.escapeHtml = escapeHtml;
|
exportWindow(isBrightColor, 'isBrightColor');
|
||||||
window.mb_strwidth = mb_strwidth;
|
exportWindow(TemplateEngine, 'TemplateEngine');
|
||||||
window.isBrightColor = isBrightColor;
|
exportWindow(getIconPath, 'getIconPath');
|
||||||
window.TemplateEngine = TemplateEngine;
|
exportWindow(activeFlip, 'activeFlip');
|
||||||
window.getIconPath = getIconPath;
|
exportWindow(errUnknown, 'errUnknown');
|
||||||
window.activeFlip = activeFlip;
|
exportWindow(errUnknownToast, 'errUnknownToast');
|
||||||
window.errUnknown = errUnknown;
|
exportWindow(quickReject, 'quickReject');
|
||||||
window.errUnknownToast = errUnknownToast;
|
exportWindow(nl2br, 'nl2br');
|
||||||
window.quickReject = quickReject;
|
exportWindow(initTooltip, 'initTooltip');
|
||||||
window.nl2br = nl2br;
|
|
||||||
window.initTooltip = initTooltip;
|
|
||||||
+2
-1
@@ -7,6 +7,7 @@ import axios from "axios";
|
|||||||
import { InvalidResponse } from "./defs";
|
import { InvalidResponse } from "./defs";
|
||||||
import { JQValidateForm, NamedRules } from "./util/jqValidateForm";
|
import { JQValidateForm, NamedRules } from "./util/jqValidateForm";
|
||||||
import { convertFormData } from "./util/convertFormData";
|
import { convertFormData } from "./util/convertFormData";
|
||||||
|
import { exportWindow } from "./util/exportWindow";
|
||||||
|
|
||||||
type ResponseScenarioItem = {
|
type ResponseScenarioItem = {
|
||||||
year?: number,
|
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 { InvalidResponse } from './defs';
|
||||||
import { unwrap } from "./util/unwrap";
|
import { unwrap } from "./util/unwrap";
|
||||||
import { convertFormData } from './util/convertFormData';
|
import { convertFormData } from './util/convertFormData';
|
||||||
|
import { exportWindow } from './util/exportWindow';
|
||||||
|
|
||||||
declare const serverNick: string;
|
declare const serverNick: string;
|
||||||
declare const serverID: string;
|
declare const serverID: string;
|
||||||
@@ -16,7 +17,6 @@ type CityPositionMap = {
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
sam_toggleSingleTap?: boolean,
|
sam_toggleSingleTap?: boolean,
|
||||||
reloadWorldMap: (option: loadMapOption, drawTarget?: string) => Promise<void>;
|
|
||||||
getCityPosition: () => CityPositionMap;
|
getCityPosition: () => CityPositionMap;
|
||||||
formatCityInfo: (city: MapCityParsedRaw)=>MapCityParsedRegionLevelText
|
formatCityInfo: (city: MapCityParsedRaw)=>MapCityParsedRegionLevelText
|
||||||
}
|
}
|
||||||
@@ -782,7 +782,7 @@ export async function reloadWorldMap(option: loadMapOption, drawTarget = '.world
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.reloadWorldMap = reloadWorldMap;
|
exportWindow(reloadWorldMap, 'reloadWorldMap');
|
||||||
$(function ($) {
|
$(function ($) {
|
||||||
if (is_touch_device()) {
|
if (is_touch_device()) {
|
||||||
$('.map_body .map_toggle_single_tap').show();
|
$('.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 { setAxiosXMLHttpRequest } from '../hwe/ts/util/setAxiosXMLHttpRequest';
|
||||||
import { unwrap_any } from '../hwe/ts/util/unwrap_any';
|
import { unwrap_any } from '../hwe/ts/util/unwrap_any';
|
||||||
import { convertFormData } from '../hwe/ts/util/convertFormData';
|
import { convertFormData } from '../hwe/ts/util/convertFormData';
|
||||||
|
import { exportWindow } from './util/exportWindow';
|
||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
changeSystem: (action: string) => Promise<void>;
|
|
||||||
changeUserStatus: (action: string, userID: Element | number, param?: number) => Promise<void>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserEntry = {
|
type UserEntry = {
|
||||||
userID: string,
|
userID: string,
|
||||||
@@ -277,9 +271,6 @@ async function refreshAll() {
|
|||||||
|
|
||||||
$(async function () {
|
$(async function () {
|
||||||
setAxiosXMLHttpRequest();
|
setAxiosXMLHttpRequest();
|
||||||
window.changeSystem = changeSystem;
|
|
||||||
window.changeUserStatus = changeUserStatus;
|
|
||||||
|
|
||||||
await refreshAll();
|
await refreshAll();
|
||||||
|
|
||||||
$('input[name=allow_join], input[name=allow_login]').on('change', async function () {
|
$('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()));
|
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