|
@@ -25,9 +25,10 @@ function imageInit(){
|
|
|
},
|
|
|
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
|
|
@@ -40,12 +41,8 @@ function imageInit(){
|
|
|
// automatically submit the form on file select
|
|
|
input.addEventListener( 'change', function( e )
|
|
|
{
|
|
|
- showFiles( e.target.files );
|
|
|
-
|
|
|
-
|
|
|
- triggerFormSubmit();
|
|
|
-
|
|
|
-
|
|
|
+ showFiles( e.target.files );
|
|
|
+ triggerFormSubmit();
|
|
|
});
|
|
|
|
|
|
// drag&drop files if the feature is available
|
|
@@ -83,18 +80,16 @@ function imageInit(){
|
|
|
|
|
|
|
|
|
triggerFormSubmit();
|
|
|
-
|
|
|
+ e.dataTransfer.files = [];
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
// 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
|
|
|
if( form.classList.contains( 'is-uploading' ) ) return false;
|
|
|
-
|
|
|
form.classList.add( 'is-uploading' );
|
|
|
form.classList.remove( 'is-error' );
|
|
|
|
|
@@ -126,10 +121,31 @@ function imageInit(){
|
|
|
ajaxData.append("language", language)
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /*
|
|
|
+ $.ajax({
|
|
|
+ type: "POST",
|
|
|
+ url: form.getAttribute( 'action' ),
|
|
|
+ headers: {"content-id": "pattern"},
|
|
|
+ data: ajaxData,
|
|
|
+ contentType: false,
|
|
|
+ processData: false,
|
|
|
+ success: function(res) {
|
|
|
+ getPattern(station, pattern)
|
|
|
+ input.value = "";
|
|
|
+ },
|
|
|
+ error: function (request, status, error) {
|
|
|
+ alert(request.responseText + status + error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ */
|
|
|
+
|
|
|
+ //Original Upload:
|
|
|
+
|
|
|
// ajax request
|
|
|
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()
|
|
|
{
|
|
|
form.classList.remove( 'is-uploading' );
|
|
@@ -138,15 +154,11 @@ function imageInit(){
|
|
|
getPattern(station, pattern)
|
|
|
|
|
|
input.value = "";
|
|
|
+ //imageInit();
|
|
|
//form.classList.add('is-success');
|
|
|
|
|
|
//old upload php: saveImages(station, pattern, curCount, language, ajax.responseText);
|
|
|
|
|
|
- /*
|
|
|
- var data = JSON.parse( ajax.responseText );
|
|
|
- form.classList.add( data.success == true ? 'is-success' : 'is-error' );
|
|
|
- if( !data.success ) errorMsg.textContent = data.error;
|
|
|
- */
|
|
|
}
|
|
|
else alert( 'Error. Please, contact the webmaster!' );
|
|
|
};
|
|
@@ -156,12 +168,22 @@ function imageInit(){
|
|
|
form.classList.remove( 'is-uploading' );
|
|
|
alert( 'Error. Please, try again!' );
|
|
|
};
|
|
|
-
|
|
|
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
|
|
|
{
|
|
|
+
|
|
|
var iframeName = 'uploadiframe' + new Date().getTime(),
|
|
|
iframe = document.createElement( 'iframe' );
|
|
|
|
|
@@ -183,6 +205,14 @@ function imageInit(){
|
|
|
iframe.parentNode.removeChild( iframe );
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ if(e.preventDefault){ e.preventDefault()}
|
|
|
+ else{e.stop()};
|
|
|
+
|
|
|
+ e.returnValue = false;
|
|
|
+ e.stopPropagation();
|
|
|
+ */
|
|
|
});
|
|
|
|
|
|
|
|
@@ -200,7 +230,6 @@ function imageInit(){
|
|
|
// Firefox focus bug fix for file input
|
|
|
input.addEventListener( 'focus', function(){ input.classList.add( 'has-focus' ); });
|
|
|
input.addEventListener( 'blur', function(){ input.classList.remove( 'has-focus' ); });
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
|