<commit_before>(function($){
    $.fn.app.attachment = function(method) {

        var sandbox,
            // Стандарный input для файлов
            maxAttachments = Constants.max_attachments_count,
            maxFileSize = Constants.upload_max_filesize,
            attCounter = 0,
            fancyboxContainer = ".fancybox"
        ;

        var maxFileSizeMB = Math.round(maxFileSize / 1024 / 1024);

        var methods = {
            init: function(options) {
                sandbox = $.extend(true, {}, this.app.attachment.defaults, options);
                return this.each(function() {
                    var $this = $(this);
                    helpers.initAttachmentMenu($this);
                    helpers.initCancelSurvey($this);
                    helpers.initFancyBoxImage($this);
                });
            }
        };

        var helpers = {
            initAttachmentMenu: function(d) {
                helpers.bindPhotoAttachment();
                helpers.bindFileAttachment();
                helpers.bindRemoveIcon();
                $(d).on('click', '.plus-menu li', function(e) {
                        e.stopPropagation();
                        var $filesInputContainer = $(this).closest('form').find('.files-input');

                        if (window.FormData === undefined) {
                            alert('Ваш браузер устарел. Вы не можете прикрепить файлы.');
                            return false;
                        }

                        var fileInput = '';
                        var attachmentType = $(this).find('i').data('attachment-type');
                        attCounter++;

                        if (attachmentType == "image") {
                            fileInput = $('<input type="file" name="images[]" class="image-field hide input-file-'+ attCounter +'"/>')
                                .clone()
                                .appendTo($filesInputContainer);

                        } else if (attachmentType == "document") {
                            fileInput = $('<input type="file" name="documents[]" class="document-field hide input-file-'+ attCounter +'"/>')
                                .clone()
                                .appendTo($filesInputContainer);

                        } else if (attachmentType == "survey") {
                            helpers.showHideSurvey(1);
                            return true;
                        } else {
                            alert("Error");
                        }

                        // спрятать меню
                        $(document).find(".plus-menu").removeClass("active");

                        if (fileInput) {
                            fileInput.click();
                        }
                    }
                );
            },

            initFancyBoxImage: function(d) {
                $(d).find(fancyboxContainer).fancybox({
                    cycling: false,
                    padding: 0,
                    hideOnOverlayClick: true,
                    //openEffect : 'elastic',
                    openSpeed  : 250,
                    overlayShow: true,

//                    closeEffect : 'elastic',
//                    closeSpeed  : 250,

                    "autoScale": false,
                    "autoSize": true,
                    "fitToView": false,

                    closeClick : true,

                    helpers: {
                        overlay: {
                            locked: false
                        }
                    }
                });
            },

            initCancelSurvey: function(d) {
                $(d).on('click', '#post-content-poll .icon-close', function() {
                    helpers.showHideSurvey(0);
                })
            },

            showHideSurvey: function(show) {
                if (show) {
                    $('#post-content-status').fadeOut(function(){
                        $('#post-content-poll').show().addClass('animated bounceIn').removeClass('bounceOut');
                        reloadMasonry(0);
                    });
                } else {
                    if (Modernizr.csstransforms3d){
                        $('#post-content-poll').removeClass('bounceIn').addClass('bounceOut').delay(500).queue(function(){
                            $(this).hide();
                            $('#post-content-status').fadeIn();
                            reloadMasonry(0);
                            $(this).dequeue();
                        });
                    }
                    else {
                        $('#post-content-poll').removeClass('bounceIn').addClass('bounceOut').hide();
                        $('#post-content-status').show();
                        reloadMasonry(0);
                    }
                }
                reloadMasonry();
            },

            bindPhotoAttachment: function() {
                $(document).on('change', '.image-field', function() {
                    helpers.displayFiles(this, 'image');
                });
            },

            bindFileAttachment: function() {
                $(document).on('change', '.document-field', function() {
                    helpers.displayFiles(this, 'document');
                });
            },

            bindRemoveIcon: function() {
                // Удаление из нового поста
                $(document).on('click', ".create-post .fancybox-close", function() {
                    var num = $(this).data('num');
                    $(".input-file-"+num).remove();
                    $(this).closest('li').remove();

                    return false;
                });

                // Удаление из редактируемого поста
                $(document).on('click', ".edit-post-footer .fancybox-close", function() {
                    var $form = $(this).closest('form');
                    var $removeContainer = $form.find('.attach-to-remove');
                    var id = $(this).data('id');
                    $(this).closest('li').remove();
                    var $checkbox = $('<input type="hidden" name="post[attachToRemove][]" value="'+id+'"/>');
                    $removeContainer.append($checkbox);
                    return false;
                });

                $(document).on('click', ".remove-doc-icon", function() {
                    var num = $(this).closest('.doc-element').data('num');
                    $(".input-file-"+num).remove();
                    $(this).closest('.doc-element').remove();

                    if ($(".document-field").length == 0) {
                        $(".doc-block .documents-title").hide();
                    }

                    return false;
                });
            },

            displayFiles: function(input, type) {

                var files = input.files;
                var $form = $(input).closest('form');

                var num = 0,
                    imgList = $form.find('.image-gallery-preview'),
                    docList = $form.find('.doc-block .doc-list'),
                    imageType = /image.*/
                    ;

                $form = $form.add(docList.closest('form'));

                $(document).on('reset', $form, function() {

                    imgList.empty();
                    docList.empty();

                    $('.files-input input:file', this).remove();<commit_msg>Правки<commit_after>(function($){
    $.fn.app.attachment = function(method) {

        var sandbox,
            // Стандарный input для файлов
            maxAttachments = Constants.max_attachments_count,
            maxFileSize = Constants.upload_max_filesize,
            attCounter = 0,
            fancyboxContainer = ".fancybox"
        ;

        var maxFileSizeMB = Math.round(maxFileSize / 1024 / 1024);

        var methods = {
            init: function(options) {
                sandbox = $.extend(true, {}, this.app.attachment.defaults, options);
                return this.each(function() {
                    var $this = $(this);
                    helpers.initAttachmentMenu($this);
                    helpers.initCancelSurvey($this);
                    helpers.initFancyBoxImage($this);
                });
            }
        };

        var helpers = {
            initAttachmentMenu: function(d) {
                helpers.bindPhotoAttachment();
                helpers.bindFileAttachment();
                helpers.bindRemoveIcon();
                $(d).on('click', '.plus-menu li', function(e) {
                        e.stopPropagation();
                        var $filesInputContainer = $(this).closest('form').find('.files-input');

                        if (window.FormData === undefined) {
                            alert('Ваш браузер устарел. Вы не можете прикрепить файлы.');
                            return false;
                        }

                        var fileInput = '';
                        var attachmentType = $(this).find('i').data('attachment-type');
                        attCounter++;

                        if (attachmentType == "image") {
                            fileInput = $('<input type="file" name="images[]" class="image-field hide input-file-'+ attCounter +'"/>')
                                .clone()
                                .appendTo($filesInputContainer);

                        } else if (attachmentType == "document") {
                            fileInput = $('<input type="file" name="documents[]" class="document-field hide input-file-'+ attCounter +'"/>')
                                .clone()
                                .appendTo($filesInputContainer);

                        } else if (attachmentType == "survey") {
                            helpers.showHideSurvey(1);
                            return true;
                        } else {
                            alert("Error");
                        }

                        // спрятать меню
                        $(document).find(".plus-menu").removeClass("active");

                        if (fileInput) {
                            fileInput.click();
                        }
                    }
                );
            },

            initFancyBoxImage: function(d) {
                $(d).find(fancyboxContainer).fancybox({
                    cycling: false,
                    padding: 0,
                    hideOnOverlayClick: true,
                    //openEffect : 'elastic',
                    openSpeed  : 250,
                    overlayShow: true,

//                    closeEffect : 'elastic',
//                    closeSpeed  : 250,

                    "autoScale": false,
                    "autoSize": true,
                    "fitToView": false,

                    closeClick : true,

                    helpers: {
                        overlay: {
                            locked: false
                        }
                    }
                });
            },

            initCancelSurvey: function(d) {
                $(d).on('click', '#post-content-poll .icon-close', function() {
                    helpers.showHideSurvey(0);
                })
            },

            showHideSurvey: function(show) {
                if (show) {
                    $('#post-content-status').fadeOut(function(){
                        $('#post-content-poll').show().addClass('animated bounceIn').removeClass('bounceOut');
                        reloadMasonry(0);
                    });
                } else {
                    if (Modernizr.csstransforms3d){
                        $('#post-content-poll').removeClass('bounceIn').addClass('bounceOut').delay(500).queue(function(){
                            $(this).hide();
                            $('#post-content-status').fadeIn();
                            reloadMasonry(0);
                            $(this).dequeue();
                        });
                    }
                    else {
                        $('#post-content-poll').removeClass('bounceIn').addClass('bounceOut').hide();
                        $('#post-content-status').show();
                        reloadMasonry(0);
                    }
                }
                reloadMasonry();
            },

            bindPhotoAttachment: function() {
                $(document).on('change', '.image-field', function() {
                    helpers.displayFiles(this, 'image');
                });
            },

            bindFileAttachment: function() {
                $(document).on('change', '.document-field', function() {
                    helpers.displayFiles(this, 'document');
                });
            },

            bindRemoveIcon: function() {
                // Удаление из нового поста
                $(document).on('click', ".create-post .fancybox-close", function() {
                    var num = $(this).data('num');
                    $(".input-file-"+num).remove();
                    $(this).closest('li').remove();
                    reloadMasonry();

                    return false;
                });

                // Удаление из редактируемого поста
                $(document).on('click', ".edit-post-footer .fancybox-close", function() {
                    var $form = $(this).closest('form');
                    var $removeContainer = $form.find('.attach-to-remove');
                    var id = $(this).data('id');
                    $(this).closest('li').remove();
                    var $checkbox = $('<input type="hidden" name="post[attachToRemove][]" value="'+id+'"/>');
                    $removeContainer.append($checkbox);
                    reloadMasonry();

                    return false;
                });

                $(document).on('click', ".remove-doc-icon", function() {
                    var num = $(this).closest('.doc-element').data('num');
                    $(".input-file-"+num).remove();
                    $(this).closest('.doc-element').remove();

                    if ($(".document-field").length == 0) {
                        $(".doc-block .documents-title").hide();
                    }
                    reloadMasonry();

                    return false;
                });
            },

            displayFiles: function(input, type) {

                var files = input.files;
                var $form = $(input).closest('form');

                var num = 0,
                    imgList = $form.find('.image-gallery-preview'),
                    docList = $form.find('.doc-block .doc-list'),
                    imageType = /image.*/
                    ;

                $form = $form.add(docList.closest('form'));

                $(document).on('reset', $form, function() {

                    imgList.empty();
                    docList.empty();

                    $('.files-input input:file', this).remove();
{'fraction_non_alphanumeric': 0.1340868053233465, 'fraction_numerical': 0.0036113154550926237, 'mean_word_length': 1.0527110501029513, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, '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': '2977437', 'n_tokens_mistral': 3667, 'n_tokens_neox': 3359, 'n_words': 552}