From: anarcat Date: Wed, 15 Jul 2020 16:30:30 +0000 (-0400) Subject: seems like i screwed up javascript loading X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/1fa28f44b77a68d766e26be27d1ec3c060f3cfd9 seems like i screwed up javascript loading --- diff --git a/doc/bugs/javascript_resources_placed_after_html_tag.mdwn b/doc/bugs/javascript_resources_placed_after_html_tag.mdwn new file mode 100644 index 000000000..23f832fdb --- /dev/null +++ b/doc/bugs/javascript_resources_placed_after_html_tag.mdwn @@ -0,0 +1,67 @@ +[[!template id=gitbranch branch=anarcat/js-newline author="[[anarcat]]"]] + +I am not sure why -- it may be [[my fault|todo/fix_javascript_load_ordering]] -- but it seems like plugins loads there Javascript resources *after* the `` and `` tags are closed. Here's an example from [my sandbox](https://anarc.at/sandbox/): + + + + + + + +Here, `toggle.js` appaars after the `` tag! Interestingly, this is not specific to that one plugin: the same thing happens, in reverse, in my [recent changes page](https://anarc.at/recentchanges/): + + + + + + + +I am not sure what determines the order in the end. + +I'm not sure what's going on, but it seems like the second time a `include_javascript`-like pattern is used, it fails to detect the `` tag and appends the resources at the end instead. That could be because the `` tag is not alone on its own line, which is actually fine in terms of comformity but confuses the regex... + +I think the simplest solution is to add a newline when we add the javascript blob, to keep the assertion that body is on its own line. I have done so in the aforementioned patch, which is reproduced here for simplicty: + + diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm + index 0093c655e..ac8a61895 100644 + --- a/IkiWiki/Plugin/recentchangesdiff.pm + +++ b/IkiWiki/Plugin/recentchangesdiff.pm + @@ -60,7 +60,7 @@ sub pagetemplate (@) { + sub format (@) { + my %params=@_; + + - if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { + + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page})."\n".$1!em)) { + # no tag, probably in preview mode + $params{content}=$params{content}.include_javascript(undef); + } + diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm + index 083966ad2..1ef6b2e2a 100644 + --- a/IkiWiki/Plugin/relativedate.pm + +++ b/IkiWiki/Plugin/relativedate.pm + @@ -26,7 +26,7 @@ sub getsetup () { + sub format (@) { + my %params=@_; + + - if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { + + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page})."\n".$1!em)) { + # no tag, probably in preview mode + $params{content}=$params{content}.include_javascript(undef); + } + diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm + index eea6e8861..9f74f6029 100644 + --- a/IkiWiki/Plugin/toggle.pm + +++ b/IkiWiki/Plugin/toggle.pm + @@ -68,7 +68,7 @@ sub format (@) { + + if ($params{content}=~s!(
\s*)
!$1!g) { + $params{content}=~s/
//g; + - if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { + + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page})."\n".$1!em)) { + # no tag, probably in preview mode + $params{content}=$params{content}.include_javascript(undef); + } + +Sorry for the trouble, HTH! :) + +PS: Note that it seems like browsers are happy to ignore the spec and load stuff outside of the `` tag, thankfully. So this is mostly a cosmetic/conformity thing...