Skip to content

Instantly share code, notes, and snippets.

@AleksMeshkov
Created May 23, 2014 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AleksMeshkov/d5a938f87b292ae66da5 to your computer and use it in GitHub Desktop.
Save AleksMeshkov/d5a938f87b292ae66da5 to your computer and use it in GitHub Desktop.
<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