Replace loop uses of var with let/const.

This commit is contained in:
voussoir 2020-09-03 15:33:37 -07:00
parent 8af340e442
commit 05b39c21fd
10 changed files with 46 additions and 52 deletions

View file

@ -164,7 +164,7 @@ function init_atag_merge_params()
*/
page_params = new URLSearchParams(window.location.search);
let as = Array.from(document.getElementsByClassName("merge_params"));
for (let a of as)
for (const a of as)
{
let a_params = new URLSearchParams(a.search);
let new_params = new URLSearchParams();
@ -206,7 +206,7 @@ function init_button_with_confirm()
data-holder-class: CSS class for the new span that holds the menu.
*/
let buttons = Array.from(document.getElementsByClassName("button_with_confirm"));
for (let button of buttons)
for (const button of buttons)
{
button.classList.remove("button_with_confirm");
@ -314,7 +314,7 @@ function init_enable_on_pageload()
class "enable_on_pageload".
*/
let elements = Array.from(document.getElementsByClassName("enable_on_pageload"));
for (let element of elements)
for (const element of elements)
{
element.disabled = false;
element.classList.remove("enable_on_pageload");
@ -334,7 +334,7 @@ function init_tabbed_container()
let tab_id = tab_button.dataset.tabId;
let tab_buttons = tab_button.parentElement.getElementsByClassName("tab_button");
let tabs = tab_button.parentElement.parentElement.getElementsByClassName("tab");
for (let tab_button of tab_buttons)
for (const tab_button of tab_buttons)
{
if (tab_button.dataset.tabId === tab_id)
{
@ -347,7 +347,7 @@ function init_tabbed_container()
tab_button.classList.add("tab_button_inactive");
}
}
for (let tab of tabs)
for (const tab of tabs)
{
if (tab.dataset.tabId === tab_id)
{ tab.classList.remove("hidden"); }
@ -357,13 +357,13 @@ function init_tabbed_container()
}
let tabbed_containers = Array.from(document.getElementsByClassName("tabbed_container"));
for (let tabbed_container of tabbed_containers)
for (const tabbed_container of tabbed_containers)
{
let button_container = document.createElement("div");
button_container.className = "tab_buttons";
tabbed_container.prepend(button_container);
let tabs = Array.from(tabbed_container.getElementsByClassName("tab"));
for (let tab of tabs)
for (const tab of tabs)
{
tab.classList.add("hidden");
let tab_id = tab.dataset.tabId || tab.dataset.tabTitle;

View file

@ -41,7 +41,7 @@ function Editor(elements, on_open, on_save, on_cancel)
this.close = function()
{
for (var index = 0; index < this.display_elements.length; index += 1)
for (let index = 0; index < this.display_elements.length; index += 1)
{
this.display_elements[index].classList.remove("hidden");
this.edit_elements[index].classList.add("hidden");
@ -65,7 +65,7 @@ function Editor(elements, on_open, on_save, on_cancel)
this.open = function()
{
for (var 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];
let edit_element = this.edit_elements[index];
@ -90,7 +90,7 @@ function Editor(elements, on_open, on_save, on_cancel)
this.save = function()
{
for (var 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];
let edit_element = this.edit_elements[index];
@ -130,9 +130,8 @@ function Editor(elements, on_open, on_save, on_cancel)
this.misc_data = {};
for (var index = 0; index < elements.length; index += 1)
for (const display_element of elements)
{
let display_element = elements[index];
let edit_element;
if (editor.PARAGRAPH_TYPES.has(display_element.tagName))
{
@ -203,9 +202,9 @@ function Editor(elements, on_open, on_save, on_cancel)
}
let placeholders = document.getElementsByClassName("editor_toolbox_placeholder");
for (var index = 0; index < placeholders.length; index += 1)
for (const placeholder of placeholders)
{
placeholders[index].parentElement.removeChild(placeholders[index]);
placeholder.parentElement.removeChild(placeholder);
}
let last_element = this.edit_elements[this.edit_elements.length - 1];
@ -252,9 +251,8 @@ function Editor(elements, on_open, on_save, on_cancel)
this.spinner = new spinner.Spinner(spinner_element);
toolbox.appendChild(spinner_element);
for (var index = 0; index < this.edit_elements.length; index += 1)
for (const edit_element of this.edit_elements)
{
let edit_element = this.edit_elements[index];
if (edit_element.tagName == "TEXTAREA")
{
common.bind_box_to_button(edit_element, this.save_button, true);

View file

@ -59,7 +59,7 @@ function show_all_hotkeys()
{
// Display an Alert with a list of all the hotkeys.
let lines = [];
for (var identifier in hotkeys.HOTKEYS)
for (const identifier in hotkeys.HOTKEYS)
{
let line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"];
lines.push(line);

View file

@ -30,9 +30,9 @@ function load_clipboard(event)
photo_clipboard.clipboard = new Set(JSON.parse(stored));
}
for (var index = 0; index < photo_clipboard.on_load_hooks.length; index += 1)
for (const on_load_hook of photo_clipboard.on_load_hooks)
{
photo_clipboard.on_load_hooks[index]();
on_load_hook();
}
return photo_clipboard.clipboard;
@ -46,9 +46,9 @@ function save_clipboard()
localStorage.setItem("photo_clipboard", serialized);
photo_clipboard.update_pagestate();
for (var index = 0; index < photo_clipboard.on_save_hooks.length; index += 1)
for (const on_save_hook of photo_clipboard.on_save_hooks)
{
photo_clipboard.on_save_hooks[index]();
on_save_hook();
}
}
@ -212,14 +212,14 @@ function ingest_toolbox_items()
*/
let toolbox = document.getElementById("clipboard_tray_toolbox");
let moreboxes = document.getElementsByClassName("my_clipboard_tray_toolbox");
for (var i = 0; i < moreboxes.length; i += 1)
for (const morebox of moreboxes)
{
let box = moreboxes[i];
while (box.firstElementChild)
while (morebox.firstElementChild)
{
toolbox.appendChild(box.firstElementChild);
toolbox.appendChild(morebox.firstElementChild);
}
box.parentElement.removeChild(box);
morebox.parentElement.removeChild(morebox);
}
}
@ -258,11 +258,11 @@ function update_clipboard_tray()
common.delete_all_children(tray_lines);
let photo_ids = Array.from(photo_clipboard.clipboard);
photo_ids.sort();
for (var i = 0; i < photo_ids.length; i += 1)
for (const photo_id of photo_ids)
{
let clipboard_line = document.createElement("div");
clipboard_line.classList.add("clipboard_tray_line");
clipboard_line.dataset.id = photo_ids[i];
clipboard_line.dataset.id = photo_id;
let clipboard_line_delete_button = document.createElement("button");
clipboard_line_delete_button.classList.add("remove_tag_button_perm");
@ -271,8 +271,8 @@ function update_clipboard_tray()
let clipboard_line_link = document.createElement("a");
clipboard_line_link.target = "_blank";
clipboard_line_link.href = "/photo/" + photo_ids[i];
clipboard_line_link.innerText = photo_ids[i];
clipboard_line_link.href = "/photo/" + photo_id;
clipboard_line_link.innerText = photo_id;
clipboard_line.appendChild(clipboard_line_delete_button);
clipboard_line.appendChild(clipboard_line_link);
@ -293,9 +293,9 @@ photo_clipboard.update_clipboard_count =
function update_clipboard_count()
{
let elements = document.getElementsByClassName("clipboard_count");
for (var index = 0; index < elements.length; index += 1)
for (const element of elements)
{
elements[index].innerText = photo_clipboard.clipboard.size;
element.innerText = photo_clipboard.clipboard.size;
}
}

View file

@ -54,7 +54,7 @@ function close_grouped_spinners(group_id)
if (group_id && !(spinner.spinner_group_closing[group_id]))
{
spinner.spinner_group_closing[group_id] = true;
for (let button of spinner.button_spinner_groups[group_id])
for (const button of spinner.button_spinner_groups[group_id])
{
window[button.dataset.spinnerCloser]();
}
@ -65,7 +65,7 @@ function close_grouped_spinners(group_id)
spinner.open_grouped_spinners =
function open_grouped_spinners(group_id)
{
for (let button of spinner.button_spinner_groups[group_id])
for (const button of spinner.button_spinner_groups[group_id])
{
window[button.dataset.spinnerOpener]();
}

View file

@ -17,13 +17,13 @@ function init_datalist()
}
common.delete_all_children(datalist);
for (var index = 0; index < tag_autocomplete.tagset["tags"].length; index += 1)
for (const tag_name of tag_autocomplete.tagset["tags"])
{
let option = document.createElement("option");
option.value = tag_autocomplete.tagset["tags"][index];
option.value = tag_name;
datalist.appendChild(option);
}
for (var synonym in tag_autocomplete.tagset["synonyms"])
for (const synonym in tag_autocomplete.tagset["synonyms"])
{
let option = document.createElement("option");
option.value = tag_autocomplete.tagset["synonyms"][synonym] + "+" + synonym;

View file

@ -148,9 +148,8 @@ on_cancel = undefined;
function create_editors()
{
let cards = document.getElementsByClassName("bookmark_card");
for (var index = 0; index < cards.length; index += 1)
for (const card of cards)
{
let card = cards[index];
let title_div = card.getElementsByClassName("bookmark_title")[0];
let url_div = card.getElementsByClassName("bookmark_url")[0];
ed = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel);

View file

@ -165,7 +165,7 @@ function recalculate_needed()
divs is in `request_more_divs`.
*/
needed = new Set();
for (let photo_id of photo_clipboard.clipboard)
for (const photo_id of photo_clipboard.clipboard)
{
if (!(photo_id in divs))
{
@ -180,7 +180,7 @@ function refresh_divs()
Add new divs to the page, and remove divs which the user has removed from
their clipboard.
*/
for (let photo_id of divs)
for (const photo_id in divs)
{
let photo_div = divs[photo_id];
let should_keep = photo_clipboard.clipboard.has(photo_id);

View file

@ -433,9 +433,8 @@ function remove_searchtag(ul, value, inputted_list)
console.log("removing " + value);
let lis = ul.children;
//console.log(lis);
for (var index = 0; index < lis.length; index += 1)
for (const li of lis)
{
let li = lis[index];
let tag_object = li.children[0];
if (! tag_object.classList.contains("tag_object"))
{continue}
@ -496,9 +495,8 @@ function orderby_hide_direction_hook(event)
function simplify_tagnames(tags)
{
let new_tags = [];
for (var index = 0; index < tags.length; index += 1)
for (const tag of tags)
{
let tag = tags[index];
tag = tag.split(".");
tag = tag[tag.length - 1];
new_tags.push(tag);
@ -540,9 +538,9 @@ function submit_search()
}
let basic_inputs = document.getElementsByClassName("basic_param");
for (var index = 0; index < basic_inputs.length; index += 1)
for (const basic_input of basic_inputs)
{
let boxname = basic_inputs[index].name;
let boxname = basic_input.name;
let box = document.getElementsByName(boxname)[0];
let value = box.value;
value = value.split("&").join("%26");
@ -561,17 +559,16 @@ function submit_search()
orderby_rows = document.getElementsByClassName("search_builder_orderby_li");
orderby_params = [];
for (var index = 0; index < orderby_rows.length; index += 1)
for (const orderby_row of orderby_rows)
{
let row = orderby_rows[index];
let column = row.children[0].value;
let column = orderby_row.children[0].value;
if (column == "random")
{
orderby_params.push(column);
}
else
{
let sorter = row.children[1].value;
let sorter = orderby_row.children[1].value;
orderby_params.push(column + "-" + sorter);
}
}

View file

@ -253,7 +253,7 @@ function tag_action_callback(response)
{
datas = [datas];
}
for (var index = 0; index < datas.length; index += 1)
for (const data of datas)
{
let tagname = data.tagname;
let message_positivity;