|
@@ -5,40 +5,48 @@ function init_components_dropimage(input){
|
|
|
if(input.data('picker')){
|
|
|
var picker = input.data('picker')
|
|
|
}else{
|
|
|
- var picker = $('<input class="hidden" type="file">');
|
|
|
+ var picker = $('<div class="data-type-dropimage"><div class="dropimage-image"></div><input class="hidden" type="file"><div class="dropimage-edit" ><i class="fas fa-pencil-alt"></i></div></div>');
|
|
|
input.after(picker);
|
|
|
- input.data('picker',picker);
|
|
|
- input.css('cursor','pointer');
|
|
|
+ picker.find('.dropimage-image').append(input.detach());
|
|
|
+ input.data('picker',picker).css('cursor','pointer');
|
|
|
}
|
|
|
|
|
|
+ var fileInput = picker.find('input');
|
|
|
+ var imageInput = picker.find('.dropimage-image > img');
|
|
|
|
|
|
- input.click(function(e){
|
|
|
- e.preventDefault();
|
|
|
+
|
|
|
+ fileInput.click(function(e){
|
|
|
e.stopPropagation();
|
|
|
-
|
|
|
- picker.trigger('click');
|
|
|
- picker.change(function(){
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ picker.click(function(e){
|
|
|
+
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ fileInput.trigger('click');
|
|
|
+ fileInput.change(function(){
|
|
|
preloader(true);
|
|
|
- var file = picker.get(0).files[0];
|
|
|
- var reader = new FileReader();
|
|
|
- reader.addEventListener("load", function () {
|
|
|
+ var file = fileInput.get(0).files[0];
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.addEventListener("load", function () {
|
|
|
|
|
|
- input.attr('src',reader.result);
|
|
|
- if(input.attr('data-callback')!=""){
|
|
|
- var callback = input.attr('data-callback');
|
|
|
- window[callback](input,reader.result);
|
|
|
+ imageInput.attr('src',reader.result);
|
|
|
+ if(imageInput.attr('data-callback')!=""){
|
|
|
+ var callback = imageInput.attr('data-callback');
|
|
|
+ window[callback](picker,reader.result);
|
|
|
preloader(false);
|
|
|
}
|
|
|
|
|
|
- }, false);
|
|
|
+ }, false);
|
|
|
reader.readAsDataURL(file);
|
|
|
});
|
|
|
});
|
|
|
- input.on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
|
|
|
+ picker.on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
|
})
|
|
|
- input.on('drop', function (e) {
|
|
|
+ picker.on('drop', function (e) {
|
|
|
preloader(true);
|
|
|
var droppedFiles = e.originalEvent.dataTransfer.files;
|
|
|
var reader = new FileReader();
|