This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/view/script.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

function joinUrlSegments(base, query) {
let separatorChar = "?";
if(base.includes("?")) {
separatorChar = "&";
}
return base + separatorChar + query;
}
function clearViewMode() {
document.querySelectorAll('.image_info').forEach((element) => {
element.classList.remove('infomode-view');
});
}
2023-12-30 18:07:59 +00:00
function updateAttr(selector, attr, value) {
document.querySelectorAll(selector).forEach(function(e) {
let current = e.getAttribute(attr);
let newval = joinUrlSegments(current, query);
e.setAttribute(attr, newval);
});
}
2020-03-02 17:12:43 +00:00
document.addEventListener('DOMContentLoaded', () => {
// find elements with class image_info and set them to view mode
// (by default, with no js, they are in edit mode - so that no-js
// users can still edit them)
document.querySelectorAll('.image_info').forEach((element) => {
element.classList.add('infomode-view');
});
2023-12-30 13:47:23 +00:00
2018-11-05 22:59:53 +00:00
if(document.location.hash.length > 3) {
var query = document.location.hash.substring(1);
2023-12-30 13:47:23 +00:00
updateAttr("LINK#prevlink", "href", query);
updateAttr("LINK#nextlink", "href", query);
updateAttr("A#prevlink", "href", query);
updateAttr("A#nextlink", "href", query);
updateAttr("span#image_delete_form form", "action", query);
2018-11-05 22:59:53 +00:00
}
});