pageSelectorをVanilla化

This commit is contained in:
shibafu 2020-08-06 01:09:25 +09:00
parent a52211758e
commit a4fdd220ba
3 changed files with 9 additions and 8 deletions

View File

@ -7,6 +7,5 @@ declare namespace JQueryTissue {
interface JQuery<TElement = HTMLElement> { interface JQuery<TElement = HTMLElement> {
linkCard: (options?: JQueryTissue.LinkCardOptions) => this; linkCard: (options?: JQueryTissue.LinkCardOptions) => this;
pageSelector: () => this;
deleteCheckinModal: () => this; deleteCheckinModal: () => this;
} }

View File

@ -1,5 +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 { pageSelector } from './tissue';
require('./bootstrap'); require('./bootstrap');
@ -20,7 +21,7 @@ $(() => {
} }
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
$('.alert').alert(); $('.alert').alert();
$('.tis-page-selector').pageSelector(); document.querySelectorAll('.tis-page-selector').forEach(pageSelector);
$('.link-card').linkCard(); $('.link-card').linkCard();
const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal(); const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal();

View File

@ -1,5 +1,12 @@
import { fetchGet } from './fetch'; import { fetchGet } from './fetch';
export function pageSelector(el: Element) {
if (!(el instanceof HTMLSelectElement)) return;
el.addEventListener('change', function () {
location.href = this.options[this.selectedIndex].dataset.href as string;
});
}
(function ($) { (function ($) {
$.fn.linkCard = function (options) { $.fn.linkCard = function (options) {
const settings = $.extend( const settings = $.extend(
@ -52,12 +59,6 @@ import { fetchGet } from './fetch';
}); });
}; };
$.fn.pageSelector = function () {
return this.on('change', function () {
location.href = $(this).find(':selected').data('href');
});
};
$.fn.deleteCheckinModal = function () { $.fn.deleteCheckinModal = function () {
return this.each(function () { return this.each(function () {
$(this) $(this)