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: previewページで削除できなくする #85

Merged
merged 3 commits into from
Jan 14, 2020
Merged
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
37 changes: 27 additions & 10 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,30 @@ function addPermalink(toot_csv) {
$("permalink").value += toot_csv;
}

export function showCards(permalink_obj) {
/**
*
* @param {Element} element DOM Element
* @param {number} index
* @param {string} prefix
*/
export function registerEventsToCard(element, index, prefix) {
element.addEventListener("dblclick", () => {
deleteCard(index, prefix);
});
element.setAttribute("draggable", "true");
element.setAttribute("data-dblclickable", "true");
element.addEventListener("dragstart", e => handleDragStart(e), false);
element.addEventListener("dragover", e => handleDragOver(e), false);
element.addEventListener("drop", e => handleDrop(e), false);
element.addEventListener("dragend", e => handleDragEnd(e), false);
}

/**
*
* @param {{instance_full: string, instance: string, toot_ids: string[]}} permalink_obj created by `decodePermalink`
* @param {boolean | undefined} registerEvent
*/
export function showCards(permalink_obj, registerEvent = false) {
const instance_full = permalink_obj["instance_full"];
const toot_ids = permalink_obj["toot_ids"];
const xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -127,15 +150,9 @@ 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.setAttribute("draggable", "true");
toot_div.setAttribute("data-dblclickable", "true");
toot_div.addEventListener("dragstart", e => handleDragStart(e), false);
toot_div.addEventListener("dragover", e => handleDragOver(e), false);
toot_div.addEventListener("drop", e => handleDrop(e), false);
toot_div.addEventListener("dragend", e => handleDragEnd(e), false);
if (true === registerEvent) {
registerEventsToCard(toot_div, idx, "o");
}
max_index++;
target_div.appendChild(toot_div);
} else {
Expand Down
10 changes: 1 addition & 9 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +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.setAttribute("data-dblclickable", "true");
clone.setAttribute("draggable", "true");
clone.addEventListener("dragstart", e => impl.handleDragStart(e), false);
clone.addEventListener("dragover", e => impl.handleDragOver(e), false);
clone.addEventListener("drop", e => impl.handleDrop(e), false);
clone.addEventListener("dragend", e => impl.handleDragEnd(e), false);
impl.registerEventsToCard(clone, len, "c");
impl.card_list.push(
$("toot-id")
.value.split("/")
Expand Down