<commit_before><?php
/**
 * YAWIK
 * 
 * @filesource
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
 * @license   MIT
 * @author    <EMAIL>
 */

namespace Core\Form\View\Helper;

use Zend\Form\View\Helper\FormTextarea;
use Zend\Form\ElementInterface;

class FormEditor extends FormTextarea
{

    protected $theme = 'modern';
    /*
    public function __invoke(ElementInterface $element = null)
    {

    }
    */


    public function render(ElementInterface $element)
    {
        $translator = $this->getTranslator();
        $name   = $element->getName();
        if (empty($name) && $name !== 0) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the element has an assigned name; none discovered',
                __METHOD__
            ));
        }

        $renderer = $this->getView();

        /*
        $pluginManager = $renderer->getHelperPluginManager();
        if (!$pluginManager->has('edit')) {
            $pluginManager->setService('edit', $this);
        }
        */

        $headscript = $renderer->plugin('headscript');
        $basepath   = $renderer->plugin('basepath');

        $headscript->appendFile($basepath('js/tinymce/tinymce.jquery.min.js'));
        $headscript->prependFile($basepath('js/jquery.min.js'));
        //
        // mode : "textareas",
        $headscript->offsetSetScript('1000_tinymce_' . $this->getTheme() , '
        $(document).ready(function() {
            tinyMCE.init({
                selector : "div.tinymce_' . $this->getTheme() . '",
                inline : true,
                theme : "modern",
                placeholder: "crumber23",
                plugins: [
                    "advlist autolink lists charmap anchor",
                    "searchreplace visualblocks code fullscreen",
                    "contextmenu paste"
                ],
                removed_menuitems: "newdocument",' . PHP_EOL
                . $this->additionalOptions() .

                'setup: function(editor) {
                    setPlaceHolder = function(editor, show) {
                        placeHolder = $("#placeholder-" + editor.id);
                        if (placeHolder.length == 1) {
                            if (show && editor.getContent() == "") {
                                placeHolder.show();
                            }
                            else {
                                placeHolder.hide();
                            }
                         }
                    },
                    editor.on("focus", function(e) {
                        setPlaceHolder(editor, false);
                    });
                    editor.on("blur", function(e) {
                        setPlaceHolder(editor, true);
                        if (editor.isDirty()) {
                            //console.log("blur event", e);
                            editor.save();
                            var container = e.target.bodyElement;
                            $(container).parents("html").addClass("yk-changed");
                            var form = $(container).parents("form");
                            //console.log("form", form, container);
                            form.submit();
                            $(form).on("yk.forms.done", function(){
                                console.log("done");
                                //$(container).parents("html").removeClass("yk-changed");
                            });
                        }
                    });
                }
            });
        });
        ');

        $attributes         = $element->getAttributes();
        $attributes['name'] = $name;
        $attributes['id']   = $name;
        $content            = $element->getValue();
        if (!isset($content)) {
            $content = '';
        }
        if (is_string($content)) {
            // content is should be in an ordinary textarea
            $escapeHtml         = $this->getEscapeHtmlHelper();

            $class = array_key_exists('class',$attributes)?$attributes['class']:'';
            $class .= (empty($class)?:' ') . ' tinymce_' . $this->getTheme() ;
            $attributes['class'] = $class;
            $placeHolder = '';
            $elementOptions = $element->getOptions();
            if (array_key_exists('placeholder', $elementOptions) && !empty($elementOptions['placeholder'])) {
                $placeHolder = '<div id="placeholder-' . $name . '" style="border: 0 none; position: relative; top: 2ex; left: 10px; color: #aaa; height: 0px; overflow: visible;' . (empty($content)?'':'display:none;') . '">' . $elementOptions['placeholder'] . '</div>';
            }
            return
                $placeHolder
                . sprintf(
                '<div %s >%s</div>',
                $this->createAttributesString($attributes),
                $content
            );

            return sprintf(
                '<textarea %s>%s</textarea>',
                $this->createAttributesString($attributes),
                $escapeHtml($content)
            );
        }
        else {
            //$content->injectElement($this);
            return (string) $content;
        }
    }

    protected function getTheme() {
        return $this->theme;
    }

    protected function additionalOptions() {
        return '';
    }

}<commit_msg>[Jobs] Removes translator from View/Helper/FormEditor.php<commit_after><?php
/**
 * YAWIK
 * 
 * @filesource
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
 * @license   MIT
 * @author    <EMAIL>
 */

