deleteCheckinModalをVanilla化
This commit is contained in:
parent
8a0a29feef
commit
23189b76e4
@ -1,5 +0,0 @@
|
|||||||
// tissue.ts で定義されているjQuery Pluginの型定義
|
|
||||||
|
|
||||||
interface JQuery<TElement = HTMLElement> {
|
|
||||||
deleteCheckinModal: () => this;
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import * as Cookies from 'js-cookie';
|
import * as Cookies from 'js-cookie';
|
||||||
import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch';
|
import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch';
|
||||||
import { linkCard, pageSelector } from './tissue';
|
import { linkCard, pageSelector, deleteCheckinModal } from './tissue';
|
||||||
|
|
||||||
require('./bootstrap');
|
require('./bootstrap');
|
||||||
|
|
||||||
@ -24,11 +24,15 @@ $(() => {
|
|||||||
document.querySelectorAll('.tis-page-selector').forEach(pageSelector);
|
document.querySelectorAll('.tis-page-selector').forEach(pageSelector);
|
||||||
|
|
||||||
document.querySelectorAll('.link-card').forEach(linkCard);
|
document.querySelectorAll('.link-card').forEach(linkCard);
|
||||||
const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal();
|
|
||||||
|
const elDeleteCheckinModal = document.getElementById('deleteCheckinModal');
|
||||||
|
if (elDeleteCheckinModal) {
|
||||||
|
const $deleteCheckinModal = deleteCheckinModal(elDeleteCheckinModal);
|
||||||
$(document).on('click', '[data-target="#deleteCheckinModal"]', function (event) {
|
$(document).on('click', '[data-target="#deleteCheckinModal"]', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$deleteCheckinModal.modal('show', this);
|
$deleteCheckinModal.modal('show', this);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on('click', '[data-href]', function (_event) {
|
$(document).on('click', '[data-href]', function (_event) {
|
||||||
location.href = $(this).data('href');
|
location.href = $(this).data('href');
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
// jQuery
|
|
||||||
import './tissue';
|
|
||||||
|
|
||||||
// Bootstrap
|
// Bootstrap
|
||||||
import 'bootstrap';
|
import 'bootstrap';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { fetchGet } from './fetch';
|
import { fetchGet } from './fetch';
|
||||||
|
|
||||||
function suicide<T>(e: T) {
|
export function suicide<T>(e: T) {
|
||||||
return function (): never {
|
return function (): never {
|
||||||
throw e;
|
throw e;
|
||||||
};
|
};
|
||||||
@ -45,19 +45,21 @@ export function linkCard(el: Element) {
|
|||||||
el.classList.remove('d-none');
|
el.classList.remove('d-none');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pageSelector(el: Element) {
|
export function pageSelector(el: Element) {
|
||||||
if (!(el instanceof HTMLSelectElement)) return;
|
if (el instanceof HTMLSelectElement) {
|
||||||
el.addEventListener('change', function () {
|
el.addEventListener('change', function () {
|
||||||
location.href = this.options[this.selectedIndex].dataset.href as string;
|
location.href = this.options[this.selectedIndex].dataset.href as string;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
(function ($) {
|
export function deleteCheckinModal(el: Element) {
|
||||||
$.fn.deleteCheckinModal = function () {
|
return $(el)
|
||||||
return this.each(function () {
|
|
||||||
$(this)
|
|
||||||
.on('show.bs.modal', function (event) {
|
.on('show.bs.modal', function (event) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
const target = $(event.relatedTarget!);
|
const target = $(event.relatedTarget!);
|
||||||
@ -71,7 +73,6 @@ export function pageSelector(el: Element) {
|
|||||||
const form = modal.find('form');
|
const form = modal.find('form');
|
||||||
form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null);
|
form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null);
|
||||||
form.submit();
|
form.submit();
|
||||||
});
|
})
|
||||||
});
|
.end();
|
||||||
};
|
}
|
||||||
})(jQuery);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user