|
@@ -92,3 +92,56 @@ function init_components_part(input){
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function init_components_dropimage(input){
|
|
|
|
+
|
|
|
|
+ if(input.data('picker')){
|
|
|
|
+ var picker = input.data('picker')
|
|
|
|
+ }else{
|
|
|
|
+ var picker = $('<input class="hidden" type="file">');
|
|
|
|
+ input.after(picker);
|
|
|
|
+ input.data('picker',picker);
|
|
|
|
+ input.css('cursor','pointer');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ input.click(function(e){
|
|
|
|
+ e.preventDefault();
|
|
|
|
+ e.stopPropagation();
|
|
|
|
+
|
|
|
|
+ picker.trigger('click');
|
|
|
|
+ picker.change(function(){
|
|
|
|
+ var file = picker.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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }, false);
|
|
|
|
+ reader.readAsDataURL(file);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ input.on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
|
|
|
|
+ e.preventDefault();
|
|
|
|
+ e.stopPropagation();
|
|
|
|
+ })
|
|
|
|
+ input.on('drop', function (e) {
|
|
|
|
+ var droppedFiles = e.originalEvent.dataTransfer.files;
|
|
|
|
+ var reader = new FileReader();
|
|
|
|
+ reader.readAsDataURL(droppedFiles[0]);
|
|
|
|
+ reader.onload = function () {
|
|
|
|
+
|
|
|
|
+ input.attr('src',reader.result);
|
|
|
|
+ };
|
|
|
|
+ reader.onerror = function (error) {
|
|
|
|
+ console.log('Error: ', error);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+}
|