Browse code

first cut of the new, shiny tor website as wml.

Andrew Lewman authored on09/07/2010 03:55:22
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,91 @@
1
+#! /usr/bin/wml
2
+<: use strict; :>
3
+<: use warnings; :>
4
+#use "perl-globals.wmi"
5
+#use "links.wmi"
6
+#use "versions.wmi"
7
+#use "sidenav.wmi"
8
+<div class="img-shadow">
9
+  <div id="sidenav">
10
+    <:
11
+      # recursively search menu structure to see if it contains a given page
12
+      sub containsSub($$);
13
+      sub containsSub($$) {
14
+          my ($elements, $page) = @_;
15
+          for my $ele (@{$elements}) {
16
+              if (containsSub($ele->{'subelements'},$page)){
17
+                  return 1;
18
+              } elsif ($page eq $ele->{'url'}) {
19
+                  return 1;
20
+              }
21
+
22
+          }
23
+          return 0;
24
+      } 
25
+
26
+      # generate navigation menu
27
+      sub printNavMenu($$$);
28
+      sub printNavMenu($$$) {
29
+          my ($navmenu, $page, $lang) = @_;
30
+          print '<ul>'."\n";
31
+          for my $navmenu (@{$navmenu}) {
32
+              # this menu entry is the current (active) page
33
+              if ($navmenu->{'url'} eq $page) {
34
+      
35
+                  # the current page has nested menu elements
36
+                  if ($navmenu->{'subelements'}) { # menu has dropdown
37
+                      printf '<li class="dropdown active"><a class="active" href="%s">%s</a></li>'."\n",
38
+                             pageToURL($navmenu->{'url'}, $lang), $navmenu->{'txt'}; 
39
+      
40
+                      print '<li>'."\n";
41
+                      printNavMenu($navmenu->{'subelements'},$page,$lang); 
42
+                      print '</li>'."\n";
43
+
44
+                  # the current (active) page does not have sub elements
45
+                  } else {
46
+                      printf '<li class="active"><a class="active" href="%s">%s</a></li>'."\n",
47
+                             pageToURL($navmenu->{'url'}, $lang), $navmenu->{'txt'}; 
48
+                  }
49
+      
50
+              # a subelement of this menu item is the current (active) page
51
+              } elsif (containsSub($navmenu->{'subelements'}, $page)) {
52
+                  printf '<li class="dropdown"><a class="active" href="%s">%s</a></li>'."\n",
53
+                         pageToURL($navmenu->{'url'}, $lang), $navmenu->{'txt'};
54
+
55
+                  print '<li>'."\n"; #encapsulate subelements
56
+                  # recurse to generate the expanded menu
57
+                  printNavMenu($navmenu->{'subelements'},$page,$lang); 
58
+                  print '</li>'."\n"; #encapsulate subelements
59
+      
60
+              # the menu entry is not active and does not enclose the active page
61
+              } else {
62
+
63
+                  # if there are subelements, set collapsed style
64
+                  if ($navmenu->{'subelements'}) {
65
+                      printf '<li class="dropdown"><a href="%s">%s</a></li>'."\n",
66
+                             pageToURL($navmenu->{'url'}, $lang), $navmenu->{'txt'};
67
+                  # regular menu entry
68
+                  } else {
69
+                      printf '<li><a href="%s">%s</a></li>'."\n",
70
+                             pageToURL($navmenu->{'url'}, $lang), $navmenu->{'txt'};
71
+                  }
72
+              }
73
+          }
74
+          print '</ul>'."\n";
75
+      }
76
+
77
+      my $lang = "$(LANG)";
78
+
79
+      use Cwd;
80
+      use Cwd 'abs_path';
81
+      use File::Spec;
82
+      
83
+      # get document path from site root
84
+      my $path = File::Spec->abs2rel(getcwd(),abs_path("$(DOCROOT)"));
85
+      my $page = $WML_SRC_BASENAME; 
86
+      printNavMenu($sidenav, $path.'/'.$page, $lang);
87
+    :>
88
+  </div>
89
+  <!-- END SIDENAV -->
90
+</div>
91
+<!-- END IMG-SHADOW -->