FIX: insert javascript requirements before the first inline script.

From http://open.silverstripe.org/ticket/6648.
This commit is contained in:
Simon Welsh 2012-07-01 18:29:54 +12:00 committed by Will Rossiter
parent 23ed5335e6
commit 9f6eeb4d0e

View File

@ -695,9 +695,10 @@ class Requirements_Backend {
// We put script tags into the body, for performance.
// If your template already has script tags in the body, then we put our script
// tags just before those. Otherwise, we put it at the bottom.
$p1 = strripos($content, '<script');
$p2 = stripos($content, '<body');
if($p1 !== false && $p1 > $p2) {
$p1 = stripos($content, '<script', $p2);
if($p1 !== false) {
$content = substr($content,0,$p1) . $jsRequirements . substr($content,$p1);
} else {
$content = preg_replace("/(<\/body[^>]*>)/i", $jsRequirements . "\\1", $content);