Created
May 23, 2014 09:33
-
-
Save AleksMeshkov/d5a938f87b292ae66da5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/*jslint unparam: true */ | |
/*global window, $ */ | |
$(function () { | |
'use strict'; | |
// Change this to the location of your server-side upload handler: | |
function removeErrorLabels() { | |
$('label.error-message').remove(); | |
} | |
function toggleInterface() { | |
$(".block-main-upload, .block-infofile").toggle(); | |
} | |
$('form').on('submit', function (e) { | |
removeErrorLabels(); | |
e.preventDefault(); | |
$.post("http://fo.ontabfile.com/uploads", $(this).serialize(), function (jsonRes) { | |
if (jsonRes.errors) { | |
$.each(jsonRes.errors, function (inputName, error) { | |
$('input[name="' + inputName + '"]').after('<label class="error-message">' + error + '</label>'); | |
}); | |
} else { | |
alert('ok!'); | |
} | |
}); | |
}); | |
$('#fileupload').fileupload({ | |
dropZone : $('#dropzone'), | |
autoUpload : true, | |
url : 'http://upload.ontabfile.com', | |
dataType : 'json', | |
done : function (e, data) { | |
var file = data.result.files[0]; | |
$('#input-location').val(file.location); | |
}, | |
progressall : function (e, data) { | |
var progress = parseInt(data.loaded / data.total * 100, 10); | |
$('#progress .progress-bar').css( | |
'width', | |
progress + '%' | |
).find('.progres-percent') | |
.text(progress + '%'); | |
} | |
}).prop('disabled', !$.support.fileInput) | |
.parent().addClass($.support.fileInput ? undefined : 'disabled') | |
.bind('fileuploadsend', function (e, data) { | |
toggleInterface(); | |
}); | |
$('#fileupload_photo').fileupload({ | |
url : 'http://fo.ontabfile.com/uploads/set_thumbnail', | |
dataType : 'json', | |
autoUpload : true, | |
done : function (e, data) { | |
if (data.result.error === 'true') { | |
alert('error'); | |
return false; | |
} | |
var _html_ = '<img src="' + data.result.url + '">'; | |
$('#fileupload_photo_loaded_thumb').html(_html_); | |
$('#input_thumbnail_location').val(data.result.url); | |
$('#photo-upload-loader').remove(); | |
}, | |
fail : function (e, data) { | |
removeErrorLabels(); | |
$('#input_thumbnail_location').after("<label class='error-message'>" + "validation.thumbnail.incorrect_format" + "</label>"); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment