From 47c1b5d0948319bb66a327741d38ae9cd69d604c Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 5 Jul 2013 22:32:01 +0100 Subject: [PATCH] move query-string-passing to JS rather than embedding in the HTML, so that the HTML can be commonised and cached better --- core/basethemelet.class.php | 4 ++-- ext/index/theme.php | 5 +++-- lib/shimmie.js | 17 +++++++++++++++++ themes/danbooru/index.theme.php | 5 +++-- themes/danbooru/themelet.class.php | 4 ++-- themes/danbooru2/index.theme.php | 5 +++-- themes/danbooru2/themelet.class.php | 4 ++-- themes/futaba/themelet.class.php | 4 ++-- themes/lite/themelet.class.php | 4 ++-- 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 21720222..9666d2d8 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -37,7 +37,7 @@ class BaseThemelet { * Generic thumbnail code; returns HTML rather than adding * a block since thumbs tend to go inside blocks... */ - public function build_thumb_html(Image $image, $query=null) { + public function build_thumb_html(Image $image) { global $config; $i_id = (int) $image->id; $h_view_link = make_link('post/view/'.$i_id, $query); @@ -55,7 +55,7 @@ class BaseThemelet { $tsize = get_thumbnail_size($image->width, $image->height); } - return "". + return "". "$h_tip". "". "\n"; diff --git a/ext/index/theme.php b/ext/index/theme.php index 8ef8bff5..0b7f5ee5 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -95,9 +95,10 @@ and of course start organising your images :-) } protected function build_table($images, $query) { - $table = "
"; + $h_query = html_escape($query); + $table = "
"; foreach($images as $image) { - $table .= $this->build_thumb_html($image, $query); + $table .= $this->build_thumb_html($image); } $table .= "
"; return $table; diff --git a/lib/shimmie.js b/lib/shimmie.js index e7b5cc7f..e52a7700 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -86,6 +86,23 @@ $(document).ready(function() { a = document.getElementById("nextlink"); a.href = a.href + '?' + query; } + + /* + * If an image list has a data-query attribute, append + * that query string to all thumb links inside the list. + * This allows us to cache the same thumb for all query + * strings, adding the query in the browser. + */ + $(".shm-image-list").each(function(idx, elm) { + var query = $(this).data("query"); + if(query) { + if(window.console) {console.log("Found list with query: "+query);} + $(this).find(".shm-thumb-link").each(function(idx2, elm2) { + if(window.console) {console.log("Appending to url: "+$(this).attr("href"));} + $(this).attr("href", $(this).attr("href") + query); + }); + } + }); }); diff --git a/themes/danbooru/index.theme.php b/themes/danbooru/index.theme.php index 155e4a24..b27aa028 100644 --- a/themes/danbooru/index.theme.php +++ b/themes/danbooru/index.theme.php @@ -49,9 +49,10 @@ class CustomIndexTheme extends IndexTheme { } protected function build_table($images, $query) { - $table = "
"; + $h_query = html_escape($query); + $table = "
"; foreach($images as $image) { - $table .= "\t" . $this->build_thumb_html($image, $query) . "\n"; + $table .= "\t" . $this->build_thumb_html($image) . "\n"; } $table .= "
"; return $table; diff --git a/themes/danbooru/themelet.class.php b/themes/danbooru/themelet.class.php index 6ef57ee8..c74dece9 100644 --- a/themes/danbooru/themelet.class.php +++ b/themes/danbooru/themelet.class.php @@ -1,6 +1,6 @@ id}", $query); $h_thumb_link = $image->get_thumb_link(); @@ -16,7 +16,7 @@ class Themelet extends BaseThemelet { $tsize = get_thumbnail_size($image->width, $image->height); } - return "$h_tip$h_tip"; } diff --git a/themes/danbooru2/index.theme.php b/themes/danbooru2/index.theme.php index 429bd0fe..4d0ca68f 100644 --- a/themes/danbooru2/index.theme.php +++ b/themes/danbooru2/index.theme.php @@ -49,9 +49,10 @@ class CustomIndexTheme extends IndexTheme { } protected function build_table($images, $query) { - $table = "
"; + $h_query = html_escape($query); + $table = "
"; foreach($images as $image) { - $table .= "\t" . $this->build_thumb_html($image, $query) . "\n"; + $table .= "\t" . $this->build_thumb_html($image) . "\n"; } $table .= "
"; return $table; diff --git a/themes/danbooru2/themelet.class.php b/themes/danbooru2/themelet.class.php index 6ef57ee8..c74dece9 100644 --- a/themes/danbooru2/themelet.class.php +++ b/themes/danbooru2/themelet.class.php @@ -1,6 +1,6 @@ id}", $query); $h_thumb_link = $image->get_thumb_link(); @@ -16,7 +16,7 @@ class Themelet extends BaseThemelet { $tsize = get_thumbnail_size($image->width, $image->height); } - return "$h_tip$h_tip"; } diff --git a/themes/futaba/themelet.class.php b/themes/futaba/themelet.class.php index cfff9d50..35034e4e 100644 --- a/themes/futaba/themelet.class.php +++ b/themes/futaba/themelet.class.php @@ -4,7 +4,7 @@ class Themelet extends BaseThemelet { * Generic thumbnail code; returns HTML rather than adding * a block since thumbs tend to go inside blocks... */ - public function build_thumb_html(Image $image, $query=null) { + public function build_thumb_html(Image $image) { global $config; $h_view_link = make_link("post/view/{$image->id}", $query); $h_thumb_link = $image->get_thumb_link(); @@ -20,7 +20,7 @@ class Themelet extends BaseThemelet { $tsize = get_thumbnail_size($image->width, $image->height); } - return "$h_tip$h_tip"; } diff --git a/themes/lite/themelet.class.php b/themes/lite/themelet.class.php index c61c9e4a..41a5ba5f 100644 --- a/themes/lite/themelet.class.php +++ b/themes/lite/themelet.class.php @@ -4,7 +4,7 @@ class Themelet extends BaseThemelet { * Generic thumbnail code; returns HTML rather than adding * a block since thumbs tend to go inside blocks... */ - public function build_thumb_html(Image $image, $query=null) { + public function build_thumb_html(Image $image) { global $config; $i_id = (int) $image->id; $h_view_link = make_link('post/view/'.$i_id, $query); @@ -22,7 +22,7 @@ class Themelet extends BaseThemelet { } return '
\n";