|
@@ -25,9 +25,10 @@ function imageInit(){
|
|
},
|
|
},
|
|
triggerFormSubmit = function()
|
|
triggerFormSubmit = function()
|
|
{
|
|
{
|
|
- var event = document.createEvent( 'HTMLEvents' );
|
|
|
|
- event.initEvent( 'submit', true, false );
|
|
|
|
- form.dispatchEvent( event );
|
|
|
|
|
|
+ $('#imgUpload').submit();
|
|
|
|
+ //var event = document.createEvent( 'HTMLEvents' );
|
|
|
|
+ //event.initEvent( 'submit', true, false );
|
|
|
|
+ //form.dispatchEvent( event );
|
|
};
|
|
};
|
|
|
|
|
|
// letting the server side to know we are going to make an Ajax request
|
|
// letting the server side to know we are going to make an Ajax request
|
|
@@ -41,11 +42,7 @@ function imageInit(){
|
|
input.addEventListener( 'change', function( e )
|
|
input.addEventListener( 'change', function( e )
|
|
{
|
|
{
|
|
showFiles( e.target.files );
|
|
showFiles( e.target.files );
|
|
-
|
|
|
|
-
|
|
|
|
triggerFormSubmit();
|
|
triggerFormSubmit();
|
|
-
|
|
|
|
-
|
|
|
|
});
|
|
});
|
|
|
|
|
|
// drag&drop files if the feature is available
|
|
// drag&drop files if the feature is available
|
|
@@ -83,15 +80,13 @@ function imageInit(){
|
|
|
|
|
|
|
|
|
|
triggerFormSubmit();
|
|
triggerFormSubmit();
|
|
-
|
|
|
|
|
|
+ e.dataTransfer.files = [];
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the form was submitted
|
|
// if the form was submitted
|
|
- form.addEventListener( 'submit', function( e )
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
|
|
+ $('#imgUpload').submit(function(e){
|
|
// preventing the duplicate submissions if the current one is in progress
|
|
// preventing the duplicate submissions if the current one is in progress
|
|
if( form.classList.contains( 'is-uploading' ) ) return false;
|
|
if( form.classList.contains( 'is-uploading' ) ) return false;
|
|
|
|
|
|
@@ -127,7 +122,7 @@ function imageInit(){
|
|
|
|
|
|
// ajax request
|
|
// ajax request
|
|
var ajax = new XMLHttpRequest();
|
|
var ajax = new XMLHttpRequest();
|
|
- ajax.open( form.getAttribute( 'method' ), form.getAttribute( 'action' ), true );
|
|
|
|
|
|
+ ajax.open( form.getAttribute( 'method' ), form.getAttribute( 'action' ), false );
|
|
|
|
|
|
ajax.onload = function()
|
|
ajax.onload = function()
|
|
{
|
|
{
|
|
@@ -155,9 +150,13 @@ function imageInit(){
|
|
form.classList.remove( 'is-uploading' );
|
|
form.classList.remove( 'is-uploading' );
|
|
alert( 'Error. Please, try again!' );
|
|
alert( 'Error. Please, try again!' );
|
|
};
|
|
};
|
|
-
|
|
|
|
ajax.send( ajaxData );
|
|
ajax.send( ajaxData );
|
|
- imageInit();
|
|
|
|
|
|
+ form.classList.remove( 'is-uploading' );
|
|
|
|
+ form.classList.remove( 'is-error', 'is-success' );
|
|
|
|
+
|
|
|
|
+ e.target.files = [];
|
|
|
|
+ input.value = "";
|
|
|
|
+ droppedFiles = false;
|
|
}
|
|
}
|
|
else // fallback Ajax solution upload for older browsers
|
|
else // fallback Ajax solution upload for older browsers
|
|
{
|
|
{
|