galleryWidget.js
2.46 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
50
51
52
$(
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="col-md-4 gw-item"><input id="' + hash + '" class="gw-image-input" name ="images[' + hash + ']" ' + 'data-img="' + hash + '_img" data-name="' + hash + '_name" type ="hidden"> ' + '<img id="' + hash + '_img" class="img-rounded" src="/admin/product/create" alt="">' + '<p id="' + hash + '_name" class="text-info"></p>' + '<button type="button" class="open-modal-imagemanager btn btn-primary" 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>';
$('.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()
.remove();
}
)
}
);