From 3e72171889e80c78c20c1e72e66ac253ce7af443 Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:34:48 -0300 Subject: [PATCH 1/2] download original filename without javascript. --- templates/post/fileinfo.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/post/fileinfo.html b/templates/post/fileinfo.html index 80ddd2a6..ec490129 100644 --- a/templates/post/fileinfo.html +++ b/templates/post/fileinfo.html @@ -22,9 +22,9 @@ {% if config.show_filename and file.filename %} , {% if file.filename|length > config.max_filename_display %} - {{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }} + {{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }} {% else %} - {{ file.filename|e|bidi_cleanup }} + {{ file.filename|e|bidi_cleanup }} {% endif %} {% endif %} ) From d4b4cf5825ff120605f1450a5fb5cc69d6d9f56f Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:35:16 -0300 Subject: [PATCH 2/2] script to expand original filename if truncated --- js/expand-filename.js | 53 +++++++++++++++++++++++++++++++++++++++++++ js/expand-too-long.js | 39 ------------------------------- 2 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 js/expand-filename.js delete mode 100644 js/expand-too-long.js diff --git a/js/expand-filename.js b/js/expand-filename.js new file mode 100644 index 00000000..2f3ac0fd --- /dev/null +++ b/js/expand-filename.js @@ -0,0 +1,53 @@ +/* + * expand-filename.js + * https://github.com/vichan-devel/vichan/blob/master/js/expand-filename.js + * + * Released under the MIT license + * Copyright (c) 2024 Perdedora + * + * Usage: + * $config['additional_javascript'][] = 'js/expand-filename.js'; + * + */ + +function doFilename(element) { + const filenames = element.querySelectorAll('[data-truncate="true"]'); + filenames.forEach(filename => { + filename.addEventListener('mouseover', event => addHover(event.target)); + filename.addEventListener('mouseout', event => removeHover(event.target)); + }); +} + +function addHover(element) { + element.dataset.truncatedFilename = element.textContent; + element.textContent = element.download; +} + +function removeHover(element) { + element.textContent = element.dataset.truncatedFilename; + delete element.dataset.truncatedFilename; +} + +document.addEventListener('DOMContentLoaded', () => { + doFilename(document); + + // Create a MutationObserver to watch for new elements + const observer = new MutationObserver(mutationsList => { + mutationsList.forEach(mutation => { + if (mutation.type === 'childList') { + mutation.addedNodes.forEach(addedNode => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + // Apply `doFilename` to newly added elements + doFilename(addedNode); + } + }); + } + }); + }); + + // Start observing the document body for changes + observer.observe(document.body, { + childList: true, + subtree: true + }); +}); diff --git a/js/expand-too-long.js b/js/expand-too-long.js deleted file mode 100644 index bbadb5f1..00000000 --- a/js/expand-too-long.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * expand-too-long.js - * https://github.com/vichan-devel/vichan/blob/master/js/expand-too-long.js - * - * Released under the MIT license - * Copyright (c) 2013-2014 Marcin Ɓabanowski - * - * Usage: - * $config['additional_javascript'][] = 'js/jquery.min.js'; - * $config['additional_javascript'][] = 'js/expand-too-long.js'; - * - */ - -$(function() { - var do_expand = function() { - $(this).find('a').click(function(e) { - e.preventDefault(); - - var url = $(this).attr('href'); - var body = $(this).parents('.body'); - - $.ajax({ - url: url, - context: document.body, - success: function(data) { - var content = $(data).find('#'+url.split('#')[1]).parent().parent().find(".body").first().html(); - - body.html(content); - } - }); - }); - }; - - $('.toolong').each(do_expand); - - $(document).on("new_post", function(e, post) { - $(post).find('.toolong').each(do_expand) - }); -});