client/js/list-bin.js
changeset 75 7adef9ce92aa
parent 74 c059efca2d7a
child 78 af9e716b01bc
--- a/client/js/list-bin.js	Wed Mar 13 10:24:23 2013 +0100
+++ b/client/js/list-bin.js	Wed Mar 13 15:37:31 2013 +0100
@@ -3,7 +3,8 @@
 Rkns.ListBin.prototype.resultTemplate = Rkns._.template(
     '<li class="Rk-Bin-Item Rk-ListBin-Item" draggable="true" data-uri="<%-url%>" '
     + 'data-title="<%-title%>" data-description="<%-description%>" data-image="<%-image%>">'
-    + '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title"><a href="<%-url%>" target="_blank"><%=htitle%></a></h4>'
+    + '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title">'
+    + '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>'
     + '<% if (description) { %><p class="Rk-ListBin-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
 );
 
@@ -32,11 +33,30 @@
         _this = this,
         count = 0;
     Rkns._(this.data).each(function(_item) {
-    	var _element = (typeof _item === "string" ? { url: _item } : _item)
-        var title = _element.title || _element.url || "",
+    	if (typeof _item === "string") {
+    		if (/^(https?:\/\/|www)/.test(_item)) {
+    			var _element = { url: _item }
+    		} else {
+    			var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() },
+    				_match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/);
+				if (_match) {
+					_element.url = _match[0];
+				}
+				if (_element.title.length > 80) {
+					_element.description = _element.title;
+					_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…');
+				}
+    		}
+    	} else {
+    		var _element = _item;
+    	}
+        var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'),
             url = _element.url || "",
             description = _element.description || "",
             image = _element.image || "";
+        if (url && !/^https?:\/\//.test(url)) {
+        	url = 'http://' + url;
+        }
         if (searchstr && !rxtest.test(title) && !rxtest.test(description)) {
             return;
         }