diff --git a/mirva/__init__.py b/mirva/__init__.py index 652152a..9d936bd 100644 --- a/mirva/__init__.py +++ b/mirva/__init__.py @@ -1,4 +1,4 @@ -__version__ = "20230928.1" +__version__ = "20230929.0" def get_version(): diff --git a/mirva/mirva.py b/mirva/mirva.py index ed197d4..28c78b1 100755 --- a/mirva/mirva.py +++ b/mirva/mirva.py @@ -280,33 +280,32 @@ Released : 20110306 def get_post(self, image, title, content): image = urllib.parse.quote(image) if self.video_match.match(image): - return """ -
- -
+ insert = """ -
-
{title}
-
 
-
{content}
-
""".format( - image=image, title=title, content=content - ) - - return """ + """ + else: + insert = """ + + """ + return ( + """
- + """ + + insert + + """
-
{title}
+
+
+
{title}
+
 
{content}
-
""".format( - image=image, title=title, content=content, med_dir=self.medium_dir - ) + """ + ).format(image=image, title=title, content=content, med_dir=self.medium_dir) def is_created_with_mirva(self): with open("index.html", "rt") as fp: @@ -338,6 +337,7 @@ Released : 20110306 "arrow_down.png", "mirva.ico", "mirva.js", + "share.svg", ): if os.path.exists(os.path.join(self.resource_dir, f)): continue diff --git a/mirva/resources/mirva.css b/mirva/resources/mirva.css index b556e52..87f9151 100644 --- a/mirva/resources/mirva.css +++ b/mirva/resources/mirva.css @@ -196,16 +196,26 @@ a:hover {} font-weight: bold; } -.post .meta .post_title { +.post .meta .post_title, +.post_share { display: inline; } -.post_title { +.post_share { cursor: pointer; } -.post_title:hover { - color: var(--links); +.post_share { + vertical-align: top; + margin-right: 0.5em; +} + +.post_share A IMG { + filter: brightness(75%); +} + +.post_share A IMG:hover { + filter: invert(47%) sepia(97%) saturate(1043%) hue-rotate(359deg) brightness(101%) contrast(105%); } .post .meta .posted {} diff --git a/mirva/resources/mirva.js b/mirva/resources/mirva.js index f27dc5f..4268f3a 100644 --- a/mirva/resources/mirva.js +++ b/mirva/resources/mirva.js @@ -3,6 +3,7 @@ let currentScrolled = -1; let scrollTimer = null; let scrollEventTimer = null; let defaultScroll = "smooth"; +let loadTime = new Date(); function r(f) { /in/.test(document.readyState) ? setTimeout('r(' + f + ')', 9) : f() @@ -18,7 +19,7 @@ function create_nav() { let navis = document.getElementsByClassName("navigation"); for (let i = 0; i < navis.length; i++) { if (i == navis.length - 1) { - navis[i].appendChild(create_button("up", navis[0], 0)); + navis[i].appendChild(create_button("up", document.body, 0)); continue; } if (navis[i - 1]) { @@ -30,11 +31,21 @@ function create_nav() { navis[i].appendChild(create_button("down", navis[i + 1], i + 1)); } } - let titles = document.getElementsByClassName("post_title"); - for (let i = 0; i < navis.length; i++) { - titles[i].onclick = function() { + let shares = document.getElementsByClassName("post_share"); + for (let i = 0; i < shares.length; i++) { + let name = shares[i].parentElement.parentElement.id.substring(5); + shares[i].onclick = function(event) { scroll_to(this.parentElement.parentElement); + event.preventDefault() } + let button = document.createElement('img'); + button.src = ".mirva/share.svg"; + let link = document.createElement('a'); + let url = window.location.href.split('?')[0] + `?i=${name}` + link.href = url; + link.title = "Link to this image: " + url; + link.appendChild(button); + shares[i].appendChild(link); } } @@ -43,6 +54,7 @@ function create_button(direction, to, next) { container.classList.add("float_" + direction); let button = document.createElement('img'); button.src = ".mirva/arrow_" + direction + ".png"; + button.title = to == document.body ? "Top of page" : `Move ${direction}`; button.classList.add("navigation_button"); button.onclick = function() { scroll_to(to.parentElement); @@ -61,7 +73,6 @@ function is_visible(el, type) { } } - function get_position() { let intro = document.getElementsByClassName("intro"); for (let i = 0; i < intro.length; i++) { @@ -116,6 +127,16 @@ function get_position() { } } +function find_by_name(name) { + let posts = document.getElementsByClassName("image_wrapper"); + for (let i = 0; i < posts.length; i++) { + if (posts[i].parentElement.id.substring(5) == name) { + return i + } + } + return null +} + function scroll_to(element) { /* Scroll smooth, if no frequent keypress */ if (scrollTimer) { @@ -148,17 +169,24 @@ function get_url_arg() { } function scroll_by_url() { + // Find the image, and scroll to it. With Lazy loading it seems to + // escape sometimes.. let name = get_url_arg(); if (name) { let element = document.getElementById(`post_${name}`); + let index = find_by_name(name); if (element) { // Just to be sure.. setTimeout(function() { + // Try for 10 seconds. + if (new Date() - loadTime > 10000) { + return + } scroll_to(element); - }, 1250); - setTimeout(function() { - scroll_to(element); - }, 10); + if (get_position().current != index) { + scroll_by_url(); + } + }, 310); } } } @@ -192,7 +220,6 @@ function keyboard_entry(ev) { }); return } - current = Math.max(0, current); - current = Math.min(posts.length - 1, current); + current = Math.min(posts.length - 1, Math.max(0, current)); scroll_to(posts[current].parentElement) -} \ No newline at end of file +} diff --git a/mirva/resources/share.svg b/mirva/resources/share.svg new file mode 100644 index 0000000..d87c095 --- /dev/null +++ b/mirva/resources/share.svg @@ -0,0 +1 @@ +