namespace Core\Form\View\Helper;

use Zend\Form\View\Helper\FormTextarea;
use Zend\Form\ElementInterface;


class FormEditor extends FormTextarea
{
    protected $theme = 'modern';

    protected $translator;

    public function render(ElementInterface $element)
    {
        $name   = $element->getName();
        if (empty($name) && $name !== 0) {
            throw new \DomainException(sprintf(
                '%s requires that the element has an assigned name; none discovered',
                __METHOD__
            ));
        }

        $renderer = $this->getView();

        $headscript = $renderer->plugin('headscript');
        $basepath   = $renderer->plugin('basepath');

        $headscript->appendFile($basepath('js/tinymce/tinymce.jquery.min.js'));
        $headscript->prependFile($basepath('js/jquery.min.js'));
        //
        // mode : "textareas",
        $headscript->offsetSetScript('1000_tinymce_' . $this->getTheme() , '
        $(document).ready(function() {
            tinyMCE.init({
                selector : "div.tinymce_' . $this->getTheme() . '",
                inline : true,
                theme : "modern",
                placeholder: "crumber23",
                plugins: [
                    "advlist autolink lists charmap anchor",
                    "searchreplace visualblocks code fullscreen",
                    "contextmenu paste"
                ],
                removed_menuitems: "newdocument",' . PHP_EOL
                . $this->additionalOptions() .

                'setup: function(editor) {
                    setPlaceHolder = function(editor, show) {
                        placeHolder = $("#placeholder-" + editor.id);
                        if (placeHolder.length == 1) {
                            if (show && editor.getContent() == "") {
                                placeHolder.show();
                            }
                            else {
                                placeHolder.hide();
                            }
                         }
                    },
                    editor.on("focus", function(e) {
                        setPlaceHolder(editor, false);
                    });
                    editor.on("blur", function(e) {
                        setPlaceHolder(editor, true);
                        if (editor.isDirty()) {
                            //console.log("blur event", e);
                            editor.save();
                            var container = e.target.bodyElement;
                            $(container).parents("html").addClass("yk-changed");
                            var form = $(container).parents("form");
                            //console.log("form", form, container);
                            form.submit();
                            $(form).on("yk.forms.done", function(){
                                console.log("done");
                                //$(container).parents("html").removeClass("yk-changed");
                            });
                        }
                    });
                }
            });
        });
        ');

        $attributes         = $element->getAttributes();
        $attributes['name'] = $name;
        $attributes['id']   = $name;
        $content            = $element->getValue();
        if (!isset($content)) {
            $content = '';
        }
        if (is_string($content)) {
            // content is should be in an ordinary textarea
            $escapeHtml         = $this->getEscapeHtmlHelper();

            $class = array_key_exists('class',$attributes)?$attributes['class']:'';
            $class .= (empty($class)?:' ') . ' tinymce_' . $this->getTheme() ;
            $attributes['class'] = $class;
            $placeHolder = '';
            $elementOptions = $element->getOptions();
            if (array_key_exists('placeholder', $elementOptions) && !empty($elementOptions['placeholder'])) {
                $placeHolder = '<div id="placeholder-' . $name . '" style="border: 0 none; position: relative; top: 2ex; left: 10px; color: #aaa; height: 0px; overflow: visible;' . (empty($content)?'':'display:none;') . '">' . $elementOptions['placeholder'] . '</div>';
            }
            return
                $placeHolder
                . sprintf(
                '<div %s >%s</div>',
                $this->createAttributesString($attributes),
                $content
            );

            return sprintf(
                '<textarea %s>%s</textarea>',
                $this->createAttributesString($attributes),
                $escapeHtml($content)
            );
        } else {

            return (string) $content;
        }
    }

    protected function getTheme() {
        return $this->theme;
    }

    protected function additionalOptions() {
        return '';
    }
}
{'fraction_non_alphanumeric': 0.13979728437559763, 'fraction_numerical': 0.004016064257028112, 'mean_word_length': 1.3609480812641084, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3627093', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2530, 'n_words': 466}