Merge remote-tracking branch 'anarcat/inline_diffs'
authorJoey Hess <joey@kitenet.net>
Thu, 19 Jul 2012 17:46:45 +0000 (13:46 -0400)
committerJoey Hess <joey@kitenet.net>
Thu, 19 Jul 2012 17:46:45 +0000 (13:46 -0400)
IkiWiki/Plugin/recentchangesdiff.pm
templates/change.tmpl

index 41882279331f8b1a2171bb98197602197ba64190..eb358be67bef0e8a87146846857d5bc24cfdc396 100644 (file)
@@ -9,10 +9,12 @@ use HTML::Entities;
 my $maxlines=200;
 
 sub import {
+       add_underlay("javascript");
        hook(type => "getsetup", id => "recentchangesdiff",
                call => \&getsetup);
        hook(type => "pagetemplate", id => "recentchangesdiff",
                call => \&pagetemplate);
+       hook(type => "format", id => "recentchangesdiff.pm", call => \&format);
 }
 
 sub getsetup () {
@@ -55,4 +57,24 @@ sub pagetemplate (@) {
        }
 }
 
+sub format (@) {
+        my %params=@_;
+
+       if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
+               # no <body> tag, probably in preview mode
+               $params{content}=include_javascript(undef).$params{content};
+       }
+       return $params{content};
+}
+
+# taken verbatim from toggle.pm
+sub include_javascript ($) {
+       my $from=shift;
+       
+       return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
+               '" type="text/javascript" charset="utf-8"></script>'."\n".
+               '<script src="'.urlto("ikiwiki/toggle.js", $from).
+               '" type="text/javascript" charset="utf-8"></script>';
+}
+
 1
index d7ec9087534af331eb53ee1c4f9ab6f786a76e6f..1751a39b5209dcbfc95e954cce3a7cdf68b397cf 100644 (file)
@@ -9,6 +9,9 @@
 <div id="change-<TMPL_VAR REV>" class="metadata">
 <span class="desc"><br />Changed pages:</span>
 <span class="pagelinks">
+<TMPL_IF DIFF>
+<a href="#diff-<TMPL_VAR REV>" class="toggle" title="revert" rel="nofollow">[[diff|wikiicons/diff.png]]</a>
+</TMPL_IF>
 <TMPL_LOOP PAGES>
 <TMPL_IF DIFFURL><a href="<TMPL_VAR DIFFURL>" title="diff" rel="nofollow">[[diff|wikiicons/diff.png]]</a><TMPL_VAR LINK>
 <TMPL_ELSE><TMPL_VAR LINK></TMPL_IF>
 </TMPL_IF>
 </TMPL_LOOP>
 </div>
+<TMPL_UNLESS DIFFURL>
 <TMPL_IF DIFF>
-<div class="diff">
+<div class="toggleable" id="diff-<TMPL_VAR REV>">
 <pre>
 <TMPL_VAR DIFF>
 </pre>
 </div>
 </TMPL_IF>
+</TMPL_UNLESS>
 <!-- <TMPL_VAR REV> -->