X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/7f93b123c983c7ca2a2bf7010e4be921cba9a8fa..dfd1b7f527415baf99c181a057bfeb12a0976c75:/stage2/static/js/checkfile.js diff --git a/stage2/static/js/checkfile.js b/stage2/static/js/checkfile.js new file mode 100644 index 0000000..f15c134 --- /dev/null +++ b/stage2/static/js/checkfile.js @@ -0,0 +1,25 @@ +$(function() { + "use strict"; + $('input[type=file]').on('change', function () { + if (window.FileReader && this.files && this.files[0]) { + var ok = true; + var name = this.files[0].name; + if (this.getAttribute('data-ext')) { + var ext = this.getAttribute('data-ext'); + var re = new RegExp('\\.(' + ext + ')$', 'i'); + if (!re.exec(name)) { + alert('Błędne rozszerzenie! Powinno być jedno z: ' + ext.replace(/\|/g, ', ')); + ok = false; + } + } + var size = this.files[0].size; + if (size > 10 * 1024 * 1024) { + alert('Rozmiar pliku nie może przekraczać 10 MB!'); + ok = false; + } + if (!ok) { + this.form.reset(); + } + } + }); +});