From: Marius Gavrilescu Date: Sat, 10 Jan 2015 18:12:24 +0000 (+0200) Subject: Try to divine file format from file extension X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=cb84f1235ad2e9b8ff24aee8dd1b71b0192b4e0b;p=plack-app-gruntmaster.git Try to divine file format from file extension --- diff --git a/MANIFEST b/MANIFEST index b702b07..14f50e6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -15,6 +15,7 @@ js/01-zepto-jquery.js js/10-bootstrap-dropdown.js js/10-bootstrap-modal.js js/90-autoresize.js +js/90-divine-format.js js/90-form.js js/90-themes.js js/90-nav.js diff --git a/js/90-divine-format.js b/js/90-divine-format.js new file mode 100644 index 0000000..5a1a7d6 --- /dev/null +++ b/js/90-divine-format.js @@ -0,0 +1,47 @@ +(function(){ + 'use strict'; + + function divine_format() { + var filename = $('#prog').val(); + var ext = /\.([^.]*)$/.exec(filename)[1]; + var format; + + switch(ext) { + case 'c': + format = 'C'; + break; + case 'cc': + case 'cpp': + case 'cxx': + case 'C': + format = 'CPP'; + break; + case 'go': + format = 'GOLANG'; + break; + case 'hs': + case 'lhs': + format = 'HASKELL'; + break; + case 'java': + format = 'JAVA'; + break; + case 'pas': + format = 'PASCAL'; + break; + case 'pl': + format = 'PERL'; + break; + case 'py': + format = 'PYTHON'; + break; + } + + if(format) + $('#prog_format').val(format); + } + + $( document ).ready(function() { + $('#prog').on('change', divine_format); + }); +})();