Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion misc/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default [
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "script",
sourceType: "module",
globals: {
...globals.browser,
"$": "readonly",
Expand Down
9 changes: 4 additions & 5 deletions public/static/functions/analysis.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* global toggleChecks */

"use strict";
import { toggleChecks } from "global.js";

document.addEventListener('DOMContentLoaded', () => {
// allow error log rows to be bulk-toggled for faster clearing
document.getElementById('clear-all').addEventListener('click', () => {
document.addEventListener('DOMContentLoaded', function () {
$('#clear-all').click(function () {
toggleChecks('error-log', false, '.clear-row');
});
});
});
65 changes: 19 additions & 46 deletions public/static/functions/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* If masterElem is false, toggle each box, otherwise use masterElem's status on all boxes
* If elemSelector is false, act on all checkboxes in formElem
*/
function toggleChecks(formElem, masterElem, elemSelector) {
export function toggleChecks(formElem, masterElem, elemSelector) {
elemSelector = elemSelector || 'input:checkbox';
if (masterElem) {
$('#' + formElem + ' ' + elemSelector).prop('checked', masterElem.checked);
Expand Down Expand Up @@ -63,15 +63,15 @@ var lightbox = {
}
};

function resize(id) {
export function resize(id) {
var textarea = document.getElementById(id);
if (textarea.scrollHeight > textarea.clientHeight) {
textarea.style.height = Math.min(1000, textarea.scrollHeight + textarea.style.fontSize) + 'px';
}
}

//ZIP downloader stuff
function add_selection() {
export function add_selection() {
var selected = $('#formats').raw().options[$('#formats').raw().selectedIndex];
if (selected.disabled === false) {
var listitem = document.createElement("li");
Expand All @@ -85,12 +85,12 @@ function add_selection() {
}
}

function remove_selection(index) {
export function remove_selection(index) {
$('#list' + index).remove();
$('#opt' + index).raw().disabled = '';
}

function toggle_display(selector) {
export function toggle_display(selector) {
let element = document.getElementById(selector);
if (!element) {
element = document.getElementsByClassName(selector);
Expand Down Expand Up @@ -207,7 +207,7 @@ var ajax = {
function Bookmark(type, id, newName) {
var bmLinks = $('#bookmarklink_' + type + '_' + id + ', .bookmarklink_' + type + '_' + id);
var oldName = bmLinks.html();
ajax.get("bookmarks.php?action=add&type=" + type + "&auth=" + document.body.dataset.auth + "&id=" + id, function() {
ajax.get("bookmarks.php?action=add&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
bmLinks.parent('.remove_bookmark, .add_bookmark').toggleClass('add_bookmark remove_bookmark');
bmLinks.html(newName).attr('title', 'Remove bookmark').removeAttr('onclick').off('click').click(function() {
Unbookmark(type, id, oldName);
Expand All @@ -218,15 +218,15 @@ function Bookmark(type, id, newName) {

function Unbookmark(type, id, newName) {
if (window.location.pathname.indexOf('bookmarks.php') != -1) {
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + document.body.dataset.auth + "&id=" + id, function() {
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
$('#group_' + id).remove();
$('.groupid_' + id).remove();
$('.bookmark_' + id).remove();
});
} else {
var bmLinks = $('#bookmarklink_' + type + '_' + id + ', .bookmarklink_' + type + '_' + id);
var oldName = bmLinks.html();
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + document.body.dataset.auth + "&id=" + id, function() {
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
bmLinks.parent('.remove_bookmark, .add_bookmark').toggleClass('add_bookmark remove_bookmark');
bmLinks.html(newName).attr('title', 'Add bookmark').removeAttr('onclick').off('click').click(function() {
Bookmark(type, id, oldName);
Expand All @@ -238,17 +238,19 @@ function Unbookmark(type, id, newName) {

/* Site wide functions */

function byte_format(size, precision) {
export function byte_format(size, precision) {
if (precision === undefined) {
precision = 2;
}
let steps = 0;
var steps = 0;
while (steps < 8 && size >= 1024) {
steps++;
size = size / 1024;
}
let ext;
var ext;
switch (steps) {
case 0: ext = ' B';
break;
case 1: ext = ' KiB';
break;
case 2: ext = ' MiB';
Expand All @@ -265,8 +267,6 @@ function byte_format(size, precision) {
break;
case 8: ext = ' YiB';
break;
default: ext = ' B';
break;
}
return (size.toFixed(precision) + ext);
}
Expand All @@ -287,7 +287,7 @@ function ratio_css(ratio) {
return 'r50';
}

function ratio(dividend, divisor, color) {
export function ratio(dividend, divisor, color) {
if (!color) {
color = true;
}
Expand All @@ -308,14 +308,14 @@ function ratio(dividend, divisor, color) {
return rat;
}

function save_message(message) {
export function save_message(message) {
var messageDiv = document.createElement("div");
messageDiv.className = "save_message";
messageDiv.innerHTML = message;
$("#content").raw().insertBefore(messageDiv,$("#content").raw().firstChild);
}

function error_message(message) {
export function error_message(message) {
var messageDiv = document.createElement("div");
messageDiv.className = "error_message";
messageDiv.innerHTML = message;
Expand Down Expand Up @@ -348,7 +348,7 @@ function array_search(needle, haystack, strict) {
return false;
}

var util = function (selector, context) {
export var util = function (selector, context) {
return new util.fn.init(selector, context);
};

Expand All @@ -372,33 +372,6 @@ function gazURL() {
return response;
}

function showWarningMessage(content, button_cb=null) {
let el = document.querySelector('.warning-message');
if (!el) {
el = document.createElement('div');
el.classList.add('warning-message');

const button = document.createElement('button');
button.classList.add('warning-message-confirm');
button.type = 'button';
button.innerText = 'Ok';
button.addEventListener('click', () => {
if (button_cb) {
button_cb();
}
el.remove();
});

el.appendChild(button);
document.body.append(el);
}
el.prepend(content);
}

function clearWarningMessage() {
document.querySelector('.warning-message')?.remove();
}

$.fn.extend({
results: function () {
return this.length;
Expand Down Expand Up @@ -548,7 +521,7 @@ $.fn.extend({
}
});

document.addEventListener('DOMContentLoaded', () => {
document.addEventListener('DOMContentLoaded', function() {
// autocomplete
var url = new gazURL();
var ARTIST_AUTOCOMPLETE_URL = 'artist.php?action=autocomplete';
Expand Down Expand Up @@ -623,4 +596,4 @@ document.addEventListener('DOMContentLoaded', () => {

$('#userssearch').focus(function () { if (this.value == 'Users') { this.value = ''; }});
$('#userssearch').blur(function () { if (this.value == '') { this.value = 'Users'; }});
});
});