X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/c987aee47acfcc0df4c1ac2667d9c63133e99d2b..88e389ef1ec5441d7941a15e3d075f011128d272:/IkiWiki/Plugin/toggle.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 284eb8249..610d38e3a 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -39,23 +39,28 @@ function toggle(s) { style.display = "none"; } -function getElementsByClass(class) { +function getElementsByClass(cls, node, tag) { + if (document.getElementsByClass) + return document.getElementsByClass(cls, node, tag); + if (! node) node = document; + if (! tag) tag = '*'; var ret = new Array(); - var pattern = new RegExp("(^|\\s)"+class+"(\\s|$)"); - var els = document.getElementsByTagName('*'); - for (i = 0, j = 0; i < els.length; i++) { + var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)"); + var els = node.getElementsByTagName(tag); + for (i = 0; i < els.length; i++) { if ( pattern.test(els[i].className) ) { - ret[j] = els[i]; - j++; + ret.push(els[i]); } } return ret; } + //--> EOF sub import { #{{{ + hook(type => "getsetup", id => "toggle", call => \&getsetup); hook(type => "preprocess", id => "toggle", call => \&preprocess_toggle); hook(type => "preprocess", id => "toggleable", @@ -63,6 +68,14 @@ sub import { #{{{ hook(type => "format", id => "toggle", call => \&format); } # }}} +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + sub genid ($$) { #{{{ my $page=shift; my $id=shift; @@ -106,7 +119,7 @@ sub preprocess_toggleable (@) { #{{{ sub format (@) { #{{{ my %params=@_; - if ($params{content}=~s!(
)
!$1!g) { + if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; if (! ($params{content}=~s!^!$javascript!m)) { # no tag, probably in preview mode