Added function to always have default icon in results (not for mobile)
@@ -5,6 +5,7 @@ AjaxFranceLabs.SubClassResultWidget = AjaxFranceLabs.ResultWidget.extend({
firstTimeWaypoint : true,
isMobile : $(window).width()<800,
mutex_locked:false,
+availableImages: {},
buildWidget : function () {
this.elm = $(this.elmSelector);
@@ -19,6 +20,17 @@ AjaxFranceLabs.SubClassResultWidget = AjaxFranceLabs.ResultWidget.extend({
}
},
+imageExists : function(image_url){
+
+ var http = new XMLHttpRequest();
+
+ http.open('HEAD', image_url, false);
+ http.send();
+
+ return http.status != 404;
+
+},
+
afterRequest : function() {
var data = this.manager.response, elm = $(this.elm),self=this;
if (!this.isMobile)
@@ -63,11 +75,24 @@ AjaxFranceLabs.SubClassResultWidget = AjaxFranceLabs.ResultWidget.extend({
elm.find('.doc:last .icon').append('<span>['+ extension.toUpperCase() +']</span> ');
}
else {
- if (extension !==undefined && extension !="")
- elm.find('.doc:last .icon').append('<object data="images/icons/'+ extension.toLowerCase() +'-icon-24x24.png"></object>&nbsp;');
- else
+ if (extension !==undefined && extension !="") {
+ var icon = "";
+ if(extension.toLowerCase() in self.availableImages) {
+ icon = self.availableImages[extension.toLowerCase()];
+ } else {
+ if(self.imageExists("./images/icons/" + extension.toLowerCase() + "-icon-24x24.png")) {
+ icon = extension.toLowerCase() +'-icon-24x24.png';
+ self.availableImages[extension.toLowerCase()] = extension.toLowerCase() +'-icon-24x24.png';
+ } else {
+ icon = "default-icon-24x24.png"
+ self.availableImages[extension.toLowerCase()] = "default-icon-24x24.png";
+ }
+ }
+ elm.find('.doc:last .icon').append('<object data="images/icons/'+ icon +'"></object>&nbsp;');
+ } else {
elm.find('.doc:last .icon').append('<object data="images/icons/default-icon-24x24.png"></object>&nbsp;');
}
+ }
var urlRedirect = 'URL?url='+ url + '&id='+Manager.store.get("id").value + '&q=' + Manager.store.get("q").value + '&position='+position;
elm.find('.doc:last .res').append('<a class="title" target="_blank" href="'+urlRedirect+'"></a>');
var title;
