client/js/list-bin.js
changeset 75 7adef9ce92aa
parent 74 c059efca2d7a
child 78 af9e716b01bc
equal deleted inserted replaced
74:c059efca2d7a 75:7adef9ce92aa
     1 Rkns.ListBin = Rkns.Utils.inherit(Rkns._BaseBin);
     1 Rkns.ListBin = Rkns.Utils.inherit(Rkns._BaseBin);
     2 
     2 
     3 Rkns.ListBin.prototype.resultTemplate = Rkns._.template(
     3 Rkns.ListBin.prototype.resultTemplate = Rkns._.template(
     4     '<li class="Rk-Bin-Item Rk-ListBin-Item" draggable="true" data-uri="<%-url%>" '
     4     '<li class="Rk-Bin-Item Rk-ListBin-Item" draggable="true" data-uri="<%-url%>" '
     5     + 'data-title="<%-title%>" data-description="<%-description%>" data-image="<%-image%>">'
     5     + 'data-title="<%-title%>" data-description="<%-description%>" data-image="<%-image%>">'
     6     + '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title"><a href="<%-url%>" target="_blank"><%=htitle%></a></h4>'
     6     + '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title">'
       
     7     + '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>'
     7     + '<% if (description) { %><p class="Rk-ListBin-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
     8     + '<% if (description) { %><p class="Rk-ListBin-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
     8 );
     9 );
     9 
    10 
    10 Rkns.ListBin.prototype._init = function(_renkan, _opts) {
    11 Rkns.ListBin.prototype._init = function(_renkan, _opts) {
    11 	this.renkan = _renkan;
    12 	this.renkan = _renkan;
    30     }
    31     }
    31     var _html = "",
    32     var _html = "",
    32         _this = this,
    33         _this = this,
    33         count = 0;
    34         count = 0;
    34     Rkns._(this.data).each(function(_item) {
    35     Rkns._(this.data).each(function(_item) {
    35     	var _element = (typeof _item === "string" ? { url: _item } : _item)
    36     	if (typeof _item === "string") {
    36         var title = _element.title || _element.url || "",
    37     		if (/^(https?:\/\/|www)/.test(_item)) {
       
    38     			var _element = { url: _item }
       
    39     		} else {
       
    40     			var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() },
       
    41     				_match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/);
       
    42 				if (_match) {
       
    43 					_element.url = _match[0];
       
    44 				}
       
    45 				if (_element.title.length > 80) {
       
    46 					_element.description = _element.title;
       
    47 					_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…');
       
    48 				}
       
    49     		}
       
    50     	} else {
       
    51     		var _element = _item;
       
    52     	}
       
    53         var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'),
    37             url = _element.url || "",
    54             url = _element.url || "",
    38             description = _element.description || "",
    55             description = _element.description || "",
    39             image = _element.image || "";
    56             image = _element.image || "";
       
    57         if (url && !/^https?:\/\//.test(url)) {
       
    58         	url = 'http://' + url;
       
    59         }
    40         if (searchstr && !rxtest.test(title) && !rxtest.test(description)) {
    60         if (searchstr && !rxtest.test(title) && !rxtest.test(description)) {
    41             return;
    61             return;
    42         }
    62         }
    43         count++;
    63         count++;
    44         _html += _this.resultTemplate({
    64         _html += _this.resultTemplate({