galleryWidget.js
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$(
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();
}
)
}
);