Debian Codegraph @

js/parsers/parser-file-type.js

raw symbols SCIP
1 /*! Parser: filetype - updated 11/10/2015 (v2.24.4) *//*
2 * When a file type extension is found, the equivalent name is
3 * prefixed into the parsed data, so sorting occurs in groups
4 */
5 /*global jQuery: false */
6 ;(function($) {
7 'use strict';
8
9 // basic list from http://en.wikipedia.org/wiki/List_of_file_formats
10 // To add a custom equivalent, define:
11 // $.tablesorter.fileTypes.equivalents['xx'] = 'A|B|C';
12 $.tablesorter.fileTypes = {
13 // divides filetype extensions in the equivalent list below
14 separator : '|',
15 equivalents : {
16 '3D Image' : '3dm|3ds|dwg|max|obj',
17 'Audio' : 'aif|aac|ape|flac|la|m4a|mid|midi|mp2|mp3|ogg|ra|raw|rm|wav|wma',
18 'Compressed' : '7z|bin|cab|cbr|gz|gzip|iso|lha|lz|rar|tar|tgz|zip|zipx|zoo',
19 'Database' : 'csv|dat|db|dbf|json|ldb|mdb|myd|pdb|sql|tsv|wdb|wmdb|xlr|xls|xlsx|xml',
20 'Development' : 'asm|c|class|cls|cpp|cc|cs|cxx|cbp|cs|dba|fla|h|java|lua|pl|py|pyc|pyo|sh|sln|r|rb|vb',
21 'Document' : 'doc|docx|odt|ott|pages|pdf|rtf|tex|wpd|wps|wrd|wri',
22 'Executable' : 'apk|app|com|exe|gadget|lnk|msi',
23 'Fonts' : 'eot|fnt|fon|otf|ttf|woff',
24 'Icons' : 'ani|cur|icns|ico',
25 'Images' : 'bmp|gif|jpg|jpeg|jpe|jp2|pic|png|psd|tga|tif|tiff|wmf|webp',
26 'Presentation' : 'pps|ppt',
27 'Published' : 'chp|epub|lit|pub|ppp|fm|mobi',
28 'Script' : 'as|bat|cgi|cmd|jar|js|lua|scpt|scptd|sh|vbs|vb|wsf',
29 'Styles' : 'css|less|sass',
30 'Text' : 'info|log|md|markdown|nfo|tex|text|txt',
31 'Vectors' : 'awg|ai|eps|cdr|ps|svg',
32 'Video' : 'asf|avi|flv|m4v|mkv|mov|mp4|mpe|mpeg|mpg|ogg|rm|rv|swf|vob|wmv',
33 'Web' : 'asp|aspx|cer|cfm|htm|html|php|url|xhtml'
34 }
35 };
36
37 $.tablesorter.addParser({
38 id: 'filetype',
39 is: function() {
40 return false;
41 },
42 format: function(s, table) {
43 var t,
44 c = table.config,
45 wo = c.widgetOptions,
46 groupSeparator = wo.group_separator || '-',
47 i = s.lastIndexOf('.'),
48 sep = $.tablesorter.fileTypes.separator,
49 m = $.tablesorter.fileTypes.matching,
50 types = $.tablesorter.fileTypes.equivalents;
51 if (!m) {
52 // make a string to 'quick' match the existing equivalents
53 t = [];
54 $.each(types, function(i, v) {
55 t.push(v);
56 });
57 m = $.tablesorter.fileTypes.matching = sep + t.join(sep) + sep;
58 }
59 if (i >= 0) {
60 t = sep + s.substring(i + 1, s.length) + sep;
61 if (m.indexOf(t) >= 0) {
62 for (i in types) {
63 if ((sep + types[i] + sep).indexOf(t) >= 0) {
64 // groupSeparator may use a regular expression!
65 return i + ( groupSeparator.toString().charAt(0) !== '/' ? wo.group_separator : '-' ) + s;
66 }
67 }
68 }
69 }
70 return s;
71 },
72 type: 'text'
73 });
74
75 // sort by file extension
76 // converts "this.is.an.image.jpg" into "jpg.this.is.an.image"
77 $.tablesorter.addParser({
78 id: 'file-extension',
79 is: function() {
80 return false;
81 },
82 format: function( str ) {
83 var ext,
84 parts = str.split( '.' );
85 if ( parts.length ) {
86 ext = parts.pop();
87 parts.unshift( ext );
88 return parts.join( '.' );
89 }
90 return str;
91 },
92 type: 'text'
93 });
94
95 })(jQuery);