From c2f382aba86aaebb9806ff1b43c1af69992e9a10 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 11 Jul 2022 15:01:02 +0300 Subject: support dark mode for images with alpha channel --- skin/admin.skin.php | 8 ++++---- skin/main.skin.php | 33 +++++++++++++++++++++++++++++++-- skin/markdown.skin.php | 6 +++--- 3 files changed, 38 insertions(+), 9 deletions(-) (limited to 'skin') diff --git a/skin/admin.skin.php b/skin/admin.skin.php index f03d7ce..5619dd0 100644 --- a/skin/admin.skin.php +++ b/skin/admin.skin.php @@ -26,9 +26,9 @@ $html = << HTML; -$js = << true, 'edit' => $is_edit]); -$js = << {$ctx->if_admin($ctx->pageAdminLinks, $page_url, $short_name)}
{$unsafe_html}
HTML; + +return [$html, markdownThemeChangeListener()]; } function pageAdminLinks($ctx, $url, $short_name) { @@ -139,7 +141,7 @@ HTML; // --------- function post($ctx, $id, $title, $unsafe_html, $date, $visible, $url, $tags, $email, $urlencoded_reply_subject) { -return <<

{$title}

@@ -158,6 +160,8 @@ return <<langRaw('blog_comments_text', $email, $urlencoded_reply_subject)}
HTML; + +return [$html, markdownThemeChangeListener()]; } function postAdminLinks($ctx, $url, $id) { @@ -171,7 +175,32 @@ function postTag($ctx, $url, $name) { return <<#{$name} HTML; +} +function markdownThemeChangeListener() { +return << div'); + if (!div) { + console.warn('could not found a>div on this node:', node); + continue; + } + var style = div.getAttribute('style'); + if (isDark) { + style = style.replace(/(a[\d]+x[\d]+)\.jpg/, '$1_dark.jpg'); + } else { + style = style.replace(/(a[\d]+x[\d]+)_dark\.jpg/, '$1.jpg'); + } + div.setAttribute('style', style); + } +}); +JS; } diff --git a/skin/markdown.skin.php b/skin/markdown.skin.php index 02d3a0f..58801f5 100644 --- a/skin/markdown.skin.php +++ b/skin/markdown.skin.php @@ -14,14 +14,14 @@ HTML; function image($ctx, // options - $align, $nolabel, $w, $padding_top, + $align, $nolabel, $w, $padding_top, $may_have_alpha, // image data $direct_url, $url, $note) { return << -
+
-
+
{$ctx->if_true( $note != '' && !$nolabel, -- cgit v1.2.3