galleryWidget.js 2.5 KB
$(
    function() {
        $(document)
            .on(
                'change', '.gw-image-input', function(e) {
                    var input = this;
                    $.ajax(
                        {
                            url: '/admin/imagemanager/manager/view',
                            type: "POST",
                            data: {
                                'ImageManager_id': input.value
                            },
                            success: function(data) {
                                $(
                                    '#' + $(input)
                                        .data('img')
                                )
                                    .attr('src', data.image);
                                $(
                                    '#' + $(input)
                                        .data('name')
                                )
                                    .html(data.fileName);
                            }
                        }
                    );
                }
            );

        $(document)
            .on(
                'click', '#add-image', function(e) {
                    var hash = Math.floor(Math.random() * 89999) + 10000;
                    var content = '<div class="gw-item"><div class="gw-item-bg"><input id="' + hash + '" class="gw-image-input" name ="images[' + hash + ']" ' + 'data-img="' + hash + '_img" data-name="' + hash + '_name" type ="hidden"> ' + '<div class="image_gall"><img id="' + hash + '_img" src="/admin/fonts/img/gallery-no-img.png" alt=""></div>' + '<p id="' + hash + '_name" class="text-info"></p></div>' + '<div class="gallery-buttons-wrapps"><button type="button" class="open-modal-imagemanager btn btn-primary btn-folder-gallery" data-aspect-ratio="" data-crop-view-mode="1" ' + 'data-input-id="' + hash + '"><i class="fa fa-folder-open"></i></button><button type="button" class="remove-img btn btn-danger">' + '<i class="fa fa-trash"></i></button></div></div>';
                    $('.gw-container').append(content);
                    //                    if (document.querySelectorAll(".gw-container > .gw-item").length % 3 === 0) {
                    //                        $('.gw-container').append('<div class="clearfix"></div>');
                    //                    }
                }
            );
        $(document)
            .on(
                'click', '.remove-img', function(e) {
                    $(this).parent().parent().remove();
                }
            )
    }
);