Use more const.

This commit is contained in:
voussoir 2020-09-14 18:33:53 -07:00
parent 7fecd65b33
commit dd0ee7a72a
14 changed files with 227 additions and 228 deletions

View file

@ -1,4 +1,4 @@
var api = {}; const api = {};
/**************************************************************************************************/ /**************************************************************************************************/
api.albums = {}; api.albums = {};

View file

@ -1,12 +1,12 @@
var common = {}; const common = {};
common.INPUT_TYPES = new Set(["INPUT", "TEXTAREA"]); common.INPUT_TYPES = new Set(["INPUT", "TEXTAREA"]);
common._request = common._request =
function _request(method, url, callback) function _request(method, url, callback)
{ {
let request = new XMLHttpRequest(); const request = new XMLHttpRequest();
let response = { const response = {
"completed": false, "completed": false,
}; };
@ -29,7 +29,7 @@ function _request(method, url, callback)
} }
callback(response); callback(response);
}; };
let asynchronous = true; const asynchronous = true;
request.open(method, url, asynchronous); request.open(method, url, asynchronous);
return request; return request;
} }
@ -61,7 +61,7 @@ function bind_box_to_button(box, button, ctrl_enter)
Thanks Yaroslav Yakovlev Thanks Yaroslav Yakovlev
http://stackoverflow.com/a/9343095 http://stackoverflow.com/a/9343095
*/ */
let bound_box_hook = function(event) const bound_box_hook = function(event)
{ {
if (event.key !== "Enter") if (event.key !== "Enter")
{return;} {return;}
@ -83,9 +83,9 @@ function create_message_bubble(message_area, message_positivity, message_text, l
{ {
lifespan = 8000; lifespan = 8000;
} }
let message = document.createElement("div"); const message = document.createElement("div");
message.className = "message_bubble " + message_positivity; message.className = "message_bubble " + message_positivity;
let span = document.createElement("span"); const span = document.createElement("span");
span.innerHTML = message_text; span.innerHTML = message_text;
message.appendChild(span); message.appendChild(span);
message_area.appendChild(message); message_area.appendChild(message);
@ -168,7 +168,7 @@ function entry_with_history_hook(event)
common.html_to_element = common.html_to_element =
function html_to_element(html) function html_to_element(html)
{ {
let template = document.createElement("template"); const template = document.createElement("template");
template.innerHTML = html.trim(); template.innerHTML = html.trim();
return template.content.firstElementChild; return template.content.firstElementChild;
} }
@ -200,13 +200,13 @@ function init_atag_merge_params(a)
if (a.dataset.mergeParams) if (a.dataset.mergeParams)
{ {
let keep = new Set(a.dataset.mergeParams.split(/[\s,]+/)); const keep = new Set(a.dataset.mergeParams.split(/[\s,]+/));
to_merge = page_params.filter(key_value => keep.has(key_value[0])); to_merge = page_params.filter(key_value => keep.has(key_value[0]));
delete a.dataset.mergeParams; delete a.dataset.mergeParams;
} }
else if (a.dataset.mergeParamsExcept) else if (a.dataset.mergeParamsExcept)
{ {
let remove = new Set(a.dataset.mergeParamsExcept.split(/[\s,]+/)); const remove = new Set(a.dataset.mergeParamsExcept.split(/[\s,]+/));
to_merge = page_params.filter(key_value => (! remove.has(key_value[0]))); to_merge = page_params.filter(key_value => (! remove.has(key_value[0])));
delete a.dataset.mergeParamsExcept; delete a.dataset.mergeParamsExcept;
} }
@ -227,7 +227,7 @@ common.init_all_atag_merge_params =
function init_all_atag_merge_params() function init_all_atag_merge_params()
{ {
const page_params = Array.from(new URLSearchParams(window.location.search)); const page_params = Array.from(new URLSearchParams(window.location.search));
let as = Array.from(document.getElementsByClassName("merge_params")); const as = Array.from(document.getElementsByClassName("merge_params"));
for (const a of as) for (const a of as)
{ {
setTimeout(() => common.init_atag_merge_params(a), 0); setTimeout(() => common.init_atag_merge_params(a), 0);
@ -269,16 +269,16 @@ function init_button_with_confirm(button)
*/ */
button.classList.remove("button_with_confirm"); button.classList.remove("button_with_confirm");
let holder = document.createElement("span"); const holder = document.createElement("span");
holder.className = "confirm_holder " + (button.dataset.holderClass || ""); holder.className = "confirm_holder " + (button.dataset.holderClass || "");
button.parentElement.insertBefore(holder, button); button.parentElement.insertBefore(holder, button);
let holder_stage1 = document.createElement("span"); const holder_stage1 = document.createElement("span");
holder_stage1.className = "confirm_holder_stage1"; holder_stage1.className = "confirm_holder_stage1";
holder_stage1.appendChild(button); holder_stage1.appendChild(button);
holder.appendChild(holder_stage1); holder.appendChild(holder_stage1);
let holder_stage2 = document.createElement("span"); const holder_stage2 = document.createElement("span");
holder_stage2.className = "confirm_holder_stage2 hidden"; holder_stage2.className = "confirm_holder_stage2 hidden";
holder.appendChild(holder_stage2); holder.appendChild(holder_stage2);
@ -301,7 +301,7 @@ function init_button_with_confirm(button)
delete button.dataset.prompt; delete button.dataset.prompt;
delete button.dataset.promptClass; delete button.dataset.promptClass;
let button_confirm = document.createElement("button"); const button_confirm = document.createElement("button");
button_confirm.innerText = (button.dataset.confirm || button.innerText).trim(); button_confirm.innerText = (button.dataset.confirm || button.innerText).trim();
if (button.dataset.confirmClass === undefined) if (button.dataset.confirmClass === undefined)
{ {
@ -323,7 +323,7 @@ function init_button_with_confirm(button)
delete button.dataset.confirmClass; delete button.dataset.confirmClass;
delete button.dataset.isInput; delete button.dataset.isInput;
let button_cancel = document.createElement("button"); const button_cancel = document.createElement("button");
button_cancel.innerText = button.dataset.cancel || "Cancel"; button_cancel.innerText = button.dataset.cancel || "Cancel";
button_cancel.className = button.dataset.cancelClass || ""; button_cancel.className = button.dataset.cancelClass || "";
holder_stage2.appendChild(button_cancel); holder_stage2.appendChild(button_cancel);
@ -331,7 +331,7 @@ function init_button_with_confirm(button)
delete button.dataset.cancelClass; delete button.dataset.cancelClass;
// If this is stupid, let me know. // If this is stupid, let me know.
let confirm_onclick = ` const confirm_onclick = `
let holder = event.target.parentElement.parentElement; let holder = event.target.parentElement.parentElement;
holder.getElementsByClassName("confirm_holder_stage1")[0].classList.remove("hidden"); holder.getElementsByClassName("confirm_holder_stage1")[0].classList.remove("hidden");
holder.getElementsByClassName("confirm_holder_stage2")[0].classList.add("hidden"); holder.getElementsByClassName("confirm_holder_stage2")[0].classList.add("hidden");
@ -341,10 +341,10 @@ function init_button_with_confirm(button)
button.removeAttribute("onclick"); button.removeAttribute("onclick");
button.onclick = function(event) button.onclick = function(event)
{ {
let holder = event.target.parentElement.parentElement; const holder = event.target.parentElement.parentElement;
holder.getElementsByClassName("confirm_holder_stage1")[0].classList.add("hidden"); holder.getElementsByClassName("confirm_holder_stage1")[0].classList.add("hidden");
holder.getElementsByClassName("confirm_holder_stage2")[0].classList.remove("hidden"); holder.getElementsByClassName("confirm_holder_stage2")[0].classList.remove("hidden");
let input = holder.getElementsByTagName("input")[0]; const input = holder.getElementsByTagName("input")[0];
if (input) if (input)
{ {
input.focus(); input.focus();
@ -353,7 +353,7 @@ function init_button_with_confirm(button)
button_cancel.onclick = function(event) button_cancel.onclick = function(event)
{ {
let holder = event.target.parentElement.parentElement; const holder = event.target.parentElement.parentElement;
holder.getElementsByClassName("confirm_holder_stage1")[0].classList.remove("hidden"); holder.getElementsByClassName("confirm_holder_stage1")[0].classList.remove("hidden");
holder.getElementsByClassName("confirm_holder_stage2")[0].classList.add("hidden"); holder.getElementsByClassName("confirm_holder_stage2")[0].classList.add("hidden");
} }
@ -363,7 +363,7 @@ function init_button_with_confirm(button)
common.init_all_button_with_confirm = common.init_all_button_with_confirm =
function init_all_button_with_confirm() function init_all_button_with_confirm()
{ {
let buttons = Array.from(document.getElementsByClassName("button_with_confirm")); const buttons = Array.from(document.getElementsByClassName("button_with_confirm"));
for (const button of buttons) for (const button of buttons)
{ {
setTimeout(() => common.init_button_with_confirm(button), 0); setTimeout(() => common.init_button_with_confirm(button), 0);
@ -385,7 +385,7 @@ function init_enable_on_pageload(element)
common.init_all_enable_on_pageload = common.init_all_enable_on_pageload =
function init_all_enable_on_pageload() function init_all_enable_on_pageload()
{ {
let elements = Array.from(document.getElementsByClassName("enable_on_pageload")); const elements = Array.from(document.getElementsByClassName("enable_on_pageload"));
for (const element of elements) for (const element of elements)
{ {
setTimeout(() => common.init_enable_on_pageload(element), 0); setTimeout(() => common.init_enable_on_pageload(element), 0);
@ -412,18 +412,18 @@ function init_all_entry_with_history()
common.init_tabbed_container = common.init_tabbed_container =
function init_tabbed_container(tabbed_container) function init_tabbed_container(tabbed_container)
{ {
let button_container = document.createElement("div"); const button_container = document.createElement("div");
button_container.className = "tab_buttons"; button_container.className = "tab_buttons";
tabbed_container.prepend(button_container); tabbed_container.prepend(button_container);
let tabs = Array.from(tabbed_container.getElementsByClassName("tab")); const tabs = Array.from(tabbed_container.getElementsByClassName("tab"));
for (const tab of tabs) for (const tab of tabs)
{ {
tab.classList.add("hidden"); tab.classList.add("hidden");
let tab_id = tab.dataset.tabId || tab.dataset.tabTitle; const tab_id = tab.dataset.tabId || tab.dataset.tabTitle;
tab.dataset.tabId = tab_id; tab.dataset.tabId = tab_id;
tab.style.borderTopColor = "transparent"; tab.style.borderTopColor = "transparent";
let button = document.createElement("button"); const button = document.createElement("button");
button.className = "tab_button tab_button_inactive"; button.className = "tab_button tab_button_inactive";
button.onclick = common.tabbed_container_switcher; button.onclick = common.tabbed_container_switcher;
button.innerText = tab.dataset.tabTitle; button.innerText = tab.dataset.tabTitle;
@ -438,7 +438,7 @@ function init_tabbed_container(tabbed_container)
common.init_all_tabbed_container = common.init_all_tabbed_container =
function init_all_tabbed_container() function init_all_tabbed_container()
{ {
let tabbed_containers = Array.from(document.getElementsByClassName("tabbed_container")); const tabbed_containers = Array.from(document.getElementsByClassName("tabbed_container"));
for (const tabbed_container of tabbed_containers) for (const tabbed_container of tabbed_containers)
{ {
setTimeout(() => common.init_tabbed_container(tabbed_container), 0); setTimeout(() => common.init_tabbed_container(tabbed_container), 0);
@ -448,13 +448,13 @@ function init_all_tabbed_container()
common.tabbed_container_switcher = common.tabbed_container_switcher =
function tabbed_container_switcher(event) function tabbed_container_switcher(event)
{ {
let tab_button = event.target; const tab_button = event.target;
if (tab_button.classList.contains("tab_button_active")) if (tab_button.classList.contains("tab_button_active"))
{ return; } { return; }
let tab_id = tab_button.dataset.tabId; const tab_id = tab_button.dataset.tabId;
let tab_buttons = tab_button.parentElement.getElementsByClassName("tab_button"); const tab_buttons = tab_button.parentElement.getElementsByClassName("tab_button");
let tabs = tab_button.parentElement.parentElement.getElementsByClassName("tab"); const tabs = tab_button.parentElement.parentElement.getElementsByClassName("tab");
for (const tab_button of tab_buttons) for (const tab_button of tab_buttons)
{ {
if (tab_button.dataset.tabId === tab_id) if (tab_button.dataset.tabId === tab_id)

View file

@ -1,4 +1,4 @@
var editor = {}; const editor = {};
editor.PARAGRAPH_TYPES = new Set(["P", "PRE"]); editor.PARAGRAPH_TYPES = new Set(["P", "PRE"]);
@ -67,13 +67,13 @@ function Editor(elements, on_open, on_save, on_cancel)
{ {
for (let index = 0; index < this.display_elements.length; index += 1) for (let index = 0; index < this.display_elements.length; index += 1)
{ {
let display_element = this.display_elements[index]; const display_element = this.display_elements[index];
let edit_element = this.edit_elements[index]; const edit_element = this.edit_elements[index];
display_element.classList.add("hidden"); display_element.classList.add("hidden");
edit_element.classList.remove("hidden"); edit_element.classList.remove("hidden");
let empty_text = display_element.dataset.editorEmptyText; const empty_text = display_element.dataset.editorEmptyText;
if (empty_text !== undefined && display_element.innerText == empty_text) if (empty_text !== undefined && display_element.innerText == empty_text)
{ {
edit_element.value = ""; edit_element.value = "";
@ -92,8 +92,8 @@ function Editor(elements, on_open, on_save, on_cancel)
{ {
for (let index = 0; index < this.display_elements.length; index += 1) for (let index = 0; index < this.display_elements.length; index += 1)
{ {
let display_element = this.display_elements[index]; const display_element = this.display_elements[index];
let edit_element = this.edit_elements[index]; const edit_element = this.edit_elements[index];
if (display_element.dataset.editorEmptyText !== undefined && edit_element.value == "") if (display_element.dataset.editorEmptyText !== undefined && edit_element.value == "")
{ {
@ -187,7 +187,7 @@ function Editor(elements, on_open, on_save, on_cancel)
return fallback.bind(this); return fallback.bind(this);
} }
let bindable = function() const bindable = function()
{ {
if (this.can_use_element_map) if (this.can_use_element_map)
{ {
@ -201,14 +201,14 @@ function Editor(elements, on_open, on_save, on_cancel)
return bindable.bind(this); return bindable.bind(this);
} }
let placeholders = document.getElementsByClassName("editor_toolbox_placeholder"); const placeholders = document.getElementsByClassName("editor_toolbox_placeholder");
for (const placeholder of placeholders) for (const placeholder of placeholders)
{ {
placeholder.parentElement.removeChild(placeholder); placeholder.parentElement.removeChild(placeholder);
} }
let last_element = this.edit_elements[this.edit_elements.length - 1]; const last_element = this.edit_elements[this.edit_elements.length - 1];
let toolbox = document.createElement("div"); const toolbox = document.createElement("div");
toolbox.classList.add("editor_toolbox"); toolbox.classList.add("editor_toolbox");
last_element.parentElement.insertBefore(toolbox, last_element.nextSibling); last_element.parentElement.insertBefore(toolbox, last_element.nextSibling);

View file

@ -1,4 +1,4 @@
var hotkeys = {}; const hotkeys = {};
hotkeys.HOTKEYS = {}; hotkeys.HOTKEYS = {};
@ -30,14 +30,14 @@ function register_hotkey(hotkey, action, description)
hotkey = hotkey.split(/\s+/g); hotkey = hotkey.split(/\s+/g);
} }
let key = hotkey.pop(); const key = hotkey.pop();
modifiers = hotkey.map(word => word.toLocaleLowerCase()); modifiers = hotkey.map(word => word.toLocaleLowerCase());
let ctrlKey = modifiers.includes("control") || modifiers.includes("ctrl"); const ctrlKey = modifiers.includes("control") || modifiers.includes("ctrl");
let shiftKey = modifiers.includes("shift"); const shiftKey = modifiers.includes("shift");
let altKey = modifiers.includes("alt"); const altKey = modifiers.includes("alt");
let identifier = hotkeys.hotkey_identifier(key, ctrlKey, shiftKey, altKey); const identifier = hotkeys.hotkey_identifier(key, ctrlKey, shiftKey, altKey);
let human = hotkeys.hotkey_human(key, ctrlKey, shiftKey, altKey); const human = hotkeys.hotkey_human(key, ctrlKey, shiftKey, altKey);
hotkeys.HOTKEYS[identifier] = {"action": action, "human": human, "description": description} hotkeys.HOTKEYS[identifier] = {"action": action, "human": human, "description": description}
} }
@ -61,7 +61,7 @@ function show_all_hotkeys()
let lines = []; let lines = [];
for (const identifier in hotkeys.HOTKEYS) for (const identifier in hotkeys.HOTKEYS)
{ {
let line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"]; const line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"];
lines.push(line); lines.push(line);
} }
lines = lines.join("\n"); lines = lines.join("\n");

View file

@ -1,4 +1,4 @@
var photo_clipboard = {}; const photo_clipboard = {};
photo_clipboard.clipboard = new Set(); photo_clipboard.clipboard = new Set();
photo_clipboard.on_load_hooks = []; photo_clipboard.on_load_hooks = [];
@ -17,7 +17,7 @@ photo_clipboard.load_clipboard =
function load_clipboard(event) function load_clipboard(event)
{ {
console.log("Loading photo clipboard from localstorage."); console.log("Loading photo clipboard from localstorage.");
let stored = localStorage.getItem("photo_clipboard"); const stored = localStorage.getItem("photo_clipboard");
if (stored === null) if (stored === null)
{ {
if (photo_clipboard.clipboard.size != 0) if (photo_clipboard.clipboard.size != 0)
@ -42,7 +42,7 @@ photo_clipboard.save_clipboard =
function save_clipboard() function save_clipboard()
{ {
console.log("Saving photo clipboard to localstorage."); console.log("Saving photo clipboard to localstorage.");
let serialized = JSON.stringify(Array.from(photo_clipboard.clipboard)); const serialized = JSON.stringify(Array.from(photo_clipboard.clipboard));
localStorage.setItem("photo_clipboard", serialized); localStorage.setItem("photo_clipboard", serialized);
photo_clipboard.update_pagestate(); photo_clipboard.update_pagestate();
@ -105,8 +105,8 @@ function apply_check_all()
Run through all the photo cards on the page and set their checkbox to the Run through all the photo cards on the page and set their checkbox to the
correct value. correct value.
*/ */
let checkboxes = document.getElementsByClassName("photo_card_selector_checkbox"); const checkboxes = document.getElementsByClassName("photo_card_selector_checkbox");
for (let checkbox of checkboxes) for (const checkbox of checkboxes)
{ {
photo_clipboard.apply_check(checkbox); photo_clipboard.apply_check(checkbox);
} }
@ -141,12 +141,12 @@ function on_photo_select(event)
} }
else if (event.shiftKey && photo_clipboard.previous_photo_select) else if (event.shiftKey && photo_clipboard.previous_photo_select)
{ {
let current_photo_div = checkbox.parentElement; const current_photo_div = checkbox.parentElement;
let previous_photo_div = photo_clipboard.previous_photo_select; const previous_photo_div = photo_clipboard.previous_photo_select;
let photo_divs = Array.from(current_photo_div.parentElement.getElementsByClassName("photo_card")); const photo_divs = Array.from(current_photo_div.parentElement.getElementsByClassName("photo_card"));
let current_index = photo_divs.indexOf(current_photo_div); const current_index = photo_divs.indexOf(current_photo_div);
let previous_index = photo_divs.indexOf(previous_photo_div); const previous_index = photo_divs.indexOf(previous_photo_div);
let slice; let slice;
if (current_index == previous_index) if (current_index == previous_index)
@ -155,12 +155,12 @@ function on_photo_select(event)
} }
else else
{ {
let left = Math.min(previous_index, current_index); const left = Math.min(previous_index, current_index);
let right = Math.max(previous_index, current_index); const right = Math.max(previous_index, current_index);
slice = photo_divs.slice(left, right + 1); slice = photo_divs.slice(left, right + 1);
} }
for (let photo_div of slice) for (const photo_div of slice)
{ {
action(photo_div.dataset.id); action(photo_div.dataset.id);
} }
@ -168,7 +168,7 @@ function on_photo_select(event)
} }
else else
{ {
let photo_div = checkbox.parentElement; const photo_div = checkbox.parentElement;
action(photo_div.dataset.id); action(photo_div.dataset.id);
photo_clipboard.previous_photo_select = photo_div; photo_clipboard.previous_photo_select = photo_div;
} }
@ -178,8 +178,8 @@ function on_photo_select(event)
photo_clipboard.select_all_photos = photo_clipboard.select_all_photos =
function select_all_photos() function select_all_photos()
{ {
let photo_divs = Array.from(document.getElementsByClassName("photo_card")); const photo_divs = Array.from(document.getElementsByClassName("photo_card"));
for (let photo_div of photo_divs) for (const photo_div of photo_divs)
{ {
photo_clipboard.clipboard.add(photo_div.dataset.id); photo_clipboard.clipboard.add(photo_div.dataset.id);
} }
@ -190,8 +190,8 @@ function select_all_photos()
photo_clipboard.unselect_all_photos = photo_clipboard.unselect_all_photos =
function unselect_all_photos() function unselect_all_photos()
{ {
let photo_divs = Array.from(document.getElementsByClassName("photo_card")); const photo_divs = Array.from(document.getElementsByClassName("photo_card"));
for (let photo_div of photo_divs) for (const photo_div of photo_divs)
{ {
photo_clipboard.clipboard.delete(photo_div.dataset.id); photo_clipboard.clipboard.delete(photo_div.dataset.id);
} }
@ -205,14 +205,14 @@ function unselect_all_photos()
photo_clipboard.clipboard_tray_collapse = photo_clipboard.clipboard_tray_collapse =
function clipboard_tray_collapse() function clipboard_tray_collapse()
{ {
let tray_body = document.getElementById("clipboard_tray_body"); const tray_body = document.getElementById("clipboard_tray_body");
tray_body.classList.add("hidden"); tray_body.classList.add("hidden");
} }
photo_clipboard.clipboard_tray_uncollapse = photo_clipboard.clipboard_tray_uncollapse =
function clipboard_tray_uncollapse() function clipboard_tray_uncollapse()
{ {
let tray_body = document.getElementById("clipboard_tray_body"); const tray_body = document.getElementById("clipboard_tray_body");
tray_body.classList.remove("hidden"); tray_body.classList.remove("hidden");
photo_clipboard.update_clipboard_tray(); photo_clipboard.update_clipboard_tray();
} }
@ -223,7 +223,7 @@ function clipboard_tray_collapse_toggle()
/* /*
Show or hide the clipboard. Show or hide the clipboard.
*/ */
let tray_body = document.getElementById("clipboard_tray_body"); const tray_body = document.getElementById("clipboard_tray_body");
if (!tray_body) if (!tray_body)
{ {
return; return;
@ -246,8 +246,8 @@ function ingest_toolbox_items()
The page may provide divs with the class "my_clipboard_tray_toolbox", and 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. we will migrate all the elements into the real clipboard tray toolbox.
*/ */
let toolbox = document.getElementById("clipboard_tray_toolbox"); const toolbox = document.getElementById("clipboard_tray_toolbox");
let moreboxes = document.getElementsByClassName("my_clipboard_tray_toolbox"); const moreboxes = document.getElementsByClassName("my_clipboard_tray_toolbox");
for (const morebox of moreboxes) for (const morebox of moreboxes)
{ {
@ -265,8 +265,8 @@ function on_tray_delete_button(event)
/* /*
Remove the clicked row from the clipboard. Remove the clicked row from the clipboard.
*/ */
let clipboard_line = event.target.parentElement; const clipboard_line = event.target.parentElement;
let photo_id = clipboard_line.dataset.id; const photo_id = clipboard_line.dataset.id;
photo_clipboard.clipboard.delete(photo_id); photo_clipboard.clipboard.delete(photo_id);
photo_clipboard.save_clipboard(); photo_clipboard.save_clipboard();
} }
@ -277,7 +277,7 @@ function update_clipboard_tray()
/* /*
Rebuild the rows if the tray is open. Rebuild the rows if the tray is open.
*/ */
let clipboard_tray = document.getElementById("clipboard_tray"); const clipboard_tray = document.getElementById("clipboard_tray");
if (clipboard_tray === null) if (clipboard_tray === null)
{ {
return; return;
@ -288,24 +288,24 @@ function update_clipboard_tray()
photo_clipboard.clipboard_tray_collapse(); photo_clipboard.clipboard_tray_collapse();
} }
let tray_lines = document.getElementById("clipboard_tray_lines"); const tray_lines = document.getElementById("clipboard_tray_lines");
if (!clipboard_tray.classList.contains("hidden")) if (!clipboard_tray.classList.contains("hidden"))
{ {
common.delete_all_children(tray_lines); common.delete_all_children(tray_lines);
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
photo_ids.sort(); photo_ids.sort();
for (const photo_id of photo_ids) for (const photo_id of photo_ids)
{ {
let clipboard_line = document.createElement("div"); const clipboard_line = document.createElement("div");
clipboard_line.classList.add("clipboard_tray_line"); clipboard_line.classList.add("clipboard_tray_line");
clipboard_line.dataset.id = photo_id; clipboard_line.dataset.id = photo_id;
let clipboard_line_delete_button = document.createElement("button"); const clipboard_line_delete_button = document.createElement("button");
clipboard_line_delete_button.classList.add("remove_tag_button_perm"); clipboard_line_delete_button.classList.add("remove_tag_button_perm");
clipboard_line_delete_button.classList.add("red_button"); clipboard_line_delete_button.classList.add("red_button");
clipboard_line_delete_button.onclick = photo_clipboard.on_tray_delete_button; clipboard_line_delete_button.onclick = photo_clipboard.on_tray_delete_button;
let clipboard_line_link = document.createElement("a"); const clipboard_line_link = document.createElement("a");
clipboard_line_link.target = "_blank"; clipboard_line_link.target = "_blank";
clipboard_line_link.href = "/photo/" + photo_id; clipboard_line_link.href = "/photo/" + photo_id;
clipboard_line_link.innerText = photo_id; clipboard_line_link.innerText = photo_id;
@ -328,7 +328,7 @@ function open_full_clipboard_tab()
photo_clipboard.update_clipboard_count = photo_clipboard.update_clipboard_count =
function update_clipboard_count() function update_clipboard_count()
{ {
let elements = document.getElementsByClassName("clipboard_count"); const elements = document.getElementsByClassName("clipboard_count");
for (const element of elements) for (const element of elements)
{ {
element.innerText = photo_clipboard.clipboard.size; element.innerText = photo_clipboard.clipboard.size;

View file

@ -1,4 +1,4 @@
var spinner = {}; const spinner = {};
/* /*
In general, spinners are used for functions that launch a callback, and the In general, spinners are used for functions that launch a callback, and the

View file

@ -1,4 +1,4 @@
var tag_autocomplete = {}; const tag_autocomplete = {};
tag_autocomplete.tagset = {"tags": [], "synonyms": {}}; tag_autocomplete.tagset = {"tags": [], "synonyms": {}};
@ -19,13 +19,13 @@ function init_datalist()
common.delete_all_children(datalist); common.delete_all_children(datalist);
for (const tag_name of tag_autocomplete.tagset["tags"]) for (const tag_name of tag_autocomplete.tagset["tags"])
{ {
let option = document.createElement("option"); const option = document.createElement("option");
option.value = tag_name; option.value = tag_name;
datalist.appendChild(option); datalist.appendChild(option);
} }
for (const synonym in tag_autocomplete.tagset["synonyms"]) for (const synonym in tag_autocomplete.tagset["synonyms"])
{ {
let option = document.createElement("option"); const option = document.createElement("option");
option.value = tag_autocomplete.tagset["synonyms"][synonym] + "+" + synonym; option.value = tag_autocomplete.tagset["synonyms"][synonym] + "+" + synonym;
datalist.appendChild(option); datalist.appendChild(option);
} }
@ -54,8 +54,8 @@ function tagname_replacements(tagname)
tag_autocomplete.entry_with_tagname_replacements_hook = tag_autocomplete.entry_with_tagname_replacements_hook =
function entry_with_tagname_replacements_hook(event) function entry_with_tagname_replacements_hook(event)
{ {
let cursor_position = event.target.selectionStart; const cursor_position = event.target.selectionStart;
let new_value = tag_autocomplete.tagname_replacements(event.target.value); const new_value = tag_autocomplete.tagname_replacements(event.target.value);
if (new_value != event.target.value) if (new_value != event.target.value)
{ {
event.target.value = new_value; event.target.value = new_value;
@ -114,7 +114,7 @@ tag_autocomplete.update_tagset =
function update_tagset() function update_tagset()
{ {
console.log("Updating known tagset."); console.log("Updating known tagset.");
let url = "/all_tags.json"; const url = "/all_tags.json";
common.get(url, tag_autocomplete.update_tagset_callback); common.get(url, tag_autocomplete.update_tagset_callback);
} }

View file

@ -143,7 +143,7 @@ h2, h3
<script id="album_listing_script" type="text/javascript"> <script id="album_listing_script" type="text/javascript">
ALBUM_ID = undefined; const ALBUM_ID = undefined;
</script> </script>
{% else %} {## Individual album ###################################################################} {% else %} {## Individual album ###################################################################}
@ -308,7 +308,7 @@ ALBUM_ID = undefined;
<script id="album_individual_script" type="text/javascript"> <script id="album_individual_script" type="text/javascript">
var ALBUM_ID = "{{album.id}}"; const ALBUM_ID = "{{album.id}}";
function add_child(child_id) function add_child(child_id)
{ {
@ -321,12 +321,12 @@ function add_child(child_id)
function paste_photo_clipboard() function paste_photo_clipboard()
{ {
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.albums.add_photos(ALBUM_ID, photo_ids, common.refresh); api.albums.add_photos(ALBUM_ID, photo_ids, common.refresh);
} }
function unpaste_photo_clipboard() function unpaste_photo_clipboard()
{ {
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.albums.remove_photos(ALBUM_ID, photo_ids, common.refresh); api.albums.remove_photos(ALBUM_ID, photo_ids, common.refresh);
} }
@ -348,8 +348,8 @@ function on_save(ed, edit_element_map, display_element_map)
ed.save(); ed.save();
let title_display = display_element_map["title"]; const title_display = display_element_map["title"];
let description_display = display_element_map["description"]; const description_display = display_element_map["description"];
document.title = title_display.innerText + " | Albums"; document.title = title_display.innerText + " | Albums";
@ -360,8 +360,8 @@ function on_save(ed, edit_element_map, display_element_map)
} }
edit_element_map["title"].value = edit_element_map["title"].value.trim(); edit_element_map["title"].value = edit_element_map["title"].value.trim();
let title = edit_element_map["title"].value; const title = edit_element_map["title"].value;
let description = edit_element_map["description"].value; const description = edit_element_map["description"].value;
ed.show_spinner(); ed.show_spinner();
api.albums.edit(ALBUM_ID, title, description, callback); api.albums.edit(ALBUM_ID, title, description, callback);
@ -376,9 +376,9 @@ function on_cancel(ed, edit_element_map, display_element_map)
} }
} }
var title_text = document.getElementById("title_text"); const title_text = document.getElementById("title_text");
var description_text = document.getElementById("description_text"); const description_text = document.getElementById("description_text");
var ed = new editor.Editor([title_text, description_text], on_open, on_save, on_cancel); const ed = new editor.Editor([title_text, description_text], on_open, on_save, on_cancel);
</script> </script>
{% endif %} {## Shared ############################################################################} {% endif %} {## Shared ############################################################################}
@ -391,7 +391,7 @@ function create_child(title)
{ {
title = undefined; title = undefined;
} }
let parent_id = ALBUM_ID; const parent_id = ALBUM_ID;
api.albums.create(title, parent_id, api.albums.callback_follow); api.albums.create(title, parent_id, api.albums.callback_follow);
} }
@ -412,7 +412,7 @@ function get_album_card_from_child(element)
function on_album_drag_start(event) function on_album_drag_start(event)
{ {
let album_card = get_album_card_from_child(event.target); const album_card = get_album_card_from_child(event.target);
event.dataTransfer.setData("text/plain", album_card.id); event.dataTransfer.setData("text/plain", album_card.id);
} }
function on_album_drag_end(event) function on_album_drag_end(event)
@ -424,11 +424,10 @@ function on_album_drag_over(event)
} }
function on_album_drag_drop(event) function on_album_drag_drop(event)
{ {
let child_id = event.dataTransfer.getData("text"); const child = document.getElementById(event.dataTransfer.getData("text"));
let child = document.getElementById(child_id); const child_id = child.dataset.id;
child_id = child.dataset.id; const parent = event.currentTarget;
let parent = event.currentTarget; const parent_id = parent.dataset.id;
let parent_id = parent.dataset.id;
event.dataTransfer.clearData(); event.dataTransfer.clearData();
if (child_id == parent_id) if (child_id == parent_id)
@ -436,8 +435,8 @@ function on_album_drag_drop(event)
return; return;
} }
let child_title = child.querySelector('.album_card_title').textContent.trim(); const child_title = child.querySelector('.album_card_title').textContent.trim();
let parent_title = parent.querySelector('.album_card_title').textContent.trim(); const parent_title = parent.querySelector('.album_card_title').textContent.trim();
if (confirm(`Move\n${child_title}\ninto\n${parent_title}?`)) if (confirm(`Move\n${child_title}\ninto\n${parent_title}?`))
{ {
if (ALBUM_ID) if (ALBUM_ID)

View file

@ -99,8 +99,8 @@
<script type="text/javascript"> <script type="text/javascript">
function create_bookmark_form() function create_bookmark_form()
{ {
let url = document.getElementById("new_bookmark_url").value.trim(); const url = document.getElementById("new_bookmark_url").value.trim();
let title = document.getElementById("new_bookmark_title").value.trim(); const title = document.getElementById("new_bookmark_title").value.trim();
if (!url) if (!url)
{ {
return; return;
@ -135,9 +135,9 @@ function on_save(ed, edit_element_map, display_element_map)
return; return;
} }
let bookmark_id = ed.misc_data["bookmark_id"]; const bookmark_id = ed.misc_data["bookmark_id"];
let title = edit_element_map["title"].value; const title = edit_element_map["title"].value;
let url = edit_element_map["url"].value; const url = edit_element_map["url"].value;
ed.show_spinner(); ed.show_spinner();
api.bookmarks.edit(bookmark_id, title, url, callback); api.bookmarks.edit(bookmark_id, title, url, callback);
@ -147,11 +147,11 @@ on_cancel = undefined;
function create_editors() function create_editors()
{ {
let cards = document.getElementsByClassName("bookmark_card"); const cards = document.getElementsByClassName("bookmark_card");
for (const card of cards) for (const card of cards)
{ {
let title_div = card.getElementsByClassName("bookmark_title")[0]; const title_div = card.getElementsByClassName("bookmark_title")[0];
let url_div = card.getElementsByClassName("bookmark_url")[0]; const url_div = card.getElementsByClassName("bookmark_url")[0];
ed = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel); ed = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel);
ed.misc_data["bookmark_id"] = card.dataset.bookmarkId; ed.misc_data["bookmark_id"] = card.dataset.bookmarkId;
} }

View file

@ -139,16 +139,16 @@
<script type="text/javascript"> <script type="text/javascript">
var divs = {}; const divs = {};
var needed = new Set(); const needed = new Set();
var holder = document.getElementById("photo_card_holder"); const holder = document.getElementById("photo_card_holder");
var add_box = document.getElementById("add_tag_textbox"); const add_box = document.getElementById("add_tag_textbox");
var add_button = document.getElementById("add_tag_button"); const add_button = document.getElementById("add_tag_button");
common.bind_box_to_button(add_box, add_button); common.bind_box_to_button(add_box, add_button);
var remove_box = document.getElementById("remove_tag_textbox"); const remove_box = document.getElementById("remove_tag_textbox");
var remove_button = document.getElementById("remove_tag_button"); const remove_button = document.getElementById("remove_tag_button");
common.bind_box_to_button(remove_box, remove_button); common.bind_box_to_button(remove_box, remove_button);
function recalculate_needed() function recalculate_needed()
@ -162,7 +162,7 @@ function recalculate_needed()
This function only calculates which ids are needed. The actual fetching of This function only calculates which ids are needed. The actual fetching of
divs is in `request_more_divs`. divs is in `request_more_divs`.
*/ */
needed = new Set(); needed.clear();
for (const photo_id of photo_clipboard.clipboard) for (const photo_id of photo_clipboard.clipboard)
{ {
if (!(photo_id in divs)) if (!(photo_id in divs))
@ -178,11 +178,12 @@ function refresh_divs()
Add new divs to the page, and remove divs which the user has removed from Add new divs to the page, and remove divs which the user has removed from
their clipboard. their clipboard.
*/ */
// 'in' instead of 'of' is intentional here because divs is a dict.
for (const photo_id in divs) for (const photo_id in divs)
{ {
let photo_div = divs[photo_id]; const photo_div = divs[photo_id];
let should_keep = photo_clipboard.clipboard.has(photo_id); const should_keep = photo_clipboard.clipboard.has(photo_id);
let on_page = holder.contains(photo_div); const on_page = holder.contains(photo_div);
if (on_page && !should_keep) if (on_page && !should_keep)
{ {
holder.removeChild(photo_div) holder.removeChild(photo_div)
@ -204,9 +205,9 @@ function request_more_divs()
{ {
return; return;
} }
let url = "/batch/photos/photo_card"; const url = "/batch/photos/photo_card";
let data = new FormData(); const data = new FormData();
let photo_ids = Array.from(needed).join(","); const photo_ids = Array.from(needed).join(",");
data.append("photo_ids", photo_ids); data.append("photo_ids", photo_ids);
function callback(response) function callback(response)
{ {
@ -242,8 +243,8 @@ photo_clipboard.on_save_hooks.push(my_clipboard_load_save_hook);
function add_remove_tag_callback(response) function add_remove_tag_callback(response)
{ {
let tagname = response.data.tagname; const tagname = response.data.tagname;
let message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
let message_positivity; let message_positivity;
let message_text; let message_text;
@ -254,7 +255,7 @@ function add_remove_tag_callback(response)
} }
else if ("action" in response.data) else if ("action" in response.data)
{ {
let action = response.data.action; const action = response.data.action;
message_positivity = "message_positive"; message_positivity = "message_positive";
if (action == "add") if (action == "add")
{message_text = "Added tag " + tagname;} {message_text = "Added tag " + tagname;}
@ -270,13 +271,13 @@ function add_tag_form()
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
let box = document.getElementById("add_tag_textbox"); const box = document.getElementById("add_tag_textbox");
let tagname = box.value.trim(); const tagname = box.value.trim();
if (! tagname) if (! tagname)
{return} {return}
box.value = ""; box.value = "";
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_add_tag(photo_ids, tagname, add_remove_tag_callback); api.photos.batch_add_tag(photo_ids, tagname, add_remove_tag_callback);
} }
@ -285,13 +286,13 @@ function remove_tag_form()
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
let box = document.getElementById("remove_tag_textbox"); const box = document.getElementById("remove_tag_textbox");
let tagname = box.value.trim(); const tagname = box.value.trim();
if (! tagname) if (! tagname)
{return} {return}
box.value = ""; box.value = "";
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_remove_tag(photo_ids, tagname, add_remove_tag_callback); api.photos.batch_remove_tag(photo_ids, tagname, add_remove_tag_callback);
} }
@ -302,22 +303,22 @@ function download_zip_form()
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.get_download_zip_token(photo_ids, api.photos.callback_download_zip); api.photos.get_download_zip_token(photo_ids, api.photos.callback_download_zip);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
var refresh_metadata_button = document.getElementById("refresh_metadata_button"); const refresh_metadata_button = document.getElementById("refresh_metadata_button");
function refresh_metadata_callback(response) function refresh_metadata_callback(response)
{ {
window[refresh_metadata_button.dataset.spinnerCloser](); window[refresh_metadata_button.dataset.spinnerCloser]();
if ("error_type" in response.data) if ("error_type" in response.data)
{ {
let message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
let message_positivity = "message_negative"; const message_positivity = "message_negative";
let message_text = response.data.error_message; const message_text = response.data.error_message;
common.create_message_bubble(message_area, message_positivity, message_text, 8000); common.create_message_bubble(message_area, message_positivity, message_text, 8000);
} }
else else
@ -333,7 +334,7 @@ function refresh_metadata_form()
return spinner.BAIL; return spinner.BAIL;
} }
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_refresh_metadata(photo_ids, refresh_metadata_callback); api.photos.batch_refresh_metadata(photo_ids, refresh_metadata_callback);
} }
@ -341,7 +342,7 @@ function refresh_metadata_form()
function set_unset_searchhidden_callback(response) function set_unset_searchhidden_callback(response)
{ {
let message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
let message_positivity; let message_positivity;
let message_text; let message_text;
if ("error_type" in response.data) if ("error_type" in response.data)
@ -361,7 +362,7 @@ function set_searchhidden_form()
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_set_searchhidden(photo_ids, set_unset_searchhidden_callback); api.photos.batch_set_searchhidden(photo_ids, set_unset_searchhidden_callback);
} }
function unset_searchhidden_form() function unset_searchhidden_form()
@ -369,7 +370,7 @@ function unset_searchhidden_form()
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
let photo_ids = Array.from(photo_clipboard.clipboard); const photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_unset_searchhidden(photo_ids, set_unset_searchhidden_callback); api.photos.batch_unset_searchhidden(photo_ids, set_unset_searchhidden_callback);
} }
</script> </script>

View file

@ -87,13 +87,13 @@ form h2
<script type="text/javascript"> <script type="text/javascript">
var message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
function login_form(event) function login_form(event)
{ {
event.preventDefault(); event.preventDefault();
let username = document.getElementById("login_input_username").value; const username = document.getElementById("login_input_username").value;
let password = document.getElementById("login_input_password").value; const password = document.getElementById("login_input_password").value;
if (username == "" || password == "") if (username == "" || password == "")
{ {
common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo.");
@ -105,10 +105,10 @@ function login_form(event)
function register_form(event) function register_form(event)
{ {
event.preventDefault(); event.preventDefault();
let username = document.getElementById("register_input_username").value; const username = document.getElementById("register_input_username").value;
let display_name = document.getElementById("register_input_display_name").value; const display_name = document.getElementById("register_input_display_name").value;
let password_1 = document.getElementById("register_input_password_1").value; const password_1 = document.getElementById("register_input_password_1").value;
let password_2 = document.getElementById("register_input_password_2").value; const password_2 = document.getElementById("register_input_password_2").value;
if (username == "" || password_1 == "" || password_2 == "") if (username == "" || password_1 == "" || password_2 == "")
{ {
common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo.");
@ -129,6 +129,5 @@ function login_register_callback(response)
window.location.href = "/"; window.location.href = "/";
} }
} }
</script> </script>
</html> </html>

View file

@ -282,17 +282,17 @@
<script type="text/javascript"> <script type="text/javascript">
var PHOTO_ID = "{{photo.id}}"; const PHOTO_ID = "{{photo.id}}";
var add_tag_box = document.getElementById('add_tag_textbox'); const add_tag_box = document.getElementById('add_tag_textbox');
var add_tag_button = document.getElementById('add_tag_button'); const add_tag_button = document.getElementById('add_tag_button');
common.bind_box_to_button(add_tag_box, add_tag_button, false); common.bind_box_to_button(add_tag_box, add_tag_button, false);
var message_area = document.getElementById('message_area'); const message_area = document.getElementById('message_area');
function add_photo_tag_form() function add_photo_tag_form()
{ {
let tagname = document.getElementById("add_tag_textbox").value; const tagname = document.getElementById("add_tag_textbox").value;
if (tagname == "") if (tagname == "")
{ {
return; return;
@ -308,7 +308,7 @@ function add_photo_tag_callback(response)
return; return;
} }
const this_tags = document.getElementById("this_tags"); const this_tags = document.getElementById("this_tags");
let tag_objects = this_tags.getElementsByClassName("tag_object"); const tag_objects = this_tags.getElementsByClassName("tag_object");
for (const tag_object of tag_objects) for (const tag_object of tag_objects)
{ {
if (tag_object.innerText === response.data.tagname) if (tag_object.innerText === response.data.tagname)
@ -342,12 +342,12 @@ function remove_photo_tag_callback(response)
{ {
return; return;
} }
let tag_objects = document.getElementById("this_tags").getElementsByClassName("tag_object"); const tag_objects = document.getElementById("this_tags").getElementsByClassName("tag_object");
for (const tag_object of tag_objects) for (const tag_object of tag_objects)
{ {
if (tag_object.innerText === response.data.tagname) if (tag_object.innerText === response.data.tagname)
{ {
let li = tag_object.parentElement; const li = tag_object.parentElement;
li.parentElement.removeChild(li); li.parentElement.removeChild(li);
} }
} }
@ -416,8 +416,8 @@ function generate_thumbnail_callback(response)
function generate_thumbnail_for_video_form(event) function generate_thumbnail_for_video_form(event)
{ {
let timestamp = document.querySelector("#right video").currentTime; const timestamp = document.querySelector("#right video").currentTime;
let special = {"timestamp": timestamp}; const special = {"timestamp": timestamp};
api.photos.generate_thumbnail(PHOTO_ID, special, generate_thumbnail_callback) api.photos.generate_thumbnail(PHOTO_ID, special, generate_thumbnail_callback)
} }
@ -428,7 +428,7 @@ function refresh_metadata_form()
function set_searchhidden_form(event) function set_searchhidden_form(event)
{ {
let checkbox = event.target; const checkbox = event.target;
if (checkbox.checked) if (checkbox.checked)
{ {
api.photos.set_searchhidden(PHOTO_ID); api.photos.set_searchhidden(PHOTO_ID);
@ -439,12 +439,12 @@ function set_searchhidden_form(event)
} }
} }
var ZOOM_BG_URL = "url('{{photo|file_link}}')"; const ZOOM_BG_URL = "url('{{photo|file_link}}')";
function enable_hoverzoom(event) function enable_hoverzoom(event)
{ {
//console.log("enable zoom"); //console.log("enable zoom");
let photo_viewer = document.getElementById("photo_viewer"); const photo_viewer = document.getElementById("photo_viewer");
let photo_img = photo_viewer.children[0]; const photo_img = photo_viewer.children[0];
if ( if (
photo_img.naturalWidth < photo_viewer.offsetWidth && photo_img.naturalWidth < photo_viewer.offsetWidth &&
photo_img.naturalHeight < photo_viewer.offsetHeight photo_img.naturalHeight < photo_viewer.offsetHeight
@ -463,8 +463,8 @@ function enable_hoverzoom(event)
function disable_hoverzoom() function disable_hoverzoom()
{ {
//console.log("disable zoom"); //console.log("disable zoom");
let photo_viewer = document.getElementById("photo_viewer"); const photo_viewer = document.getElementById("photo_viewer");
let photo_img = photo_viewer.children[0]; const photo_img = photo_viewer.children[0];
photo_img.style.opacity = "100"; photo_img.style.opacity = "100";
photo_viewer.style.cursor = ""; photo_viewer.style.cursor = "";
@ -474,7 +474,7 @@ function disable_hoverzoom()
} }
function toggle_hoverzoom(event) function toggle_hoverzoom(event)
{ {
let photo_img = document.getElementById("photo_viewer").children[0]; const photo_img = document.getElementById("photo_viewer").children[0];
if (photo_img.style.opacity === "0") if (photo_img.style.opacity === "0")
{ {
disable_hoverzoom(); disable_hoverzoom();
@ -483,7 +483,7 @@ function toggle_hoverzoom(event)
{ {
enable_hoverzoom(event); enable_hoverzoom(event);
} }
let content_body = document.getElementById('content_body'); const content_body = document.getElementById('content_body');
if (getComputedStyle(content_body).getPropertyValue("--narrow") == 0) if (getComputedStyle(content_body).getPropertyValue("--narrow") == 0)
{ {
add_tag_box.focus(); add_tag_box.focus();
@ -492,8 +492,8 @@ function toggle_hoverzoom(event)
function move_hoverzoom(event) function move_hoverzoom(event)
{ {
let photo_viewer = document.getElementById("photo_viewer"); const photo_viewer = document.getElementById("photo_viewer");
let photo_img = photo_viewer.children[0]; const photo_img = photo_viewer.children[0];
let x; let x;
let y; let y;
@ -563,7 +563,7 @@ setTimeout(
*/ */
function() function()
{ {
let content_body = document.getElementById("content_body"); const content_body = document.getElementById("content_body");
if (getComputedStyle(content_body).getPropertyValue("--narrow") == 1) if (getComputedStyle(content_body).getPropertyValue("--narrow") == 1)
{ {
add_tag_box.autofocus = false; add_tag_box.autofocus = false;

View file

@ -369,26 +369,26 @@ These values should match those of the server itself. The purpose of this dict
is to know that we DON'T need to include these parameters in the url if the is to know that we DON'T need to include these parameters in the url if the
selected form values are these. selected form values are these.
*/ */
PARAM_DEFAULTS = { const PARAM_DEFAULTS = {
'limit': 50, 'limit': 50,
'view': 'grid', 'view': 'grid',
} }
function add_searchtag(ul, value, inputted_list, li_class) function add_searchtag(ul, value, inputted_list, li_class)
{ {
console.log("adding " + value); console.log("adding " + value);
let already_have = inputted_list.indexOf(value) !== -1; const already_have = inputted_list.indexOf(value) !== -1;
if (already_have) if (already_have)
{return;} {return;}
inputted_list.push(value); inputted_list.push(value);
let new_li = document.createElement("li"); const new_li = document.createElement("li");
new_li.className = li_class; new_li.className = li_class;
let new_span = document.createElement("span"); const new_span = document.createElement("span");
new_span.className = "tag_object"; new_span.className = "tag_object";
new_span.innerHTML = value; new_span.innerHTML = value;
let new_delbutton = document.createElement("button") const new_delbutton = document.createElement("button")
new_delbutton.classList.add("remove_tag_button"); new_delbutton.classList.add("remove_tag_button");
new_delbutton.classList.add("red_button"); new_delbutton.classList.add("red_button");
new_delbutton.onclick = function(){remove_searchtag(ul, value, inputted_list)}; new_delbutton.onclick = function(){remove_searchtag(ul, value, inputted_list)};
@ -429,15 +429,15 @@ function add_searchtag_from_box(box, inputted_list, li_class)
function remove_searchtag(ul, value, inputted_list) function remove_searchtag(ul, value, inputted_list)
{ {
console.log("removing " + value); console.log("removing " + value);
let lis = ul.children; const lis = ul.children;
//console.log(lis); //console.log(lis);
for (const li of lis) for (const li of lis)
{ {
let tag_object = li.children[0]; const tag_object = li.children[0];
if (! tag_object.classList.contains("tag_object")) if (! tag_object.classList.contains("tag_object"))
{continue} {continue}
let tagname = tag_object.innerHTML; const tagname = tag_object.innerHTML;
if (tagname != value) if (tagname != value)
{continue} {continue}
@ -453,23 +453,23 @@ function remove_searchtag(ul, value, inputted_list)
function add_new_orderby() function add_new_orderby()
{ {
/* Called by the green + button */ /* Called by the green + button */
let ul = document.getElementById("search_builder_orderby_ul"); const ul = document.getElementById("search_builder_orderby_ul");
let lis = ul.children; const lis = ul.children;
if (lis.length >= 9) if (lis.length >= 9)
{ {
/* 9 because there are only 9 sortable properties */ /* 9 because there are only 9 sortable properties */
return; return;
} }
prev_li = lis[lis.length - 2]; prev_li = lis[lis.length - 2];
let new_li = prev_li.cloneNode(true); const new_li = prev_li.cloneNode(true);
ul.insertBefore(new_li, prev_li.nextSibling); ul.insertBefore(new_li, prev_li.nextSibling);
} }
function orderby_remove_hook(button) function orderby_remove_hook(button)
{ {
/* Called by the red button next to orderby dropdowns */ /* Called by the red button next to orderby dropdowns */
let li = button.parentElement; const li = button.parentElement;
let ul = li.parentElement; const ul = li.parentElement;
// 2 because keep 1 row and the adder button // 2 because keep 1 row and the adder button
if (ul.children.length>2) if (ul.children.length>2)
{ {
@ -492,7 +492,7 @@ function orderby_hide_direction_hook(event)
function simplify_tagnames(tags) function simplify_tagnames(tags)
{ {
let new_tags = []; const new_tags = [];
for (let tag of tags) for (let tag of tags)
{ {
tag = tag.split("."); tag = tag.split(".");
@ -518,16 +518,16 @@ function submit_search()
add_searchtag_from_box(input_forbids, inputted_forbids, "search_builder_forbids_inputted"); add_searchtag_from_box(input_forbids, inputted_forbids, "search_builder_forbids_inputted");
let has_tag_params = false; let has_tag_params = false;
let musts = simplify_tagnames(inputted_musts).join(","); const musts = simplify_tagnames(inputted_musts).join(",");
if (musts) {parameters.push("tag_musts=" + musts); has_tag_params = true;} if (musts) {parameters.push("tag_musts=" + musts); has_tag_params = true;}
let mays = simplify_tagnames(inputted_mays).join(","); const mays = simplify_tagnames(inputted_mays).join(",");
if (mays) {parameters.push("tag_mays=" + mays); has_tag_params = true;} if (mays) {parameters.push("tag_mays=" + mays); has_tag_params = true;}
let forbids = simplify_tagnames(inputted_forbids).join(","); const forbids = simplify_tagnames(inputted_forbids).join(",");
if (forbids) {parameters.push("tag_forbids=" + forbids); has_tag_params = true;} if (forbids) {parameters.push("tag_forbids=" + forbids); has_tag_params = true;}
let expression = document.getElementsByName("tag_expression")[0].value; const expression = document.getElementsByName("tag_expression")[0].value;
if (expression) if (expression)
{ {
//expression = expression.replace(new RegExp(" ", 'g'), "-"); //expression = expression.replace(new RegExp(" ", 'g'), "-");
@ -535,11 +535,11 @@ function submit_search()
has_tag_params = true; has_tag_params = true;
} }
let basic_inputs = document.getElementsByClassName("basic_param"); const basic_inputs = document.getElementsByClassName("basic_param");
for (const basic_input of basic_inputs) for (const basic_input of basic_inputs)
{ {
let boxname = basic_input.name; const boxname = basic_input.name;
let box = document.getElementsByName(boxname)[0]; const box = document.getElementsByName(boxname)[0];
let value = box.value; let value = box.value;
value = value.split("&").join("%26"); value = value.split("&").join("%26");
console.log(value); console.log(value);
@ -555,18 +555,18 @@ function submit_search()
parameters.push(boxname + "=" + value); parameters.push(boxname + "=" + value);
} }
let orderby_rows = document.getElementsByClassName("search_builder_orderby_li"); const orderby_rows = document.getElementsByClassName("search_builder_orderby_li");
let orderby_params = []; let orderby_params = [];
for (const orderby_row of orderby_rows) for (const orderby_row of orderby_rows)
{ {
let column = orderby_row.children[0].value; const column = orderby_row.children[0].value;
if (column == "random") if (column == "random")
{ {
orderby_params.push(column); orderby_params.push(column);
} }
else else
{ {
let sorter = orderby_row.children[1].value; const sorter = orderby_row.children[1].value;
orderby_params.push(column + "-" + sorter); orderby_params.push(column + "-" + sorter);
} }
} }
@ -647,18 +647,18 @@ function tag_input_hook_forbids()
} }
tag_autocomplete.init_datalist(); tag_autocomplete.init_datalist();
var input_musts = document.getElementById("search_builder_musts_input"); const input_musts = document.getElementById("search_builder_musts_input");
var ul_musts = input_musts.parentElement.parentElement; const ul_musts = input_musts.parentElement.parentElement;
var input_mays = document.getElementById("search_builder_mays_input"); const input_mays = document.getElementById("search_builder_mays_input");
var ul_mays = input_mays.parentElement.parentElement; const ul_mays = input_mays.parentElement.parentElement;
var input_forbids = document.getElementById("search_builder_forbids_input"); const input_forbids = document.getElementById("search_builder_forbids_input");
var ul_forbids = input_forbids.parentElement.parentElement; const ul_forbids = input_forbids.parentElement.parentElement;
var input_expression = document.getElementById("search_builder_expression_input"); const input_expression = document.getElementById("search_builder_expression_input");
/* Prefix the form with the parameters from last search */ /* Prefix the form with the parameters from last search */
var inputted_musts = []; const inputted_musts = [];
var inputted_mays = []; const inputted_mays = [];
var inputted_forbids = []; const inputted_forbids = [];
{% for tagtype in ["musts", "mays", "forbids"] %} {% for tagtype in ["musts", "mays", "forbids"] %}
{% set key="tag_" + tagtype %} {% set key="tag_" + tagtype %}
{% if search_kwargs[key] %} {% if search_kwargs[key] %}

View file

@ -259,9 +259,9 @@ h2, h3
<script type="text/javascript"> <script type="text/javascript">
let SPECIFIC_TAG = "{{specific_tag.name}}"; let SPECIFIC_TAG = "{{specific_tag.name}}";
var add_tag_textbox = document.getElementById('add_tag_textbox'); const add_tag_textbox = document.getElementById('add_tag_textbox');
var add_tag_button = document.getElementById('add_tag_button'); const add_tag_button = document.getElementById('add_tag_button');
var message_area = document.getElementById('message_area'); const message_area = document.getElementById('message_area');
common.bind_box_to_button(add_tag_textbox, add_tag_button, false); common.bind_box_to_button(add_tag_textbox, add_tag_button, false);
function tag_object_from_li(li) function tag_object_from_li(li)
@ -395,8 +395,8 @@ function on_save(ed, edit_element_map, display_element_map)
ed.hide_spinner(); ed.hide_spinner();
if (response.meta.status == 200) if (response.meta.status == 200)
{ {
let new_name = response.data.name; const new_name = response.data.name;
let new_description = response.data.description; const new_description = response.data.description;
document.title = new_name + " | Tags"; document.title = new_name + " | Tags";
SPECIFIC_TAG = new_name; SPECIFIC_TAG = new_name;
window.history.replaceState(null, null, "/tag/" + new_name); window.history.replaceState(null, null, "/tag/" + new_name);
@ -411,17 +411,17 @@ function on_save(ed, edit_element_map, display_element_map)
} }
} }
let name_display = display_element_map["name"]; const name_display = display_element_map["name"];
let name_editor = edit_element_map["name"]; const name_editor = edit_element_map["name"];
let description_display = display_element_map["description"]; const description_display = display_element_map["description"];
let description_editor = edit_element_map["description"]; const description_editor = edit_element_map["description"];
let tag_name = name_display.innerText; const tag_name = name_display.innerText;
let name = name_editor.value; const new_name = name_editor.value;
let description = description_editor.value; const new_description = description_editor.value;
ed.show_spinner(); ed.show_spinner();
api.tags.edit(tag_name, name, description, callback) api.tags.edit(tag_name, new_name, new_description, callback)
} }
function on_cancel(ed, edit_element_map, display_element_map) function on_cancel(ed, edit_element_map, display_element_map)
@ -433,9 +433,9 @@ function on_cancel(ed, edit_element_map, display_element_map)
} }
} }
var name_text = document.getElementById("name_text"); const name_text = document.getElementById("name_text");
var description_text = document.getElementById("description_text"); const description_text = document.getElementById("description_text");
var ed = new editor.Editor([name_text, description_text], on_open, on_save, on_cancel); const ed = new editor.Editor([name_text, description_text], on_open, on_save, on_cancel);
{% endif %} {% endif %}
</script> </script>
</html> </html>