client/js/list-bin.js
changeset 160 408da84d4dc0
parent 139 9929b1447f69
child 170 603ffa4c6fa5
equal deleted inserted replaced
159:1796e0220bef 160:408da84d4dc0
    10     + '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>'
    10     + '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>'
    11     + '<% if (description) { %><p class="Rk-ResourceList-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
    11     + '<% if (description) { %><p class="Rk-ResourceList-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>'
    12 );
    12 );
    13 
    13 
    14 Rkns.ResourceList.Bin.prototype._init = function(_renkan, _opts) {
    14 Rkns.ResourceList.Bin.prototype._init = function(_renkan, _opts) {
    15 	this.renkan = _renkan;
    15     this.renkan = _renkan;
    16     this.title_$.html(_opts.title);
    16     this.title_$.html(_opts.title);
    17     if (_opts.list) {
    17     if (_opts.list) {
    18     	this.data = _opts.list;
    18         this.data = _opts.list;
    19     }
    19     }
    20     this.refresh();
    20     this.refresh();
    21 }
    21 }
    22 
    22 
    23 Rkns.ResourceList.Bin.prototype.render = function(searchstr) {
    23 Rkns.ResourceList.Bin.prototype.render = function(searchstr) {
    24     if (searchstr) {
    24     if (searchstr) {
    25     	var _rgxp = new RegExp('('+(searchstr).replace(/(\W)/g,'\\$1')+')','gi'),
    25         var _rgxp = new RegExp('('+(searchstr).replace(/(\W)/g,'\\$1')+')','gi'),
    26     		rxtest = new RegExp(searchstr.replace(/(\W)/g,'\\$1'),'i');
    26             rxtest = new RegExp(searchstr.replace(/(\W)/g,'\\$1'),'i');
    27     }
    27     }
    28     function highlight(_text) {
    28     function highlight(_text) {
    29     	if (searchstr) {
    29         if (searchstr) {
    30     		return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>");
    30             return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>");
    31     	} else {
    31         } else {
    32     		return _text;
    32             return _text;
    33     	}
    33         }
    34     }
    34     }
    35     var _html = "",
    35     var _html = "",
    36         _this = this,
    36         _this = this,
    37         count = 0;
    37         count = 0;
    38     Rkns._(this.data).each(function(_item) {
    38     Rkns._(this.data).each(function(_item) {
    39     	if (typeof _item === "string") {
    39         if (typeof _item === "string") {
    40     		if (/^(https?:\/\/|www)/.test(_item)) {
    40             if (/^(https?:\/\/|www)/.test(_item)) {
    41     			var _element = { url: _item }
    41                 var _element = { url: _item }
    42     		} else {
    42             } else {
    43     			var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() },
    43                 var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() },
    44     				_match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/);
    44                     _match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/);
    45 				if (_match) {
    45                 if (_match) {
    46 					_element.url = _match[0];
    46                     _element.url = _match[0];
    47 				}
    47                 }
    48 				if (_element.title.length > 80) {
    48                 if (_element.title.length > 80) {
    49 					_element.description = _element.title;
    49                     _element.description = _element.title;
    50 					_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…');
    50                     _element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…');
    51 				}
    51                 }
    52     		}
    52             }
    53     	} else {
    53         } else {
    54     		var _element = _item;
    54             var _element = _item;
    55     	}
    55         }
    56         var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'),
    56         var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'),
    57             url = _element.url || "",
    57             url = _element.url || "",
    58             description = _element.description || "",
    58             description = _element.description || "",
    59             image = _element.image || "";
    59             image = _element.image || "";
    60         if (url && !/^https?:\/\//.test(url)) {
    60         if (url && !/^https?:\/\//.test(url)) {
    61         	url = 'http://' + url;
    61             url = 'http://' + url;
    62         }
    62         }
    63         if (searchstr && !rxtest.test(title) && !rxtest.test(description)) {
    63         if (searchstr && !rxtest.test(title) && !rxtest.test(description)) {
    64             return;
    64             return;
    65         }
    65         }
    66         count++;
    66         count++;
    88     this.renkan.resizeBins();
    88     this.renkan.resizeBins();
    89 }
    89 }
    90     
    90     
    91 Rkns.ResourceList.Bin.prototype.refresh = function() {
    91 Rkns.ResourceList.Bin.prototype.refresh = function() {
    92     if (this.data) {
    92     if (this.data) {
    93     	this.render();
    93         this.render();
    94     }
    94     }
    95 }
    95 }