11OC . MimeType = {
22
3+ files : [ ] ,
4+
35 mimeTypeAlias : { } ,
46
57 mimeTypeIcons : { } ,
68
79 init : function ( ) {
8- OC . MimeType . mimeTypeAlias = {
9- "application/octet-stream" : "file" , // use file icon as fallback
10-
11- "application/illustrator" : "image/vector" ,
12- "application/postscript" : "image/vector" ,
13- "image/svg+xml" : "image/vector" ,
14-
15- "application/coreldraw" : "image" ,
16- "application/x-gimp" : "image" ,
17- "application/x-photoshop" : "image" ,
18- "application/x-dcraw" : "image" ,
19-
20- "application/font-sfnt" : "font" ,
21- "application/x-font" : "font" ,
22- "application/font-woff" : "font" ,
23- "application/vnd.ms-fontobject" : "font" ,
24-
25- "application/json" : "text/code" ,
26- "application/x-perl" : "text/code" ,
27- "application/x-php" : "text/code" ,
28- "text/x-shellscript" : "text/code" ,
29- "application/yaml" : "text/code" ,
30- "application/xml" : "text/html" ,
31- "text/css" : "text/code" ,
32- "application/x-tex" : "text" ,
33-
34- "application/x-compressed" : "package/x-generic" ,
35- "application/x-7z-compressed" : "package/x-generic" ,
36- "application/x-deb" : "package/x-generic" ,
37- "application/x-gzip" : "package/x-generic" ,
38- "application/x-rar-compressed" : "package/x-generic" ,
39- "application/x-tar" : "package/x-generic" ,
40- "application/vnd.android.package-archive" : "package/x-generic" ,
41- "application/zip" : "package/x-generic" ,
42-
43- "application/msword" : "x-office/document" ,
44- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "x-office/document" ,
45- "application/vnd.openxmlformats-officedocument.wordprocessingml.template" : "x-office/document" ,
46- "application/vnd.ms-word.document.macroEnabled.12" : "x-office/document" ,
47- "application/vnd.ms-word.template.macroEnabled.12" : "x-office/document" ,
48- "application/vnd.oasis.opendocument.text" : "x-office/document" ,
49- "application/vnd.oasis.opendocument.text-template" : "x-office/document" ,
50- "application/vnd.oasis.opendocument.text-web" : "x-office/document" ,
51- "application/vnd.oasis.opendocument.text-master" : "x-office/document" ,
52-
53- "application/mspowerpoint" : "x-office/presentation" ,
54- "application/vnd.ms-powerpoint" : "x-office/presentation" ,
55- "application/vnd.openxmlformats-officedocument.presentationml.presentation" : "x-office/presentation" ,
56- "application/vnd.openxmlformats-officedocument.presentationml.template" : "x-office/presentation" ,
57- "application/vnd.openxmlformats-officedocument.presentationml.slideshow" : "x-office/presentation" ,
58- "application/vnd.ms-powerpoint.addin.macroEnabled.12" : "x-office/presentation" ,
59- "application/vnd.ms-powerpoint.presentation.macroEnabled.12" : "x-office/presentation" ,
60- "application/vnd.ms-powerpoint.template.macroEnabled.12" : "x-office/presentation" ,
61- "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" : "x-office/presentation" ,
62- "application/vnd.oasis.opendocument.presentation" : "x-office/presentation" ,
63- "application/vnd.oasis.opendocument.presentation-template" : "x-office/presentation" ,
64-
65- "application/msexcel" : "x-office/spreadsheet" ,
66- "application/vnd.ms-excel" : "x-office/spreadsheet" ,
67- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "x-office/spreadsheet" ,
68- "application/vnd.openxmlformats-officedocument.spreadsheetml.template" : "x-office/spreadsheet" ,
69- "application/vnd.ms-excel.sheet.macroEnabled.12" : "x-office/spreadsheet" ,
70- "application/vnd.ms-excel.template.macroEnabled.12" : "x-office/spreadsheet" ,
71- "application/vnd.ms-excel.addin.macroEnabled.12" : "x-office/spreadsheet" ,
72- "application/vnd.ms-excel.sheet.binary.macroEnabled.12" : "x-office/spreadsheet" ,
73- "application/vnd.oasis.opendocument.spreadsheet" : "x-office/spreadsheet" ,
74- "application/vnd.oasis.opendocument.spreadsheet-template" : "x-office/spreadsheet" ,
75- "text/csv" : "x-office/spreadsheet" ,
76-
77- "application/msaccess" : "database"
78- } ;
10+ $ . getJSON ( OC . webroot + '/core/mimetypes.json' , function ( data ) {
11+ OC . MimeType . mimeTypeAlias = data [ 'aliases' ] ;
12+ OC . MimeType . files = data [ 'files' ] ;
13+ } ) ;
7914 } ,
8015
8116 mimetypeIcon : function ( mimeType ) {
82- if ( mimeType === undefined ) {
17+ if ( _ . isUndefined ( mimeType ) ) {
8318 return undefined ;
8419 }
8520
@@ -90,49 +25,36 @@ OC.MimeType = {
9025 return OC . MimeType . mimeTypeIcons [ mimeType ] ;
9126 }
9227
93- if ( mimeType == 'dir' ) {
94- return OC . webroot + '/core/img/filetypes/folder.png' ;
95- }
96- if ( mimeType == 'dir-shared' ) {
97- return OC . webroot + '/core/img/filetypes/folder-shared.png' ;
98- }
99- if ( mimeType == 'dir-external' ) {
100- return OC . webroot + '/core/img/filetypes/folder-external.png' ;
101- }
102-
103- function checkExists ( url ) {
104- var ok ;
105- $ . ajax ( {
106- url :url ,
107- async : false ,
108- type :'HEAD' ,
109- error : function ( ) {
110- ok = false ;
111- } ,
112- success : function ( ) {
113- ok = true ;
114- }
115- } ) ;
116- return ok ;
117- }
118-
119-
12028 var icon = mimeType . replace ( new RegExp ( '/' , 'g' ) , '-' ) ;
12129 //icon = icon.replace(new RegExp('\\', 'g'), '-');
12230
123- if ( checkExists ( OC . webroot + '/core/img/filetypes/' + icon + '.png' ) ) {
124- OC . MimeType . mimeTypeIcons [ mimeType ] = OC . webroot + '/core/img/filetypes/' + icon + '.png' ;
125- return OC . MimeType . mimeTypeIcons [ mimeType ] ;
31+ var path = OC . webroot + '/core/img/filetypes/' ;
32+
33+ // Generate path
34+ if ( mimeType === 'dir' ) {
35+ path += 'folder' ;
36+ } else if ( mimeType === 'dir-shared' ) {
37+ path += 'folder-shared' ;
38+ } else if ( mimeType === 'dir-external' ) {
39+ path += 'folder-external' ;
40+ } else if ( $ . inArray ( icon , OC . MimeType . files ) ) {
41+ path += icon ;
42+ } else if ( $ . inArray ( icon . split ( '-' ) [ 0 ] , OC . MimeType . files ) ) {
43+ path += icon . split ( '-' ) [ 0 ] ;
44+ } else {
45+ path += 'file' ;
12646 }
12747
128- mimePart = icon . split ( '-' ) [ 0 ] ;
129- if ( checkExists ( OC . webroot + '/core/img/filetypes/' + mimePart + '.png' ) ) {
130- OC . MimeType . mimeTypeIcons [ mimeType ] = OC . webroot + '/core/img/filetypes/' + mimePart + '.png' ;
131- return OC . MimeType . mimeTypeIcons [ mimeType ] ;
48+ // Use svg if we can
49+ if ( OC . Util . hasSVGSupport ( ) ) {
50+ path += '.svg' ;
13251 } else {
133- OC . MimeType . mimeTypeIcons [ mimeType ] = OC . webroot + '/core/img/filetypes/file.png' ;
134- return OC . MimeType . mimeTypeIcons [ mimeType ] ;
52+ path += '.png' ;
13553 }
54+
55+ // Cache the result
56+ OC . MimeType . mimeTypeIcons [ mimeType ] = path ;
57+ return path ;
13658 }
13759
13860} ;
0 commit comments