Created
September 3, 2014 08:41
-
-
Save saksmt/ed31bcc19e6b48342785 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
var uploadInput = $('#fileUpload'); | |
var selectFileButton = $('#selectFileButton'); | |
var selectedFile = $('#selectedFile'); | |
var uploadProgress = $('#uploadProgress'); | |
var currentFile = ''; | |
function fileChanged(e, data) { | |
console.log(e,data); | |
if(data === undefined || !data.files.length) { | |
return; | |
} | |
$('.error').fadeOut(); | |
var fileName = data.files[0].name; | |
if (fileName === currentFile) { | |
return; | |
} else { | |
currentFile = fileName; | |
} | |
if (!fileName.match(/mov|(m(4v|p4))/i)) { | |
uploadInput.val(''); | |
$('.error').fadeIn(); | |
var nua = navigator.userAgent; | |
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1)); | |
if (is_android) { // http://habrastorage.org/getpro/habr/post_images/027/2b2/eca/0272b2ecabaf7b64a8d37e78c099bbcd.png | |
window.location.hash = 'error'; | |
window.location.reload(); | |
} | |
init(); | |
return; | |
} | |
selectedFile.html('Selected: "'+ data.files[0].name+'"'); | |
uploadProgress.attr('aria-valuenow', 0); | |
uploadProgress.html(0+'%'); | |
uploadProgress.css('width',0+'%'); | |
uploadProgress.parent().fadeOut(); | |
init(); | |
} | |
function init() { | |
uploadInput.fileupload({ | |
dataType: 'json', | |
url: uploadInput.attr('data-url'), | |
autoUpload: false, | |
maxNumberOfFiles: 1, | |
fileInput: uploadInput, | |
maxFileSize: 1024*1024*1024*2, | |
acceptFileTypes: 'mov|(m(4v|p4))', | |
formData: function () { | |
console.log($('#tagsForm').serializeArray()); | |
return $('#tagsForm').serializeArray(); | |
}, | |
add: function (e,data) { | |
fileChanged(e, data); | |
console.log(data); | |
$('#uploadSubmit').unbind(); | |
$('#uploadSubmit').click(function () { | |
data.submit(); | |
uploadProgress.parent().fadeIn(); | |
}) | |
}, | |
change: fileChanged(), | |
progressall: function(e,data) { | |
var progress = parseInt(data.loaded / data.total * 100, 10); | |
uploadProgress.attr('aria-valuenow', progress); | |
uploadProgress.html(progress+'%'); | |
uploadProgress.css('width',progress+'%'); | |
}, | |
done: function(e,data) { | |
if(data.result.status === undefined) { | |
$('.error').fadeIn(); | |
console.log('Response: ',data); | |
} else { | |
$('.error').fadeOut(); | |
$('#content').html(data.result.page); | |
} | |
console.log(data); | |
} | |
}); | |
} | |
$(document).ready(function(){ | |
console.log('Document loaded, binding events!'); | |
uploadProgress.parent().hide(); | |
uploadProgress.parent().removeAttr('hidden'); | |
init(); | |
// http://habrastorage.org/getpro/habr/post_images/027/2b2/eca/0272b2ecabaf7b64a8d37e78c099bbcd.png | |
if (window.location.hash !== '#error') { | |
$('.error').hide(); | |
} else { | |
window.location.hash = ''; | |
} | |
$('.error').removeAttr('hidden'); | |
$('.soft-hide').css({ | |
'position': 'absolute', | |
'top': '-9999px', | |
'z-index': '-1' | |
}); | |
$('.soft-hide').removeClass('hidden'); | |
console.log('document is read!'); | |
selectFileButton.click(function(){console.log('clicked button!');console.log(uploadInput[0].tagName);uploadInput.click();}); | |
}); | |
$(function () { | |
/*uploadInput | |
.bind('fileuploadsend', function (e, data) { | |
if (data.dataType.substr(0, 6) === 'iframe') { | |
var progressObj = { | |
name: '{{ oneup_uploader_upload_key() }}', | |
value: (new Date()).getTime() // pseudo unique ID | |
}; | |
data.formData.push(progressObj); | |
data.context.data('interval', setInterval(function () { | |
$.get('{{ oneup_uploader_progress("video") }}', $.param([progressObj]), function (result) { | |
e = $.Event( 'progress', {bubbles: false, cancelable: true}); | |
$.extend(e, result); | |
(uploadInput.data('blueimp-fileupload') || | |
uploadInput.data('fileupload'))._onProgress(e, data); | |
}, 'json'); | |
}, 1000)); | |
} | |
}) | |
.bind('fileuploadalways', function (e, data) { | |
clearInterval(data.context.data('interval')); | |
}) | |
.bind('fileuploadchange', function (e,data) { | |
console.log(data); | |
selectedFile.text('Selected: "'+data.files[0].name+'"'); | |
}) | |
.bind('fileuploadprogressall', function (e,data) { | |
var progress = parseInt(data.loaded / data.total * 100, 10); | |
uploadProgress.attr('aria-valuenow', progress); | |
uploadProgress.html(progress+'%'); | |
uploadProgress.css('width',progress+'%'); | |
}) | |
.bind('fileuploaddone', function (e,data) { | |
; /// TODO: redirect to retrieved(video page or home) URL | |
});*/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment