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

トゥートの並び順をフリップするボタンを作成 #81

Merged
merged 5 commits into from
Jan 11, 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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1><a href="./">mastogetter</a></h1>
</span>
</p>
</div>
<input id="flip" type="button" value="flip"></input>
<div id="cards">
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ export function handleDrop(e) {
let node_index = -1;
for (let i = 0; i < children.length; i++) {
if (children[i] === src) {
src_index = i - 1;
src_index = i;
}
if (children[i] === node) {
node_index = i - 1;
node_index = i;
}
}
if (src_index < 0) {
Expand Down
24 changes: 24 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,31 @@ function addCard() {
.reverse()[0]
);

if ($("cards").hasChildNodes() && $("cards").firstChild.nodeName === "#text") {
$("cards").removeChild($("cards").firstChild);
}
$("cards").appendChild(clone);
impl.genPermalink();
}

function flipCards() {
const cards = $("cards");
if (!cards) return;
let card_nodes = [];
while (cards.hasChildNodes()) {
if (cards.firstChild.nodeName !== "#text") {
card_nodes.push(cards.firstChild);
}
cards.removeChild(cards.firstChild);
}
if (card_nodes.length === 0) return;
while (card_nodes.length > 0) {
cards.appendChild(card_nodes.pop());
}
impl.card_list.reverse();
impl.genPermalink();
}

function copyPermalink() {
if (isEmptyPermalink()) {
alertUsageNoPermalink();
Expand Down Expand Up @@ -125,4 +146,7 @@ impl.ready(() => {
$("copylink").addEventListener("click", () => {
copyPermalink();
});
$("flip").addEventListener("click", () => {
flipCards();
});
});