From fbdb8f3c55e487d1a93855cf8de4a17e7890474a Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 28 Mar 2012 08:10:57 +0000 Subject: [PATCH] mime_icon method for vfs-mime widget --- etemplate/js/et2_widget_vfs.js | 4 ++-- phpgwapi/js/jsapi/egw_images.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index 9ae7f4d7ad..82c60edcba 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -199,7 +199,7 @@ var et2_vfsMime = et2_valueWidget.extend([et2_IDetachedDOM], { { src += "&thsize="+this.options.size; } - this.image.css("width", "100%"); + this.image.css("max-width", "100%"); } this.image.attr("src", src); } @@ -233,7 +233,7 @@ et2_register_widget(et2_vfsMime, ["vfs-mime"]); */ var et2_vfsSize = et2_description.extend({ init: function() { - this._super.apply(this, arguments); + this._super.apply(this, arguments); this.span.addClass("et2_vfs"); }, human_size: function(size) { diff --git a/phpgwapi/js/jsapi/egw_images.js b/phpgwapi/js/jsapi/egw_images.js index 544cd27f79..2319b6b181 100644 --- a/phpgwapi/js/jsapi/egw_images.js +++ b/phpgwapi/js/jsapi/egw_images.js @@ -89,6 +89,43 @@ egw.extend('images', egw.MODULE_GLOBAL, function() { if(matches != null) tries[_app + " (matched)"]= matches; console.log('egw.image("'+_name+'", "'+_app+'") image NOT found! Tried ', tries); return null; + }, + + /** + * Get image url for a given mime-type and option file + * + * @param _mime + * @param _path vfs path to generate thumbnails for images + * @param _size defaults to 16 (only supported size currently) + * @returns url of image + */ + mime_icon: function(_mime, _path, _size) + { + if (typeof _size == 'undefined') _size = 16; + if (!_mime) _mime = 'unknown'; + if (_mime == 'httpd/unix-directory') _mime = 'directory'; + + var type = _mime.toLowerCase().split('/'); + var image; + + if (type[0] == 'egw' && (image = this.image('navbar',type[1]))) + { + + } + else if (typeof _path == 'string' && type[0] == 'image' && type[1].match(/^(png|jpe?g|gif|bmp)$/)) + { + var thsize = this.config('link_list_thumbnail') || 32; + image = this.link('/etemplate/thumbnail.php',{ 'path': _path, 'thsize': thsize}); + } + else + { + if ((typeof type[1] == 'undefined' || !(image = this.image('mime'+_size+'_'+type[0]+'_'+type[1], 'etemplate'))) && + !(image = this.image('mime'+_size+'_'+type[0], 'etemplate'))) + { + image = this.image('mime'+_size+'_unknown', 'etemplate'); + } + } + return image; } } });