2020-09-15 01:33:53 +00:00
|
|
|
const photo_clipboard = {};
|
2018-07-23 02:43:07 +00:00
|
|
|
|
|
|
|
photo_clipboard.clipboard = new Set();
|
|
|
|
photo_clipboard.on_load_hooks = [];
|
|
|
|
photo_clipboard.on_save_hooks = [];
|
2017-12-10 01:48:56 +00:00
|
|
|
|
2018-01-20 06:24:07 +00:00
|
|
|
// Load save ///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clear_clipboard =
|
|
|
|
function clear_clipboard()
|
2018-02-25 07:00:28 +00:00
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard.clear();
|
|
|
|
photo_clipboard.save_clipboard();
|
2018-02-25 07:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.load_clipboard =
|
|
|
|
function load_clipboard(event)
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2020-09-03 18:46:26 +00:00
|
|
|
console.log("Loading photo clipboard from localstorage.");
|
2020-09-15 01:33:53 +00:00
|
|
|
const stored = localStorage.getItem("photo_clipboard");
|
2017-12-10 01:48:56 +00:00
|
|
|
if (stored === null)
|
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
if (photo_clipboard.clipboard.size != 0)
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard = new Set();
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard = new Set(JSON.parse(stored));
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
2018-02-18 00:31:51 +00:00
|
|
|
|
2020-09-03 22:33:37 +00:00
|
|
|
for (const on_load_hook of photo_clipboard.on_load_hooks)
|
2018-02-18 00:31:51 +00:00
|
|
|
{
|
2020-09-03 22:33:37 +00:00
|
|
|
on_load_hook();
|
2018-02-18 00:31:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
return photo_clipboard.clipboard;
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.save_clipboard =
|
|
|
|
function save_clipboard()
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2020-09-03 18:46:26 +00:00
|
|
|
console.log("Saving photo clipboard to localstorage.");
|
2020-09-15 01:33:53 +00:00
|
|
|
const serialized = JSON.stringify(Array.from(photo_clipboard.clipboard));
|
2017-12-10 01:48:56 +00:00
|
|
|
localStorage.setItem("photo_clipboard", serialized);
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.update_pagestate();
|
2018-02-18 00:31:51 +00:00
|
|
|
|
2020-09-03 22:33:37 +00:00
|
|
|
for (const on_save_hook of photo_clipboard.on_save_hooks)
|
2018-02-18 00:31:51 +00:00
|
|
|
{
|
2020-09-03 22:33:37 +00:00
|
|
|
on_save_hook();
|
2018-02-18 00:31:51 +00:00
|
|
|
}
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 06:24:07 +00:00
|
|
|
// Card management /////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-01-05 09:24:03 +00:00
|
|
|
photo_clipboard.give_checkbox =
|
|
|
|
function give_checkbox(photo_card)
|
|
|
|
{
|
|
|
|
// There are some UIs where photo cards appear
|
|
|
|
const checkbox = document.createElement("input")
|
|
|
|
checkbox.type = "checkbox";
|
|
|
|
checkbox.className = "photo_clipboard_selector_checkbox";
|
|
|
|
checkbox.onclick = function(event)
|
|
|
|
{
|
|
|
|
return photo_clipboard.on_photo_select(event);
|
|
|
|
}
|
|
|
|
photo_card.appendChild(checkbox);
|
|
|
|
return checkbox;
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.apply_check =
|
2020-09-10 03:09:41 +00:00
|
|
|
function apply_check(checkbox)
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
2020-09-10 03:09:41 +00:00
|
|
|
Check the checkbox if this photo ID is on the clipboard.
|
|
|
|
|
|
|
|
There are two valid scenarios:
|
|
|
|
1. The checkbox is a child of a photo_card div, and that div has data-id
|
|
|
|
containing the photo id. That div will receive the CSS class
|
|
|
|
photo_card_selected or photo_card_unselected.
|
|
|
|
This is the most common usage.
|
|
|
|
2. The checkbox has its own data-photo-id, and the parent element will be
|
|
|
|
ignored. This is used only if the checkbox needs to be displayed outside
|
|
|
|
of a photo card, such as on the /photo/id page where it makes no sense
|
|
|
|
to put a photo card of the photo you're already looking at.
|
2018-01-20 06:24:07 +00:00
|
|
|
*/
|
2020-09-10 03:09:41 +00:00
|
|
|
let photo_id;
|
|
|
|
let photo_card;
|
|
|
|
if (checkbox.dataset.photoId)
|
|
|
|
{
|
|
|
|
photo_id = checkbox.dataset.photoId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
photo_card = checkbox.parentElement;
|
|
|
|
photo_id = photo_card.dataset.id;
|
|
|
|
}
|
|
|
|
checkbox.checked = photo_clipboard.clipboard.has(photo_id);
|
|
|
|
if (! photo_card)
|
|
|
|
{
|
2020-12-26 21:11:31 +00:00
|
|
|
// E.g. on the Photo page there is a checkbox for adding it to the
|
|
|
|
// clipboard, though it does not reside in a photo_card div.
|
2020-09-10 03:09:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-20 09:32:33 +00:00
|
|
|
if (checkbox.checked)
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2018-10-20 09:32:33 +00:00
|
|
|
photo_card.classList.remove("photo_card_unselected");
|
|
|
|
photo_card.classList.add("photo_card_selected");
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-20 09:32:33 +00:00
|
|
|
photo_card.classList.remove("photo_card_selected");
|
|
|
|
photo_card.classList.add("photo_card_unselected");
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.apply_check_all =
|
2018-01-20 06:24:07 +00:00
|
|
|
function apply_check_all()
|
2017-12-16 11:47:54 +00:00
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
2021-01-05 09:24:03 +00:00
|
|
|
Run through all the photo cards, give them their checkbox if they don't
|
|
|
|
already have it, and check it if that photo is on the clipboard.
|
2018-01-20 06:24:07 +00:00
|
|
|
*/
|
2021-01-05 09:24:03 +00:00
|
|
|
const cards = document.getElementsByClassName("photo_card");
|
|
|
|
for (const card of cards)
|
2020-09-10 03:09:41 +00:00
|
|
|
{
|
2021-01-05 09:24:03 +00:00
|
|
|
let checkbox = card.getElementsByClassName("photo_clipboard_selector_checkbox")[0];
|
|
|
|
if (! checkbox)
|
|
|
|
{
|
|
|
|
checkbox = photo_clipboard.give_checkbox(card);
|
|
|
|
}
|
2020-09-10 03:09:41 +00:00
|
|
|
photo_clipboard.apply_check(checkbox);
|
|
|
|
}
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.previous_photo_select = null;
|
|
|
|
|
|
|
|
photo_clipboard.on_photo_select =
|
2017-12-10 01:48:56 +00:00
|
|
|
function on_photo_select(event)
|
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
|
|
|
Select or unselect the clicked photo, with support for Shift-click to action
|
|
|
|
everything between the previous click and this one inclusively.
|
|
|
|
|
|
|
|
Those middle items will be set to the same state as the new state of the
|
|
|
|
clicked item.
|
|
|
|
*/
|
2020-09-10 15:20:55 +00:00
|
|
|
const checkbox = event.target;
|
|
|
|
let action;
|
|
|
|
if (checkbox.checked)
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2020-12-26 21:11:31 +00:00
|
|
|
action = function(photo_div)
|
|
|
|
{
|
|
|
|
console.log("photo_card_selected");
|
|
|
|
photo_clipboard.clipboard.add(photo_div.dataset.id);
|
|
|
|
photo_div.classList.remove("photo_card_unselected");
|
|
|
|
photo_div.classList.add("photo_card_selected");
|
|
|
|
}
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-26 21:11:31 +00:00
|
|
|
action = function(photo_div)
|
|
|
|
{
|
|
|
|
console.log("photo_card_unselected");
|
|
|
|
photo_clipboard.clipboard.delete(photo_div.dataset.id);
|
|
|
|
photo_div.classList.remove("photo_card_selected");
|
|
|
|
photo_div.classList.add("photo_card_unselected");
|
|
|
|
}
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 15:20:55 +00:00
|
|
|
if (! checkbox.parentElement.classList.contains("photo_card"))
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2020-12-26 21:11:31 +00:00
|
|
|
if (checkbox.checked)
|
|
|
|
{
|
|
|
|
photo_clipboard.clipboard.add(checkbox.dataset.photoId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
photo_clipboard.clipboard.delete(checkbox.dataset.photoId);
|
|
|
|
}
|
2020-09-10 15:20:55 +00:00
|
|
|
}
|
|
|
|
else if (event.shiftKey && photo_clipboard.previous_photo_select)
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const current_photo_div = checkbox.parentElement;
|
|
|
|
const previous_photo_div = photo_clipboard.previous_photo_select;
|
|
|
|
const photo_divs = Array.from(current_photo_div.parentElement.getElementsByClassName("photo_card"));
|
2017-12-10 01:48:56 +00:00
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
const current_index = photo_divs.indexOf(current_photo_div);
|
|
|
|
const previous_index = photo_divs.indexOf(previous_photo_div);
|
2017-12-10 01:48:56 +00:00
|
|
|
|
2020-09-03 22:02:37 +00:00
|
|
|
let slice;
|
2017-12-10 01:48:56 +00:00
|
|
|
if (current_index == previous_index)
|
|
|
|
{
|
|
|
|
slice = [current_photo_div];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const left = Math.min(previous_index, current_index);
|
|
|
|
const right = Math.max(previous_index, current_index);
|
2018-10-20 23:18:02 +00:00
|
|
|
slice = photo_divs.slice(left, right + 1);
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
for (const photo_div of slice)
|
2020-09-10 15:20:55 +00:00
|
|
|
{
|
2020-12-26 21:11:31 +00:00
|
|
|
action(photo_div);
|
2020-09-10 15:20:55 +00:00
|
|
|
}
|
|
|
|
photo_clipboard.previous_photo_select = current_photo_div;
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const photo_div = checkbox.parentElement;
|
2020-12-26 21:11:31 +00:00
|
|
|
action(photo_div);
|
2020-09-10 15:20:55 +00:00
|
|
|
photo_clipboard.previous_photo_select = photo_div;
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
2020-12-26 21:11:31 +00:00
|
|
|
setTimeout(() => photo_clipboard.save_clipboard(), 0);
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.select_all_photos =
|
2018-03-23 18:58:39 +00:00
|
|
|
function select_all_photos()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const photo_divs = Array.from(document.getElementsByClassName("photo_card"));
|
|
|
|
for (const photo_div of photo_divs)
|
2020-09-10 15:20:55 +00:00
|
|
|
{
|
|
|
|
photo_clipboard.clipboard.add(photo_div.dataset.id);
|
2020-12-26 21:11:31 +00:00
|
|
|
photo_div.classList.remove("photo_card_unselected");
|
|
|
|
photo_div.classList.add("photo_card_selected");
|
2021-01-05 07:31:41 +00:00
|
|
|
const checkbox = photo_div.getElementsByClassName("photo_clipboard_selector_checkbox")[0];
|
2020-12-26 21:11:31 +00:00
|
|
|
if (checkbox)
|
|
|
|
{
|
|
|
|
checkbox.checked = true;
|
|
|
|
}
|
2020-09-10 15:20:55 +00:00
|
|
|
}
|
2020-12-26 21:11:31 +00:00
|
|
|
photo_clipboard.previous_photo_select = null;
|
|
|
|
setTimeout(() => photo_clipboard.save_clipboard(), 0);
|
2018-03-23 18:58:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.unselect_all_photos =
|
2018-03-23 18:58:39 +00:00
|
|
|
function unselect_all_photos()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const photo_divs = Array.from(document.getElementsByClassName("photo_card"));
|
|
|
|
for (const photo_div of photo_divs)
|
2020-09-10 15:20:55 +00:00
|
|
|
{
|
|
|
|
photo_clipboard.clipboard.delete(photo_div.dataset.id);
|
2020-12-26 21:11:31 +00:00
|
|
|
photo_div.classList.remove("photo_card_selected");
|
|
|
|
photo_div.classList.add("photo_card_unselected");
|
2021-01-05 07:31:41 +00:00
|
|
|
const checkbox = photo_div.getElementsByClassName("photo_clipboard_selector_checkbox")[0];
|
2020-12-26 21:11:31 +00:00
|
|
|
if (checkbox)
|
|
|
|
{
|
|
|
|
checkbox.checked = false;
|
|
|
|
}
|
2020-09-10 15:20:55 +00:00
|
|
|
}
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.previous_photo_select = null;
|
2020-12-26 21:11:31 +00:00
|
|
|
setTimeout(() => photo_clipboard.save_clipboard(), 0);
|
2018-03-23 18:58:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 06:24:07 +00:00
|
|
|
// Tray management /////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard_tray_collapse =
|
2018-02-21 04:20:20 +00:00
|
|
|
function clipboard_tray_collapse()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const tray_body = document.getElementById("clipboard_tray_body");
|
2018-02-21 04:20:20 +00:00
|
|
|
tray_body.classList.add("hidden");
|
|
|
|
}
|
2018-07-23 02:43:07 +00:00
|
|
|
|
|
|
|
photo_clipboard.clipboard_tray_uncollapse =
|
2018-02-21 04:20:20 +00:00
|
|
|
function clipboard_tray_uncollapse()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const tray_body = document.getElementById("clipboard_tray_body");
|
2018-02-21 04:20:20 +00:00
|
|
|
tray_body.classList.remove("hidden");
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.update_clipboard_tray();
|
2018-02-21 04:20:20 +00:00
|
|
|
}
|
2018-07-23 02:43:07 +00:00
|
|
|
|
|
|
|
photo_clipboard.clipboard_tray_collapse_toggle =
|
2018-02-21 04:20:20 +00:00
|
|
|
function clipboard_tray_collapse_toggle()
|
2017-12-16 11:47:54 +00:00
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
|
|
|
Show or hide the clipboard.
|
|
|
|
*/
|
2020-09-15 01:33:53 +00:00
|
|
|
const tray_body = document.getElementById("clipboard_tray_body");
|
2018-07-14 09:54:39 +00:00
|
|
|
if (!tray_body)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
if (tray_body.classList.contains("hidden") && photo_clipboard.clipboard.size > 0)
|
2017-12-16 11:47:54 +00:00
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard_tray_uncollapse();
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard_tray_collapse();
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:29:05 +00:00
|
|
|
photo_clipboard.ingest_toolbox_items =
|
|
|
|
function ingest_toolbox_items()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The page may provide divs with the class "my_clipboard_tray_toolbox", and
|
|
|
|
we will migrate all the elements into the real clipboard tray toolbox.
|
|
|
|
*/
|
2020-09-15 01:33:53 +00:00
|
|
|
const toolbox = document.getElementById("clipboard_tray_toolbox");
|
|
|
|
const moreboxes = document.getElementsByClassName("my_clipboard_tray_toolbox");
|
2020-09-03 22:33:37 +00:00
|
|
|
|
|
|
|
for (const morebox of moreboxes)
|
2018-09-23 21:29:05 +00:00
|
|
|
{
|
2020-09-03 22:33:37 +00:00
|
|
|
while (morebox.firstElementChild)
|
2018-09-23 21:29:05 +00:00
|
|
|
{
|
2020-09-03 22:33:37 +00:00
|
|
|
toolbox.appendChild(morebox.firstElementChild);
|
2018-09-23 21:29:05 +00:00
|
|
|
}
|
2020-09-03 22:33:37 +00:00
|
|
|
morebox.parentElement.removeChild(morebox);
|
2018-09-23 21:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.on_tray_delete_button =
|
2017-12-16 11:47:54 +00:00
|
|
|
function on_tray_delete_button(event)
|
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
|
|
|
Remove the clicked row from the clipboard.
|
|
|
|
*/
|
2020-09-15 01:33:53 +00:00
|
|
|
const clipboard_line = event.target.parentElement;
|
|
|
|
const photo_id = clipboard_line.dataset.id;
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard.delete(photo_id);
|
|
|
|
photo_clipboard.save_clipboard();
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.update_clipboard_tray =
|
2017-12-16 11:47:54 +00:00
|
|
|
function update_clipboard_tray()
|
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
2018-02-21 04:20:20 +00:00
|
|
|
Rebuild the rows if the tray is open.
|
2018-01-20 06:24:07 +00:00
|
|
|
*/
|
2020-09-15 01:33:53 +00:00
|
|
|
const clipboard_tray = document.getElementById("clipboard_tray");
|
2018-02-18 03:12:34 +00:00
|
|
|
if (clipboard_tray === null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
if (photo_clipboard.clipboard.size == 0)
|
2018-02-22 21:36:31 +00:00
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.clipboard_tray_collapse();
|
2018-02-22 21:36:31 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
const tray_lines = document.getElementById("clipboard_tray_lines");
|
2017-12-16 11:47:54 +00:00
|
|
|
if (!clipboard_tray.classList.contains("hidden"))
|
|
|
|
{
|
2018-07-23 02:12:08 +00:00
|
|
|
common.delete_all_children(tray_lines);
|
2020-09-15 01:33:53 +00:00
|
|
|
const photo_ids = Array.from(photo_clipboard.clipboard);
|
2017-12-16 11:47:54 +00:00
|
|
|
photo_ids.sort();
|
2020-09-03 22:33:37 +00:00
|
|
|
for (const photo_id of photo_ids)
|
2017-12-16 11:47:54 +00:00
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const clipboard_line = document.createElement("div");
|
2017-12-16 11:47:54 +00:00
|
|
|
clipboard_line.classList.add("clipboard_tray_line");
|
2020-09-03 22:33:37 +00:00
|
|
|
clipboard_line.dataset.id = photo_id;
|
2017-12-16 11:47:54 +00:00
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
const clipboard_line_delete_button = document.createElement("button");
|
2017-12-16 11:47:54 +00:00
|
|
|
clipboard_line_delete_button.classList.add("remove_tag_button_perm");
|
2017-12-16 22:13:02 +00:00
|
|
|
clipboard_line_delete_button.classList.add("red_button");
|
2018-07-23 02:43:07 +00:00
|
|
|
clipboard_line_delete_button.onclick = photo_clipboard.on_tray_delete_button;
|
2017-12-16 11:47:54 +00:00
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
const clipboard_line_link = document.createElement("a");
|
2017-12-16 11:47:54 +00:00
|
|
|
clipboard_line_link.target = "_blank";
|
2020-09-03 22:33:37 +00:00
|
|
|
clipboard_line_link.href = "/photo/" + photo_id;
|
|
|
|
clipboard_line_link.innerText = photo_id;
|
2017-12-16 11:47:54 +00:00
|
|
|
|
|
|
|
clipboard_line.appendChild(clipboard_line_delete_button);
|
|
|
|
clipboard_line.appendChild(clipboard_line_link);
|
2017-12-16 20:24:46 +00:00
|
|
|
tray_lines.appendChild(clipboard_line);
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 09:54:39 +00:00
|
|
|
// Page and event management ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.open_full_clipboard_tab =
|
2018-07-14 09:54:39 +00:00
|
|
|
function open_full_clipboard_tab()
|
|
|
|
{
|
2019-08-26 00:17:40 +00:00
|
|
|
window.open("/clipboard");
|
2018-07-14 09:54:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.on_storage_event =
|
2018-07-14 21:19:13 +00:00
|
|
|
function on_storage_event()
|
2017-12-10 01:48:56 +00:00
|
|
|
{
|
2018-01-20 06:24:07 +00:00
|
|
|
/*
|
|
|
|
Receive storage events from other tabs and update our state to match.
|
|
|
|
*/
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.load_clipboard();
|
|
|
|
photo_clipboard.update_pagestate();
|
2018-02-21 04:20:20 +00:00
|
|
|
}
|
2018-07-14 21:19:13 +00:00
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.update_pagestate =
|
2018-02-21 04:20:20 +00:00
|
|
|
function update_pagestate()
|
|
|
|
{
|
2020-09-03 18:46:26 +00:00
|
|
|
/*
|
|
|
|
Update all relevant DOM elements to match internal state.
|
|
|
|
*/
|
2021-01-08 04:18:07 +00:00
|
|
|
common.update_dynamic_elements("dynamic_clipboard_count", photo_clipboard.clipboard.size);
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.update_clipboard_tray();
|
|
|
|
photo_clipboard.apply_check_all();
|
2017-12-16 11:47:54 +00:00
|
|
|
}
|
2018-07-14 21:19:13 +00:00
|
|
|
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.on_pageload =
|
2017-12-16 11:47:54 +00:00
|
|
|
function on_pageload()
|
|
|
|
{
|
2018-07-23 02:43:07 +00:00
|
|
|
window.addEventListener("storage", photo_clipboard.on_storage_event, false);
|
2020-09-03 18:47:40 +00:00
|
|
|
hotkeys.register_hotkey("ctrl a", photo_clipboard.select_all_photos, "Select all photos.");
|
|
|
|
hotkeys.register_hotkey("ctrl d", photo_clipboard.unselect_all_photos, "Deselect all photos.");
|
|
|
|
hotkeys.register_hotkey("c", photo_clipboard.clipboard_tray_collapse_toggle, "Toggle clipboard tray.");
|
|
|
|
hotkeys.register_hotkey("shift c", photo_clipboard.open_full_clipboard_tab, "Open full clipboard page.");
|
2018-09-23 21:29:05 +00:00
|
|
|
photo_clipboard.ingest_toolbox_items();
|
2018-07-23 02:43:07 +00:00
|
|
|
photo_clipboard.load_clipboard();
|
|
|
|
photo_clipboard.update_pagestate();
|
2017-12-10 01:48:56 +00:00
|
|
|
}
|
2018-07-23 02:43:07 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", photo_clipboard.on_pageload);
|