<commit_before>/**
 * This jQuery plugin will be the javascript hub for all contentNodeField actions of the MMCmfContentBundle
 */
(function ($) {

    /**
     *
     * @param $contentNode
     * @param $options
     */
    var mmCmfContentStructureEditor = function ($contentNodes, $options) {

        var $this = this;
        this.contentNodes = $contentNodes;
        this.settings = $options;
        this.modalParent = $('body');

        this.initiateDragula($('.ContentNodeChildren.draggable'));


        $(this.contentNodes).each(function (key, $contentNode) {
            if (!$($contentNode).data('mmCmfContentStructureEditor')) {
                $this.appendSettingsMenu($($contentNode));
                $($contentNode).data('mmCmfContentStructureEditor', $this);
            }

        });
    };

    /**
     * creates CmfContentNode settings gui
     */
    mmCmfContentStructureEditor.prototype.appendSettingsMenu = function ($contentNode) {

        var $this = this;
        var $settings = this.settings;
        /**
         * append to inner box div
         */
        var $box = this.generateSettingsBox($contentNode);

        var $boxInner = $('<div class="inner" />');

        for (var i in $settings.gridSizes) {
            var $selectBox = this.generateColumnSelect($contentNode, $settings.gridSizes[i], $settings.gridCount);
            $boxInner.append($selectBox);
        }

        /**
         * bind change event
         */
        $boxInner.on('change', 'select', function (e) {

            e.preventDefault();
            $this.onChangeGridsystem($contentNode, $boxInner, $box);
        });


        /**
         * append position switch widget
         */
        var $posSwitch = this.generatePositionSwitchControls($contentNode);
        $boxInner.append($posSwitch);


        /**
         * append inner controlls to main menu
         */
        $box.append($boxInner);

        $contentNode.append($box);

    };


    mmCmfContentStructureEditor.prototype.onChangeGridsystem = function ($contentNode, $boxInner, $box) {

        $box.parent().removeClass(function (index, css) {
            return (css.match(/col-[a-z1-9\-]*/g) || []).join(' ');
        });

        $boxInner.find('select').each(function () {
            $box.parent().addClass($(this).val());
        });

        var $fieldName = 'classes';
        var $value = $contentNode.attr('class');

        var $cmfId = $contentNode.data('cmf-id');

        var $cmfForbiddenClasses = $contentNode.data('cmf-css-generated-classes') +
            " " + this.settings.highlightClass +
            " " + this.settings.hoverClass;

        var $cmfForbiddenClassesArray = $cmfForbiddenClasses.split(" ");

        for (var i = 0; i < $cmfForbiddenClassesArray.length; i++) {
            $value = $value.replace($cmfForbiddenClassesArray[i], '');
        }

        $(document).trigger('updated.MMCmfContentFieldEditor',
            {
                value: $value.trim(),
                name: $fieldName,
                'cmf-id': $cmfId
            }
        );
    };


    /**
     * Returns gui elemets which lets the user move the position of the current ContentNode
     *
     * @returns {*|HTMLElement}
     */
    mmCmfContentStructureEditor.prototype.generatePositionSwitchControls = function ($contentNode) {

        var $this = this;
        /**
         * manual position switcher
         */
        var $posiswitch = $('<div class="posiswitch"><div class="upper"><i class="fa fa-chevron-up"></i></div><div class="downer"><i class="fa fa-chevron-down"></i></div></div>');

        /**
         * bind events
         */
        $posiswitch.on('click', '.upper , .downer', function (e) {

            e.preventDefault();

            var $ele = $(this);

            if ($ele.hasClass('upper')) {
                if ($contentNode.prev().hasClass('ContentNode'))
                    $contentNode.prev().before($contentNode);
            }

            if ($ele.hasClass('downer')) {
                if ($contentNode.next().hasClass('ContentNode'))
                    $contentNode.next().after($contentNode);
            }

            $this.refreshPositions($contentNode);
        });

        return $posiswitch;
    };

    /**
     * Returns Grid-System-Size selectbox which lets the user change the grid size based on the viewport
     *
     * @returns {*|HTMLElement}
     */
    mmCmfContentStructureEditor.prototype.generateColumnSelect = function ($contentNode, $gridSize, $gridCount) {

        var $select = $('<select />').data('grid-size', $gridSize);

        $select.append('<option></option>');

        for (var i = 1; i <= $gridCount; i++) {

            var $colClass = 'col-' + $gridSize + '-' + i;
            var $option = $('<option value="' + $colClass + '">' + i + '</option>');

            if ($contentNode.hasClass($colClass))
                $option.attr('selected', 'selected');

            $select.append($option);
        }

        var $selectContainer = $('<div class="select-container select-container-' + $gridSize + '" />');
        $selectContainer.append('<label>' + $gridSize.toUpperCase() + '</label>');
        $selectContainer.append($select);

        return $selectContainer;

    };

    /**
     * loads the contentNode Modal
     *
     * @param $url
     */
    mmCmfContentStructureEditor.prototype.loadSettingsForm = function ($url,$contentNode) {

        var $this = this;

        var $id = $contentNode.data('cmf-id');

        if ($url != "")
            $.ajax({
                'url': $url,
                'method': 'GET',
                'success': function (request) {
                    $this.modalParent.append(request);
                    $('#modal_content_node_' + $id )
                        .modal()
                        .on('hidden.bs.modal', function () {
                            $(this).remove();
                        });<commit_msg>Fixed mmCmfContentStructureEditor Modal massloading-bug: ContentNode-SettingsForm no longer calls for general .modal css selector; also added html-id attribute to general-form<commit_after>/**
 * This jQuery plugin will be the javascript hub for all contentNodeField actions of the MMCmfContentBundle
 */
(function ($) {

    /**
     *
     * @param $contentNode
     * @param $options
     */
    var mmCmfContentStructureEditor = function ($contentNodes, $options) {

        var $this = this;
        this.contentNodes = $contentNodes;
        this.settings = $options;
        this.modalParent = $('body');

        this.initiateDragula($('.ContentNodeChildren.draggable'));


        $(this.contentNodes).each(function (key, $contentNode) {
            if (!$($contentNode).data('mmCmfContentStructureEditor')) {
                $this.appendSettingsMenu($($contentNode));
                $($contentNode).data('mmCmfContentStructureEditor', $this);
            }

        });
    };

    /**
     * creates CmfContentNode settings gui
     */
    mmCmfContentStructureEditor.prototype.appendSettingsMenu = function ($contentNode) {

        var $this = this;
        var $settings = this.settings;
        /**
         * append to inner box div
         */
        var $box = this.generateSettingsBox($contentNode);

        var $boxInner = $('<div class="inner" />');

        for (var i in $settings.gridSizes) {
            var $selectBox = this.generateColumnSelect($contentNode, $settings.gridSizes[i], $settings.gridCount);
            $boxInner.append($selectBox);
        }

        /**
         * bind change event
         */
        $boxInner.on('change', 'select', function (e) {

            e.preventDefault();
            $this.onChangeGridsystem($contentNode, $boxInner, $box);
        });


        /**
         * append position switch widget
         */
        var $posSwitch = this.generatePositionSwitchControls($contentNode);
        $boxInner.append($posSwitch);


        /**
         * append inner controlls to main menu
         */
        $box.append($boxInner);

        $contentNode.append($box);

    };


    mmCmfContentStructureEditor.prototype.onChangeGridsystem = function ($contentNode, $boxInner, $box) {

        $box.parent().removeClass(function (index, css) {
            return (css.match(/col-[a-z1-9\-]*/g) || []).join(' ');
        });

        $boxInner.find('select').each(function () {
            $box.parent().addClass($(this).val());
        });

        var $fieldName = 'classes';
        var $value = $contentNode.attr('class');

        var $cmfId = $contentNode.data('cmf-id');

        var $cmfForbiddenClasses = $contentNode.data('cmf-css-generated-classes') +
            " " + this.settings.highlightClass +
            " " + this.settings.hoverClass;

        var $cmfForbiddenClassesArray = $cmfForbiddenClasses.split(" ");

        for (var i = 0; i < $cmfForbiddenClassesArray.length; i++) {
            $value = $value.replace($cmfForbiddenClassesArray[i], '');
        }

        $(document).trigger('updated.MMCmfContentFieldEditor',
            {
                value: $value.trim(),
                name: $fieldName,
                'cmf-id': $cmfId
            }
        );
    };


    /**
     * Returns gui elemets which lets the user move the position of the current ContentNode
     *
     * @returns {*|HTMLElement}
     */
    mmCmfContentStructureEditor.prototype.generatePositionSwitchControls = function ($contentNode) {

        var $this = this;
        /**
         * manual position switcher
         */
        var $posiswitch = $('<div class="posiswitch"><div class="upper"><i class="fa fa-chevron-up"></i></div><div class="downer"><i class="fa fa-chevron-down"></i></div></div>');

        /**
         * bind events
         */
        $posiswitch.on('click', '.upper , .downer', function (e) {

            e.preventDefault();

            var $ele = $(this);

            if ($ele.hasClass('upper')) {
                if ($contentNode.prev().hasClass('ContentNode'))
                    $contentNode.prev().before($contentNode);
            }

            if ($ele.hasClass('downer')) {
                if ($contentNode.next().hasClass('ContentNode'))
                    $contentNode.next().after($contentNode);
            }

            $this.refreshPositions($contentNode);
        });

        return $posiswitch;
    };

    /**
     * Returns Grid-System-Size selectbox which lets the user change the grid size based on the viewport
     *
     * @returns {*|HTMLElement}
     */
    mmCmfContentStructureEditor.prototype.generateColumnSelect = function ($contentNode, $gridSize, $gridCount) {

        var $select = $('<select />').data('grid-size', $gridSize);

        $select.append('<option></option>');

        for (var i = 1; i <= $gridCount; i++) {

            var $colClass = 'col-' + $gridSize + '-' + i;
            var $option = $('<option value="' + $colClass + '">' + i + '</option>');

            if ($contentNode.hasClass($colClass))
                $option.attr('selected', 'selected');

            $select.append($option);
        }

        var $selectContainer = $('<div class="select-container select-container-' + $gridSize + '" />');
        $selectContainer.append('<label>' + $gridSize.toUpperCase() + '</label>');
        $selectContainer.append($select);

        return $selectContainer;

    };

    /**
     * loads the contentNode Modal
     *
     * @param $url
     */
    mmCmfContentStructureEditor.prototype.loadSettingsForm = function ($url,$contentNode) {

        var $this = this;

        if ($url != "")
            $.ajax({
                'url': $url,
                'method': 'GET',
                'success': function (request) {

                    $this.modalParent.append(request);

                    $(request)
                        .modal()
                        .on('hidden.bs.modal', function () {
                            $(this).remove();
                        });
{'fraction_non_alphanumeric': 0.15181848515181848, 'fraction_numerical': 0.000667334000667334, 'mean_word_length': 1.9705153617443012, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 41, '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': '6339306', 'n_tokens_mistral': 3382, 'n_tokens_neox': 3243, 'n_words': 630}