From 6eef2c55c264bcb6f3a7fcc05ff9ae2b816314cb Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 3 May 2014 21:52:05 +0200 Subject: [PATCH] In fullscreen mode, avoid an extra HTTP round-trip to re-validate the preloaded image. --- files/pr0n-fullscreen.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/files/pr0n-fullscreen.js b/files/pr0n-fullscreen.js index 278ad08..661cea7 100644 --- a/files/pr0n-fullscreen.js +++ b/files/pr0n-fullscreen.js @@ -113,7 +113,6 @@ function replace_image_element(url, element_id, parent_node) { var img = document.getElementById(element_id); if (img !== null) { - img.src = "data:"; img.parentNode.removeChild(img); } @@ -129,11 +128,34 @@ function replace_image_element(url, element_id, parent_node) return img; } +function rename_element(old_name, new_name) +{ + // Remove any element that's in the way. + var elem = document.getElementById(new_name); + if (elem !== null) { + elem.parentNode.removeChild(elem); + } + + elem = document.getElementById(old_name); + if (elem !== null) { + elem.id = new_name; + } + return elem; +} + function display_image(width, height, evt, filename, element_id) { var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/nobox/" + filename; var main = document.getElementById("iehack"); - var img = replace_image_element(url, element_id, main); + var preload = document.getElementById("preload"); + var img; + // See if we have a preload going on that we can reuse. + if (element_id == "image" && preload !== null && preload.src == url) { + rename_element("preload_box", "image_box"); + img = rename_element("preload", "image"); + } else { + img = replace_image_element(url, element_id, main); + } img.style.position = "absolute"; img.style.left = "0px"; img.style.top = "0px"; @@ -181,13 +203,11 @@ function prepare_preload(img, num) // cancel any pending preload var preload = document.getElementById("preload"); if (preload !== null) { - preload.src = "data:"; preload.parentNode.removeChild(preload); } var preload_box = document.getElementById("preload_box"); if (preload_box !== null) { - preload_box.src = "data:"; preload_box.parentNode.removeChild(preload_box); } -- 2.39.2