-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from shikorism/replace-jquery-tissue-plugin
Replace jquery tissue plugin
- Loading branch information
Showing
6 changed files
with
84 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
// jQuery | ||
import './tissue'; | ||
|
||
// Bootstrap | ||
import 'bootstrap'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,73 @@ | ||
import { fetchGet } from './fetch'; | ||
|
||
(function ($) { | ||
$.fn.linkCard = function (options) { | ||
const settings = $.extend( | ||
{ | ||
endpoint: '/api/checkin/card', | ||
}, | ||
options | ||
); | ||
export function suicide<T>(e: T) { | ||
return function (): never { | ||
throw e; | ||
}; | ||
} | ||
|
||
return this.each(function () { | ||
const $this = $(this); | ||
const die = suicide('Element not found!'); | ||
|
||
const url = $this.find('a').attr('href'); | ||
if (!url) { | ||
return; | ||
} | ||
export function linkCard(el: Element) { | ||
const url = el.querySelector('a')?.href; | ||
if (!url) { | ||
return; | ||
} | ||
|
||
fetchGet(settings.endpoint, { url }) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
const $metaColumn = $this.find('.col-12:last-of-type'); | ||
const $imageColumn = $this.find('.col-12:first-of-type'); | ||
const $title = $this.find('.card-title'); | ||
const $desc = $this.find('.card-text'); | ||
const $image = $imageColumn.find('img'); | ||
fetchGet('/api/checkin/card', { url }) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
const metaColumn = el.querySelector('.col-12:last-of-type') || die(); | ||
const imageColumn = el.querySelector<HTMLElement>('.col-12:first-of-type') || die(); | ||
const title = el.querySelector<HTMLElement>('.card-title') || die(); | ||
const desc = el.querySelector<HTMLElement>('.card-text') || die(); | ||
const image = imageColumn.querySelector('img') || die(); | ||
|
||
if (data.title === '') { | ||
$title.hide(); | ||
} else { | ||
$title.text(data.title); | ||
} | ||
if (data.title === '') { | ||
title.style.display = 'none'; | ||
} else { | ||
title.textContent = data.title; | ||
} | ||
|
||
if (data.description === '') { | ||
$desc.hide(); | ||
} else { | ||
$desc.text(data.description); | ||
} | ||
if (data.description === '') { | ||
desc.style.display = 'none'; | ||
} else { | ||
desc.textContent = data.description; | ||
} | ||
|
||
if (data.image === '') { | ||
$imageColumn.hide(); | ||
$metaColumn.removeClass('col-md-6'); | ||
} else { | ||
$image.attr('src', data.image); | ||
} | ||
if (data.image === '') { | ||
imageColumn.style.display = 'none'; | ||
metaColumn.classList.remove('col-md-6'); | ||
} else { | ||
image.src = data.image; | ||
} | ||
|
||
if (data.title !== '' || data.description !== '' || data.image !== '') { | ||
$this.removeClass('d-none'); | ||
} | ||
}); | ||
if (data.title !== '' || data.description !== '' || data.image !== '') { | ||
el.classList.remove('d-none'); | ||
} | ||
}); | ||
}; | ||
|
||
$.fn.pageSelector = function () { | ||
return this.on('change', function () { | ||
location.href = $(this).find(':selected').data('href'); | ||
}); | ||
}; | ||
return el; | ||
} | ||
|
||
$.fn.deleteCheckinModal = function () { | ||
return this.each(function () { | ||
$(this) | ||
.on('show.bs.modal', function (event) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const target = $(event.relatedTarget!); | ||
const modal = $(this); | ||
modal.find('.modal-body .date-label').text(target.data('date')); | ||
modal.data('id', target.data('id')); | ||
}) | ||
.find('.btn-danger') | ||
.on('click', function (_event) { | ||
const modal = $('#deleteCheckinModal'); | ||
const form = modal.find('form'); | ||
form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null); | ||
form.submit(); | ||
}); | ||
export function pageSelector(el: Element) { | ||
if (el instanceof HTMLSelectElement) { | ||
el.addEventListener('change', function () { | ||
location.href = this.options[this.selectedIndex].dataset.href as string; | ||
}); | ||
}; | ||
})(jQuery); | ||
} | ||
return el; | ||
} | ||
|
||
export function deleteCheckinModal(modal: Element) { | ||
let id: any = null; | ||
modal.querySelector('form')?.addEventListener('submit', function () { | ||
this.action = this.action.replace('@', id); | ||
}); | ||
return $(modal).on('show.bs.modal', function (event) { | ||
const target = event.relatedTarget || die(); | ||
const dateLabel = this.querySelector('.modal-body .date-label') || die(); | ||
dateLabel.textContent = target.dataset.date || null; | ||
id = target.dataset.id; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters