dynamic-comments.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2005-2013 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. AddModuleDescription('dynamic-comments.pl', 'Dynamic Comments Extension');
  17. our ($q, $CollectingJournal, $CommentsPrefix, @MyInitVariables, $HtmlHeaders);
  18. push(@MyInitVariables, \&DynamicCommentsAddScript);
  19. sub DynamicCommentsAddScript {
  20. $HtmlHeaders .= qq{
  21. <script type="text/Javascript">
  22. function togglecomments (id) {
  23. var elem = document.getElementById(id);
  24. if (elem.className=="commentshown") {
  25. elem.className="commenthidden";
  26. }
  27. else {
  28. elem.className="commentshown";
  29. }
  30. }
  31. </script>
  32. } unless $HtmlHeaders =~ /commenthidden/; # mod_perl?
  33. }
  34. my $num = 0;
  35. *DynamicCommentsOldGetPageLink = \&GetPageLink;
  36. *GetPageLink = \&DynamicCommentsNewGetPageLink;
  37. sub DynamicCommentsNewGetPageLink {
  38. my ($id, @rest) = @_;
  39. if ($CollectingJournal and $id =~ /^$CommentsPrefix/) {
  40. my $title = $id;
  41. $title =~ s/_/ /g;
  42. my $page = PageHtml($id);
  43. if ($page) {
  44. my $anchor = "id" . $num++;
  45. return qq{<a href="javascript:togglecomments('$anchor')">$title</a>}
  46. . '</p>' # close p before opening div
  47. . $q->div({-class=>'commenthidden', -id=>$anchor},
  48. $page,
  49. $q->p(DynamicCommentsOldGetPageLink($id, T('Add Comment'))))
  50. . '<p>'; # open an empty p that will be closed in PrintAllPages
  51. } else {
  52. return DynamicCommentsOldGetPageLink($id, T('Add Comment'));
  53. }
  54. } else {
  55. return DynamicCommentsOldGetPageLink($id, @rest);
  56. }
  57. }