$(function () { if (window.my_user_id < 0) // dirty hack! document.location.href = '/'; $('#file_error').hide(); $('#tags_error').hide(); $('#captcha_error').hide(); $('#upload_suggestions').hide(); $('#tags_field').on('keyup', function (event) { var tags = $('#tags_field').val(); if (tags[tags.length - 1] == ' ') { $('#upload_suggestions').hide(); return; } tags = tags.trim(); if (tags.length == 0) { $('#upload_suggestions').hide(); return; } suggest('#upload_suggestions', '#upload_suggestions_content', '#tags_field', tags); }); $('#upload_button').click(function () { $('#upload_button').addClass('is-loading'); $('#upload_button').prop('disabled', true); var form = new FormData(); form.append('video', $('#video').prop('files')[0]); form.append('tags', $('#tags_field').val()); form.append('h-captcha-response', grecaptcha.getResponse()); api_unchecked('upload/video', form, function (data) { $('#upload_button').removeClass('is-loading'); $('#upload_button').prop('disabled', false); if (data.error !== undefined) { switch (data.error) { case 'not a valid video': case 'illegal video': show_hide('#file_error'); break; case 'illegal tags': show_hide('#tags_error'); break; case 'captcha check failed': show_hide('#captcha_error'); break; default: popup('danger', 'Error: ' + data.error); break; } grecaptcha.reset(); return; } popup('primary', 'Successfully uploaded your video!'); setTimeout(function () { document.location.href = '/watch/' + String(data.video_id); }, 1500); }); }); });