]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/toggle.pm
export javascript, and support default-open toggles
[ikiwiki.git] / IkiWiki / Plugin / toggle.pm
index df5a2a7373290026a11910b97b94a291f24eed5c..54c9a0d9a29223e98aecfc6e49f707c7263adfae 100644 (file)
@@ -9,7 +9,7 @@ use IkiWiki 2.00;
 # of css to hide toggleables, to avoid any flashing on page load. The css
 # is only emitted after the javascript tests that it's going to be able to
 # show the toggleables.
-my $javascript=<<'EOF';
+our $javascript=<<'EOF';
 <script type="text/javascript">
 <!--
 if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
@@ -21,7 +21,8 @@ function inittoggle() {
        var as = getElementsByClass('toggle');
        for (var i = 0; i < as.length; i++) {
                var id = as[i].href.match(/#(\w.+)/)[1];
-               document.getElementById(id).style.display="none";
+               if (document.getElementById(id).className == "toggleable")
+                       document.getElementById(id).style.display="none";
                as[i].onclick = function() {
                        toggle(this);
                        return false;
@@ -112,7 +113,10 @@ sub format (@) { #{{{
 
        if ($params{content}=~s!(<div class="toggleable" id="[^"]+">)</div>!$1!g) {
                $params{content}=~s/<div class="toggleableend">//g;
-               $params{content}=~s!^<\/body>!$javascript</body>!m;
+               if (! ($params{content}=~s!^<\/body>!$javascript</body>!m)) {
+                       # no </body> tag, probably in preview mode
+                       $params{content}.=$javascript;
+               }
        }
        return $params{content};
 } # }}}