afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-06-28 09:49 am

[dw-free] Add custom colors to S2 layouts

[commit: http://hg.dwscoalition.org/dw-free/rev/c8ba1a1ed789]

http://bugs.dwscoalition.org/show_bug.cgi?id=1282

Custom reading list colors for core2. Implemented in Negatives, Tabula Rasa.

Patch by [personal profile] liv.

Files modified:
  • bin/upgrading/s2layers/core2.s2
  • bin/upgrading/s2layers/core2base/layout.s2
  • bin/upgrading/s2layers/negatives/layout.s2
--------------------------------------------------------------------------------
diff -r 8330cd5dc234 -r c8ba1a1ed789 bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Sun Jun 28 06:58:32 2009 +0000
+++ b/bin/upgrading/s2layers/core2.s2	Sun Jun 28 09:44:31 2009 +0000
@@ -1085,8 +1085,8 @@ property bool use_journalstyle_entry_pag
 property bool use_journalstyle_entry_page  { des = "Show entry pages in my journal style rather than the app style"; }
 set use_journalstyle_entry_page = true;
 
-# this may be changed to default to true later; however, none of of the styles use custom colours, so it's not of much help.
-property bool use_custom_friend_colors  { des = "Use my custom friend colors"; }
+# Defaults to false, but layouts can set it to true to switch on custom colors for different posters on reading list.
+property bool use_custom_friend_colors  { des = "Use my custom reading list colors"; }
 set use_custom_friend_colors = false;
 
 
@@ -1645,6 +1645,31 @@ set color_module_link_visited = "";
 set color_module_link_visited = "";
 set color_module_title = "";
 set color_module_border = "";
+
+# Initialize custom colors, these properties can be selected or overwritten by layout layers, but should not normally be exposed in the wizard.
+
+property string custom_foreground_element {
+    des = "Part of entry that will display foreground color, if you have custom colors enabled";
+    values = "subject|Entry title|userpic_border|Icon border|postername|Posted by|entry|Entry text|metadata|Mood/music/location|bottom_links|Comment links|custom|Custom template";
+    noui = 1;
+    }
+property string custom_background_element {
+    des = "Part of entry that will display background color, if you have custom colors enabled";
+    values = "subject|Entry header background|userpic_background|Icon background|entry_border|Entry border|metadata_background|Mood/music/location section|footer_border|Entry footer|custom|Custom template";
+    noui = 1;
+    }
+property string custom_colors_template {
+    des = "Your own CSS to use for custom color";
+    doc = "Enter a CSS statement with the class or id of CSS elements you want to use for foreground and background, and any CSS instructions.
+           Use %%foreground%% for the custom foreground color, and %%background%% for the custom background color
+           Each CSS rule should begin with %%new%%";
+    example = "%%new%% div.special {border: 1px dotted %%background%%; font-size: 120%; color: %%foreground%%}";
+    noui = 1;
+    }
+
+set custom_foreground_element = "";
+set custom_background_element = "";
+set custom_colors_template = "";
 
 ##===============================
 ## Custom CSS
@@ -2699,6 +2724,64 @@ function Page::print_stylesheets()
         end_css();
         println """</style>""";
     }
+}
+
+function FriendsPage::print_stylesheets() {
+#This creates entry-specific CSS to allow custom colors on reading page. Rather than override this, layouts should change custom_foreground_element, custom_background_element (and custom_colors_template for advanced options) instead
+    $super->print_stylesheets();
+
+    if ($*use_custom_friend_colors) {
+        println """<style type="text/css">""";
+        start_css();
+
+        foreach var Entry e ($this.entries) {
+            var Color bg;
+            var Color fg;
+
+            $bg = $.friends{$e.journal.username}.bgcolor;
+            $fg = $.friends{$e.journal.username}.fgcolor;
+
+            var string{} custom_foreground_location;
+            var string{} custom_background_location;
+
+            $custom_foreground_location = {
+                "subject" => "h3.entry-title a {color:",
+                "userpic_border" => "div.userpic a img {border: solid; border-color:",
+                "postername" => "span.entry-poster a {color:",
+                "entry" => "div.entry-content {color:",
+                "metadata" => ".metadata {color:",
+                "bottom_links" => ".footer a {color:"
+                };
+
+            $custom_background_location = {
+                "subject" => "h3.entry-title {background-color:",
+                "userpic_background" => "div.userpic a img {padding: 2px; background-color:",
+                "entry_border" => "div.entry-content {border: solid; border-color:",
+                "metadata_background" => ".metadata {background-color:",
+                "footer_border" => "div.footer {border: solid; border-color:"
+                };
+
+            var string custom_foreground_css = "";
+            var string custom_background_css = "";
+            $custom_foreground_css = """.journal-$e.journal.username $custom_foreground_location{$*custom_foreground_element} $fg; } \n""";
+            $custom_background_css = """.journal-$e.journal.username $custom_background_location{$*custom_background_element} $bg; } \n\n""";
+
+            var string custom_colors_css;
+            if ($*custom_colors_template != ""){
+            var string foreground = $fg;
+            var string background = $bg;
+            $custom_colors_css = $*custom_colors_template->replace("%%foreground%%", $foreground);
+            $custom_colors_css = $custom_colors_css->replace("%%background%%", $background);
+            $custom_colors_css = $custom_colors_css->replace("%%new%%", ".journal-$e.journal.username");
+            $custom_colors_css = $custom_colors_css + "\n\n";
+            }
+            else {$custom_colors_css = $custom_foreground_css + $custom_background_css;}
+            print $custom_colors_css;
+            }
+
+        end_css();
+        println """</style>""";
+        }
 }
 
 function generate_background_css (
@@ -4661,5 +4744,3 @@ function MessagePage::print_links() {
     }
     println """</div>""";
 }
-
-
diff -r 8330cd5dc234 -r c8ba1a1ed789 bin/upgrading/s2layers/core2base/layout.s2
--- a/bin/upgrading/s2layers/core2base/layout.s2	Sun Jun 28 06:58:32 2009 +0000
+++ b/bin/upgrading/s2layers/core2base/layout.s2	Sun Jun 28 09:44:31 2009 +0000
@@ -14,11 +14,15 @@ propgroup presentation {
     property use tags_page_type;
     property use sidebar_width;
     property use sidebar_width_doubled;
+    property use use_custom_friend_colors;
 }
 
 set sidebar_width = "15em";
 set sidebar_width_doubled = "30em";
 set layout_type = "one-column";
+set use_custom_friend_colors = false;
+set custom_foreground_element = "userpic_border";
+set custom_background_element = "userpic_background";
 
 ##===============================
 ## Journal style - colors
diff -r 8330cd5dc234 -r c8ba1a1ed789 bin/upgrading/s2layers/negatives/layout.s2
--- a/bin/upgrading/s2layers/negatives/layout.s2	Sun Jun 28 06:58:32 2009 +0000
+++ b/bin/upgrading/s2layers/negatives/layout.s2	Sun Jun 28 09:44:31 2009 +0000
@@ -15,9 +15,11 @@ propgroup presentation {
     property use use_journalstyle_entry_page;
     property use layout_type;
     property use tags_page_type;
+    property use use_custom_friend_colors;
 }
 
 set layout_type = "two-columns-right";
+set custom_colors_template = "%%new%% div.footer, %%new%% div.footer ul, %%new%% div.footer ul a {background-color: %%background%%} %%new%% {border: 5px solid %%background%%;} %%new%% div.footer a, %%new%% div.footer {color: %%foreground%%;}";
 
 ##===============================
 ## Journal style - colors
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org