fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-01-26 06:16 am

[dw-free] Having the classes applied to the link instead of the surrounding list item in navlinks ca

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

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

Let styles choose whether to apply a CSS class to the li of a module list
item (useful for, say, navlinks). No styles currently use it.

Patch by [personal profile] fu.

Files modified:
  • bin/upgrading/s2layers/core2.s2
--------------------------------------------------------------------------------
diff -r 0a1d6b8603a0 -r c3fd821250d8 bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Tue Jan 25 18:10:41 2011 +0800
+++ b/bin/upgrading/s2layers/core2.s2	Wed Jan 26 14:16:24 2011 +0800
@@ -3851,11 +3851,25 @@ function close_module() {
     close_module(false);
 }
 
-function print_module_list(string[] list) {
+function print_module_list(string[] list)
+"Takes a straight list of strings, prints them out as a list for a module"
+{
     if (size $list) {
         println """<ul class="module-list">""";
         foreach var string s ($list) {
             print safe """<li class="module-list-item">$s</li>\n""";
+        }
+        println """</ul>""";
+    }
+}
+
+function print_module_list(string{}[] list)
+"Takes a list of hashes in the form of [ { class => list_of_classes, item => list_item_contents }], prints them out as a list for a module"
+{
+    if (size $list) {
+        println """<ul class="module-list">""";
+        foreach var string{} s ($list) {
+            print safe """<li class="module-list-item $s{"class"}">$s{"item"}</li>\n""";
         }
         println """</ul>""";
     }
@@ -3899,17 +3913,39 @@ function print_module_userprofile() {
     close_module(); 
 }
 
+function print_module_navlinks( bool apply_class_to_link ) {
+    var Page p = get_page();
+    open_module("navlinks", "", "");
+
+    if ( $apply_class_to_link ) {
+        var string[] links = [];
+        foreach var string k ($p.views_order) {
+            var string css = """ class="$k" """;
+            if ($p.view == $k) { $css = """ class="current $k" """; }
+            $links[size $links] = """<a href="$p.view_url{$k}"$css>"""+lang_viewname($k)+"""</a>""";
+
+        }
+        print_module_list($links);
+    } else {
+        var string{}[] links = [];
+
+        foreach var string k ($p.views_order) {
+            var string class = $k;
+            if ($p.view == $k) { $class = "current $k"; }
+            $links[size $links] = { "class" => $class, "item" => """<a href="$p.view_url{$k}">"""+lang_viewname($k)+"""</a>""" };
+        }
+        print_module_list($links);
+    }
+
+    close_module();
+
+}
+
 function print_module_navlinks() {
-    var Page p = get_page();
-    open_module("navlinks", "", "");
-    var string[] links = [];
-    foreach var string k ($p.views_order) {
-        var string css = """ class="$k" """;
-        if ($p.view == $k) { $css = """ class="current $k" """; }
-        $links[size $links] = """<a href="$p.view_url{$k}"$css>"""+lang_viewname($k)+"""</a>""";
-    }
-    print_module_list($links);
-    close_module();
+    # prints as   <li><a class="current view...">
+    # styles may override and change to print_module_navlinks( false )
+    # to print as <li class="current view...">
+    print_module_navlinks( true );
 }
 
 function print_module_time() {
--------------------------------------------------------------------------------
ninetydegrees: Art: self-portrait (Default)

[personal profile] ninetydegrees 2011-01-26 03:41 pm (UTC)(link)
Hmm. I think that means another patch for Funky. Nice change, thanks.