<?php

namespace Oneup\Contao\J2B;

use Contao\PageModel;
use Contao\LayoutModel;
use Contao\PageRegular;

class Runner
{
    public function moveJs(PageModel $objPage, LayoutModel $objLayout, PageRegular $objPageRegular)
    {
        if ('FE' === TL_MODE) {
            if (!is_array($GLOBALS['TL_BODY'])) {
                $GLOBALS['TL_BODY'] = [];
            }

            foreach($GLOBALS['TL_JAVASCRIPT'] as $index => $javascript) {
                $javascript = preg_replace('/\|.*/', '', $javascript);

                $GLOBALS['TL_BODY'] = array_merge(
                    [
                        sprintf(
                            '<script type="text/javascript" src="%s"></script>',
                            $javascript
                        )
                    ],
                    $GLOBALS['TL_BODY']
                );

                unset($GLOBALS['TL_JAVASCRIPT'][$index]);
            }
        }
    }
}

<?php

namespace Oneup\Contao\J2B;

use Contao\PageModel;
use Contao\LayoutModel;
use Contao\PageRegular;

class Runner
{
    public function moveJs(PageModel $objPage, LayoutModel $objLayout, PageRegular $objPageRegular)
    {
        if ('FE' === TL_MODE) {
            foreach($GLOBALS['TL_JAVASCRIPT'] as $index => $javascript) {
                $javascript = preg_replace('/\|.*/', '', $javascript);

                $GLOBALS['TL_BODY'][] = '<script type="text/javascript" src="' . $javascript . '"></script>';

                unset($GLOBALS['TL_JAVASCRIPT'][$index]);
            }
        }
    }
}

Revert "Add <head>-javascripts before <body>-javascripts"
Revert "Add <head>-javascripts before <body>-javascripts"

This reverts commit 7681ef4f43591af5cae8e3d26935d8efd4632c73.
