fix: initTooltip과 bootstrap-vue-3 충돌 문제 해결

- 기타 data-bs 안붙은거 마저 수정
This commit is contained in:
2021-12-11 11:37:41 +09:00
parent 95bd5b539f
commit dfb10c1b44
15 changed files with 131 additions and 112 deletions
+42
View File
@@ -0,0 +1,42 @@
import $ from "jquery";
export function activateFlip($obj?: JQuery<HTMLElement>): void {
let $result: JQuery<HTMLElement>;
if ($obj === undefined) {
$result = $('img[data-flip]');
} else {
$result = $obj.find('img[data-flip]');
}
$result.each(function () {
activeFlipItem($(this));
});
}
export function activeFlipItem($img: JQuery<HTMLElement>): void {
const imageList = [];
imageList.push($img.attr('src'));
$.each($img.data('flip').split(','), function (idx, value) {
value = $.trim(value);
if (!value) {
return true;
}
imageList.push(value);
});
if (imageList.length <= 1) {
return;
}
$img.data('computed_flip_array', imageList);
$img.data('computed_flip_idx', 0);
$img.click(function () {
const arr = $img.data('computed_flip_array');
let idx = $img.data('computed_flip_idx');
idx = (idx + 1) % (arr.length);
$img.attr('src', arr[idx]);
$img.data('computed_flip_idx', idx);
});
$img.css('cursor', 'pointer');
}
+46
View File
@@ -0,0 +1,46 @@
import Tooltip from "bootstrap/js/dist/tooltip";
//HACK: 이유는 잘 모르겠지만 bootstrap-vue3에서 bootstrap 호출하는 것과 충돌하여 우회 중
import $ from "jquery";
import { trim } from "lodash";
export function initTooltip($obj?: JQuery<HTMLElement>): void {
if ($obj === undefined) {
$obj = $('.obj_tooltip');
} else if (!$obj.hasClass('obj_tooltip')) {
$obj = $obj.find('.obj_tooltip');
}
$obj.each(function () {
const $target = $(this);
if ($target.data('installHandler')) {
return;
}
$target.data('installHandler', true);
$target.on('mouseover', function () {
const $objTooltip = $(this);
if ($objTooltip.data('setObjTooltip')) {
return;
}
let tooltipClassText = $objTooltip.data('tooltip-class');
if (!tooltipClassText) {
tooltipClassText = '';
}
const template = `<div class="tooltip ${tooltipClassText}" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>`;
const oTooltip = new Tooltip(this, {
title: function () {
return trim(this.querySelector('.tooltiptext')?.innerHTML);
},
template: template,
html: true
});
oTooltip.show();
$objTooltip.data('setObjTooltip', true);
});
});
}
+27 -13
View File
@@ -1,29 +1,43 @@
import $ from 'jquery';
import { activateFlip, initTooltip } from '@/common_legacy';
import jQuery from 'jquery';
import { activateFlip } from "@/legacy/activateFlip";
import { unwrap } from '@util/unwrap';
import { htmlReady } from '@util/htmlReady';
import { initTooltip } from './initTooltip';
import { exportWindow } from '@/util/exportWindow';
import '@/msg.ts';
import '@/map.ts';
import '@scss/main.scss';
import { unwrap } from '@util/unwrap';
import { htmlReady } from '@util/htmlReady';
exportWindow(jQuery, '$');
htmlReady(() => {
$('.refreshPage').click(function () {
document.querySelector('.refreshPage')?.addEventListener('click', function () {
document.location.reload();
return false;
});
$('.open-window').on('click', function (e) {
document.querySelector('.open-window')?.addEventListener('click', function (e) {
e.preventDefault();
let target = $(e.target as HTMLAnchorElement);
while (target.attr('href') === undefined) {
target = target.parent('a');
if (target.length == 0) {
let target: HTMLElement | null = e.target as HTMLElement;
while (target !== null) {
target = target.parentElement;
if (target === null) {
return;
}
if (target.tagName != 'a') {
continue;
}
if ((target as HTMLAnchorElement).href !== undefined) {
break;
}
}
const href = target.attr('href');
window.open(href);
if (!target) {
return;
}
window.open((target as HTMLAnchorElement).href);
});
activateFlip();