Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 削除対象はeventの引数を利用する #98

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export const get_url_vars = (function() {
})();

/**
* @param {Element} target
* @param {number} index
* @param {string} prefix
*/
export function deleteCard(index, prefix) {
$("cards").removeChild($(`${prefix}_${index}`));
export function deleteCard(target, index) {
while (!target.getAttribute("data-dblclickable")) {
target = target.parentNode;
}
target.parentElement.removeChild(target);
card_list.splice(index, 1);
genPermalink();
}
Expand Down Expand Up @@ -112,9 +115,7 @@ export function showCards(permalink_obj) {
</div>`;
const idx = max_index;
toot_div.setAttribute("id", `o_${idx}`);
toot_div.addEventListener("dblclick", () => {
deleteCard(idx, "o");
});
toot_div.addEventListener("dblclick", e => deleteCard(e.target, idx));
toot_div.setAttribute("draggable", "true");
toot_div.setAttribute("data-dblclickable", "true");
toot_div.addEventListener("dragstart", e => handleDragStart(e), false);
Expand Down
4 changes: 1 addition & 3 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ function addCard() {
const clone = $("card-preview").firstElementChild.cloneNode(true);
const len = impl.card_list.length;
clone.setAttribute("id", `c_${len}`);
clone.addEventListener("dblclick", () => {
impl.deleteCard(len, "c");
});
clone.addEventListener("dblclick", e => impl.deleteCard(e.target, len));
clone.setAttribute("data-dblclickable", "true");
clone.setAttribute("draggable", "true");
clone.addEventListener("dragstart", e => impl.handleDragStart(e), false);
Expand Down