protected function formSnippetsOutput($scripts, $widgetName, $ajaxRequest)
    {
        $preparedScripts = [];
        foreach ($scripts as $script) {
            if ($widgetName && !$ajaxRequest) {
                $sanitizedScript = $this->sanitize($script);
                $script = "WidgetsHandler.registerFunction('$sanitizedScript', '$widgetName');";
            }
            $preparedScripts[] = $script;
        }

        return implode(PHP_EOL, $preparedScripts);
    }