- Clean template code for list bin
authorymh <ymh.work@gmail.com>
Fri, 05 Apr 2013 13:56:22 +0200
changeset 139 9929b1447f69
parent 138 e5be5cc9f09b
child 140 4ed1664b6087
- Clean template code for list bin - set data-image to empty when there is no image for a resource - correct Rkns.Utils.getFullURL to handle case when the url is null or undefined - correct Rkns.Utils.getFullURL to avoid requesting the url when the url is already absolute
client/js/list-bin.js
client/js/main.js
--- a/client/js/list-bin.js	Fri Apr 05 13:51:47 2013 +0200
+++ b/client/js/list-bin.js	Fri Apr 05 13:56:22 2013 +0200
@@ -4,8 +4,9 @@
 
 Rkns.ResourceList.Bin.prototype.resultTemplate = Rkns._.template(
     '<li class="Rk-Bin-Item Rk-ResourceList-Item" draggable="true" data-uri="<%-url%>" '
-    + 'data-title="<%-title%>" data-description="<%-description%>" data-image="<%- Rkns.Utils.getFullURL(image) %>">'
-    + '<% if (image) { %><img class="Rk-ResourceList-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ResourceList-Title">'
+    + 'data-title="<%-title%>" data-description="<%-description%>" '
+    + '<% if (image) { %>data-image="<%- Rkns.Utils.getFullURL(image) %>"<% } else { %>data-image=""<% } %> >'
+    + '<% if (image) { %><img class="Rk-ResourceList-Image" src="<%-image%>"/><% } %><h4 class="Rk-ResourceList-Title">'
     + '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>'
     + '<% if (description) { %><p class="Rk-ResourceList-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
 );
--- a/client/js/main.js	Fri Apr 05 13:51:47 2013 +0200
+++ b/client/js/main.js	Fri Apr 05 13:56:22 2013 +0200
@@ -289,6 +289,13 @@
         return _base + this._ID_BASE + '-' + _n;
     },
     getFullURL : function(url) {
+    	
+    	if(typeof(url) == 'undefined' || url == null ) {
+    		return "";
+    	}
+    	if(url.indexOf("http://")==0) {
+    		return url;
+    	}
     	var img = new Image();
     	img.src = url;
     	var res = img.src;