refac: 500px 모드 변환기 분리
This commit is contained in:
+11
-50
@@ -12,7 +12,8 @@ exportWindow($, '$');
|
|||||||
|
|
||||||
import '../scss/main.scss';
|
import '../scss/main.scss';
|
||||||
import { unwrap } from './util/unwrap';
|
import { unwrap } from './util/unwrap';
|
||||||
import { number } from 'vue-types';
|
import { auto500px } from './util/auto500px';
|
||||||
|
import { htmlReady } from './util/htmlReady';
|
||||||
|
|
||||||
$(function ($) {
|
$(function ($) {
|
||||||
$('.refreshPage').click(function () {
|
$('.refreshPage').click(function () {
|
||||||
@@ -37,14 +38,6 @@ $(function ($) {
|
|||||||
initTooltip();
|
initTooltip();
|
||||||
});
|
});
|
||||||
|
|
||||||
function ready(fn: () => unknown) {
|
|
||||||
if (document.readyState != 'loading') {
|
|
||||||
fn();
|
|
||||||
} else {
|
|
||||||
document.addEventListener('DOMContentLoaded', fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
let finInit = false;
|
let finInit = false;
|
||||||
@@ -55,11 +48,7 @@ function ready(fn: () => unknown) {
|
|||||||
|
|
||||||
let nationMsgBox!: HTMLElement;
|
let nationMsgBox!: HTMLElement;
|
||||||
let nationMsg!: HTMLElement;
|
let nationMsg!: HTMLElement;
|
||||||
let nationMsgHeight : number|undefined = undefined;
|
let nationMsgHeight: number | undefined = undefined;
|
||||||
|
|
||||||
let commandSelector!: HTMLElement;
|
|
||||||
let deviceWidth = -1;
|
|
||||||
let viewportMeta! : HTMLMetaElement;
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
const buttons = document.querySelectorAll<HTMLAnchorElement>('#float-tabs a.btn');
|
const buttons = document.querySelectorAll<HTMLAnchorElement>('#float-tabs a.btn');
|
||||||
@@ -82,36 +71,8 @@ function ready(fn: () => unknown) {
|
|||||||
|
|
||||||
nationMsgBox = unwrap(document.getElementById('nation-msg-box'));
|
nationMsgBox = unwrap(document.getElementById('nation-msg-box'));
|
||||||
nationMsg = unwrap(document.getElementById('nation-msg'));
|
nationMsg = unwrap(document.getElementById('nation-msg'));
|
||||||
|
|
||||||
commandSelector = unwrap(document.getElementById('reservedCommandList'));
|
|
||||||
viewportMeta = unwrap(document.querySelector<HTMLMetaElement>("meta[name=viewport]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function adjustViewportWidth() {
|
|
||||||
if(deviceWidth == window.screen.availWidth){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deviceWidth = window.screen.availWidth;
|
|
||||||
const innerHeight = window.innerHeight;
|
|
||||||
const selectorHeight = commandSelector.offsetHeight*1.1;
|
|
||||||
|
|
||||||
if(deviceWidth < 500){
|
|
||||||
viewportMeta.content = 'width=500, initial-scale=1';
|
|
||||||
console.log(`2`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(innerHeight < selectorHeight){
|
|
||||||
const maybeNextWidth = deviceWidth / innerHeight * selectorHeight;
|
|
||||||
if(maybeNextWidth >= 750){
|
|
||||||
viewportMeta.content = 'width=1000, initial-scale=1';
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
viewportMeta.content = `height=${Math.ceil(selectorHeight)}, initial-scale=1`;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onScroll() {
|
function onScroll() {
|
||||||
if (!finInit && !init()) return;
|
if (!finInit && !init()) return;
|
||||||
|
|
||||||
@@ -143,26 +104,26 @@ function ready(fn: () => unknown) {
|
|||||||
button.classList.add('active');
|
button.classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nationMsgBox.offsetWidth < nationMsg.offsetWidth){
|
if (nationMsgBox.offsetWidth < nationMsg.offsetWidth) {
|
||||||
if(nationMsgHeight === undefined){
|
if (nationMsgHeight === undefined) {
|
||||||
nationMsgHeight = nationMsgBox.offsetHeight;
|
nationMsgHeight = nationMsgBox.offsetHeight;
|
||||||
nationMsgBox.style.height = `${nationMsgHeight / 2}px`;
|
nationMsgBox.style.height = `${nationMsgHeight / 2}px`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
if(nationMsgBox.style.height){
|
if (nationMsgBox.style.height) {
|
||||||
nationMsgHeight = undefined;
|
nationMsgHeight = undefined;
|
||||||
nationMsgBox.style.height = '';
|
nationMsgBox.style.height = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustViewportWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ready(() => {
|
htmlReady(() => {
|
||||||
init();
|
init();
|
||||||
onScroll();
|
onScroll();
|
||||||
window.addEventListener('scroll', onScroll, true);
|
window.addEventListener('scroll', onScroll, true);
|
||||||
window.addEventListener('orientationchange', onScroll, true);
|
window.addEventListener('orientationchange', onScroll, true);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
auto500px();
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { htmlReady } from "./htmlReady";
|
||||||
|
import { unwrap } from "./unwrap";
|
||||||
|
|
||||||
|
export function auto500px(targetHeight = 700): void {
|
||||||
|
let deviceWidth = -1;
|
||||||
|
let viewportMeta!: HTMLMetaElement;
|
||||||
|
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
let _viewPortMeta = document.querySelector<HTMLMetaElement>("meta[name=viewport]");
|
||||||
|
if (_viewPortMeta) {
|
||||||
|
viewportMeta = _viewPortMeta;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const htmlTag = unwrap(document.querySelector("head"));
|
||||||
|
_viewPortMeta = document.createElement("meta");
|
||||||
|
_viewPortMeta.name = 'viewport';
|
||||||
|
_viewPortMeta.content = 'width=500, initial-scale=1';
|
||||||
|
htmlTag.appendChild(_viewPortMeta);
|
||||||
|
viewportMeta = _viewPortMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjustViewportWidth() {
|
||||||
|
if (deviceWidth == window.screen.availWidth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deviceWidth = window.screen.availWidth;
|
||||||
|
const innerHeight = window.innerHeight;
|
||||||
|
const selectorHeight = targetHeight;
|
||||||
|
|
||||||
|
if (deviceWidth < 500) {
|
||||||
|
viewportMeta.content = 'width=500, initial-scale=1';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (innerHeight < selectorHeight) {
|
||||||
|
const maybeNextWidth = deviceWidth / innerHeight * selectorHeight;
|
||||||
|
if (maybeNextWidth >= 750) {
|
||||||
|
viewportMeta.content = 'width=1000, initial-scale=1';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewportMeta.content = `height=${Math.ceil(selectorHeight)}, initial-scale=1`;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlReady(() => {
|
||||||
|
init();
|
||||||
|
adjustViewportWidth();
|
||||||
|
window.addEventListener('scroll', adjustViewportWidth, true);
|
||||||
|
window.addEventListener('orientationchange', adjustViewportWidth, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export function htmlReady(fn: () => unknown): void {
|
||||||
|
if (document.readyState != 'loading') {
|
||||||
|
fn();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user